LOOP-R Engineering Track · course 2 of 6 · 8 lessons
Long runs: the agent works for hours and the test decides when it's done
Seven state files, a goal.md that can't be met by a shortcut, a hook that watches the context and the cache, a handoff you can check, a headless loop with caps, and measurement of every session. All with the open execucao-longa kit and real terminal output.

- 8lessons
- 20exercises with expected output
- 73tests in the kit (10/19)
- 1video
The lessons
In the order you build them: folder and goal, context and cache, handoff, headless loop, measurement, and a full run.
Lesson 1 · 15 minThe kit: seven files that hold a long run togetherA long session fails in three ways: it doesn't know when to stop, it forgets what it did after compaction, and it spends what it shouldn't. The execucao-longa kit answers with files, not with the model's memory: the agent rereads the folder instead of remembering. In this lesson you install the kit and create your first folder.
Lesson 2 · 18 minWrite a level 3+ goal.md with no possible shortcutIn the kit's pilot, with a level 3 criterion and 14 frozen tests, the run finished in the first cycle, in 3 minutes. Most of the work in a long run is writing the criterion. Here you write your own goal.md so that the only way to meet it is to do the work.
Lesson 3 · 18 minContext in bands: 50, 70 and 85% of the compaction pointThe biggest enemy of a long session is repeated compaction: the goal survives, but what is done and what remains get diluted. The hook-longrun measures the context and acts before the limit, in three bands. In this lesson you turn on the hook and trigger all three bands in a rehearsal, without spending a token.
Lesson 4 · 16 minCache and idle time: what the October numbers showGoing back to a large session that has sat idle for two hours can cost hundreds of thousands of tokens in a single message. It's not a bug: the cache expired. With the numbers measured in October 2026, you'll understand the timeline of an idle session and decide, with real math, between resending and starting clean.
Lesson 5 · 17 minHandoff that checks it was savedA handoff written by the agent itself certifies itself: it can say it tested what it did not test, and the file may not even have been written. Since 10/17/2026 the proof is out of the text: a script writes a stamp, commit and fingerprint of the files, and the hook checks in the transcript that the handoff was really saved.
Lesson 6 · 20 minHeadless loop: loop-longrun.sh, flock, timeout, and MemoryMaxIn the interactive /goal, an evaluator reading the conversation decides when it's done. In the headless loop, the test decides, run by the loop itself, with the test files protected. In this lesson you run loop-longrun.sh with a fake agent: you see it finish, you see the cheat get reverted, and you see the lock stop two loops in the same folder, without spending any quota.
Lesson 7 · 17 minMeasure the session: medir-sessao.py, resume cost, and recallWithout measuring, "the session got expensive" and "the agent forgot" are just impressions. The kit reads the JSONL transcripts from Claude Code and Codex and gives you duration, compactions, tokens and cache per turn, the real cost of resuming, and a search across everything that has been said. In this lesson you measure a known case and then your biggest session.
Lesson 8 · 20 minA run of hours, from start to finishNow put it all together in a real run: folder, level 3 goal, frozen tests, how to run it, watching without interrupting, knowing when to stop, and closing with measurement. The kit's pilot, from 10/01/2026, is a step-by-step reference. At the end, the course map and your plan with dates.
Who it's for
- 1People who already use Claude Code or Codex in the terminal and want to leave a task running for hours.
- 2People who have seen the agent say "done" with a deleted test, or forget what it did after a compaction.
- 3People who need to run an agent in cron or systemd without freezing the machine or wasting the quota.
What you'll be able to do
- 1Create the longrun/ folder and write command → output criteria that cover function, regression, and limit.
- 2Turn on the context band hook and know when to compact, write a handoff, or open a new session.
- 3Run loop-longrun.sh with flock, timeout, MemoryMax, and protected tests, first with a fake agent.
- 4Measure the session, the cost of resuming, and find old decisions with recall.
Before you start
- 1Linux or macOS with git, Python 3, and pytest; on Linux, user systemd for MemoryMax and the timers.
- 2Claude Code or Codex installed and signed in through your subscription. The rehearsal exercises don't use up quota.
- 3Recommended: course 0 (Base) for the done criterion scale and course 1 (Verification) for evaluators.