The kit: seven files that hold a long run together
A 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.
1Install the kit and confirm that all 73 tests pass
2Create longrun/[date]-[slug]/ with one command
3Separate what gets rewritten from what only gets appended
4Put the method into the agent's global rules
Goal: create the longrun/ folder for a run and say, for each of the seven files, who writes it, when it is read, and whether it only appends.
01 · The seven files around the agent
Tap each block: who writes it, when it is read, and how it changes.
Lesson 101 · The seven files around the agentTap each block: who writes it, when it is read, and how it changes.
Compacted, crashed, or switched models? The next cycle rereads the folder and keeps going.
1/6
goal.md
Result in one sentence, done criteria (function, regression, limit), caps, constraints, and human gates. It is the only file the agent should not rewrite: changing the goal midway means changing the task.
Scroll the page: each step below lights up its part of the diagram.
1/6
goal.md
Result in one sentence, done criteria (function, regression, limit), caps, constraints, and human gates. It is the only file the agent should not rewrite: changing the goal midway means changing the task.
2/6
plan.md + state.md
Both are snapshots of right now: rewrite, don't accumulate. state.md ends with the exact commands to resume. When the first line of "Funciona" says concluído, the watchdog and the hook stop treating the run as active.
3/6
progress, failures, decisions
Dated history in a table. You never delete a line: it's what lets you see later whether the agent reopened an item that was already done or repeated the same attempt three times.
4/6
canal.md
Project knowledge, not task state: where things are, the right name for each piece, the trap that cost an hour. Append only, one line per fact, with a date. The hook asks you to fill it in at band 1 (lesson 3).
5/6
Agent or loop
After every compaction or resume, the first thing is to reread the files, in this order: goal → state → plan → canal → end of progress and failures, and continue from the first pending item.
6/6
The folder is the memory
The goal stays parked in goal.md; the now lives in plan and state; the history only grows in progress, failures and decisions; what the summary loses lives in the canal.
The same files work for Claude Code and for Codex: one picks up what the other wrote.
02 · When each file comes into play
One run from start to finish, seen through the files.
1. Before
novo-longrun.sh creates the folder with the seven files already stamped with the date.
You fill in goal.md. It's the slow part, and it decides whether the run finishes (lesson 2).
Folder namelongrun/2026-10-19-contador-palavras/
2. Every cycle
Reads state and plan, picks the next useful action, runs it and tests it.
At the end it rewrites state and plan and adds a line to progress. If something went wrong, a line in failures.
~/projetos/execucao-longa/tools/novo-longrun.sh ~/projetos/<seu-projeto> <slug-do-objetivo>
ls ~/projetos/<seu-projeto>/longrun/*/
Global CLAUDE.md and AGENTS.md · paste once (templates/AGENTS-long-run.md)
## Execução longa (/goal, loop, objetivo de horas) — método em ~/projetos/execucao-longa
- **Antes de começar:** `~/projetos/execucao-longa/tools/novo-longrun.sh <projeto> <slug>` cria `longrun/<data>-<slug>/` (goal, plan, state, progress, failures, decisions, canal). Critério de pronto no `goal.md` em **nível 3+**: `comando → saída esperada`, cobrindo função, regressão e limite, sem atalho possível (contagem mínima, testes congelados, validador).
- **Durante:** releia goal → state → plan → canal após toda compactação ou retomada; registre cedo no `canal.md` (só acrescentar) fatos, aprendizados, glossário e armadilhas; teste cada mudança; commit a cada checkpoint; continue enquanto houver próxima ação útil e segura.
- **Parar e chamar o humano:** 3 ciclos sem avanço mensurável; o mesmo plano de fechamento repetido sem fechar ou item já feito reaberto (contexto degradou); crédito/API, ação irreversível ou externa, credencial ausente, decisão de negócio.
- **Faixas de contexto** (no Claude Code o hook avisa uma vez cada; no Codex, acompanhe o % em `/status`): ~50% → registrar no `canal.md`; ~70% → atualizar estado e pedir `/compact`; ~85% ou 3ª compactação → `/session-handoff` + sessão nova + `/prime`.
- **Headless:** `~/projetos/execucao-longa/tools/loop-longrun.sh <pasta-longrun>` (flock, timeout, MemoryMax, testes protegidos, parada por estagnação). Medir: `tools/medir-sessao.py <jsonl>`.
- Tetos sempre: timeout, memória (`systemd-run --user --scope -p MemoryMax=`), saída de ferramenta curta.
- **Histórico:** `recall "termo" [--projeto X] [--fonte codex|claude] [--desde AAAA-MM-DD]` busca em tudo o que já foi dito com o Codex e o Claude nesta máquina (índice reindexado de hora em hora) — use antes de perguntar ao usuário algo que pode já ter sido decidido.
Example from the repository
$ python3 -m pytest -q -p no:cacheprovider | tail -1
73 passed in 18.59s
$ novo-longrun.sh ~/ensaio/projeto-teste contador-palavras
criado: ~/ensaio/projeto-teste/longrun/2026-10-19-contador-palavras
próximo: preencher ~/ensaio/projeto-teste/longrun/2026-10-19-contador-palavras/goal.md (critérios nível 3+) e colar templates/prompt-goal-codex.md no /goal
$ ls ~/ensaio/projeto-teste/longrun/*/
canal.md decisions.md failures.md goal.md plan.md progress.md state.md
$ novo-longrun.sh ~/ensaio/projeto-teste contador-palavras
já existe: ~/ensaio/projeto-teste/longrun/2026-10-19-contador-palavras
$ echo $?
1
Run with the 10/18/2026 kit; only the path of the rehearsal folder was shortened. The pytest time changes from machine to machine.
Folder outside a project: the script requires the project folder to exist. The hook and the vigia look for longrun/*/state.md at the root of the git repository.
Reusing the slug: two runs on the same day with the same slug collide and the script refuses. Use another slug; don't delete the old folder, it is history.
Writing "concluído" in state.md by mistake: for the hook and the vigia, the run is no longer active.
04 · Video: the three pieces of the method
Six minutes with the concept (10/10/2026). The concept holds; two details changed afterward: at band 3 and at the 3rd compaction the agent finishes the task in progress before the new session (lesson 3), and the care with the cache today is the automatic handoff at 45 min idle (lesson 4).
On your machine. Only move on to the next one when the "done when" is true.
E1 · Kit installed and tested
10 min
Clone the kit into ~/projetos/execucao-longa and run its test suite.
Done when:python3 -m pytest -q -p no:cacheprovider | tail -1 → 73 passed (in a newer clone the number may be higher; failed must never appear).
E2 · The folder of a real run
10 min
Pick a real task from one of your projects that takes more than an hour and create its folder. Run the same command twice.
Done when:ls ~/projetos/[your-project]/longrun/*/ | wc -l → 7; the second call prints já existe: and echo $? → 1.
E3 · The method in the global rules
10 min
Paste the block from templates/AGENTS-long-run.md into ~/.claude/CLAUDE.md and into ~/.codex/AGENTS.md. Open a new session and ask: "how do you start a long run?" The block also mentions /session-handoff, /prime and recall: they only exist from lessons 5 and 7 on.
Done when:grep -c novo-longrun.sh ~/.claude/CLAUDE.md → 1 or more, and the new session answers by citing novo-longrun.sh and the level 3 criterion without you reminding it.
06 · Lesson quiz
Question 1 of 4
Which of these files should the agent REWRITE each cycle, instead of only appending to?skill
Correct
state.md and plan.md are a snapshot of right now and get rewritten. progress, failures and decisions are history: they only get appended to, so you can later see whether the agent repeated an attempt or reopened an item.
Not this one
state.md and plan.md are a snapshot of right now and get rewritten. progress, failures and decisions are history: they only get appended to, so you can later see whether the agent repeated an attempt or reopened an item.Review: The seven files around the agent
Question 2 of 4
The agent found out that the test database only starts with the variable DB_LOCAL=1. Where does this go?
Correct
It is project knowledge that compaction loses: canal.md, one line with a date. In plan.md it disappears at the next rewrite; in goal.md it would change the task.
Not this one
It is project knowledge that compaction loses: canal.md, one line with a date. In plan.md it disappears at the next rewrite; in goal.md it would change the task.Review: The seven files around the agent
Question 3 of 4
After a compaction, what is the first thing the agent does?skill
Correct
The summary mixes what is confirmed with guesses. The files don't. That is why the kit tells you to reread the folder in order and continue from the first pending item.
Not this one
The summary mixes what is confirmed with guesses. The files don't. That is why the kit tells you to reread the folder in order and continue from the first pending item.Review: When each file comes into play
Question 4 of 4
You ran novo-longrun.sh with a slug that already exists today. What happens?
Correct
The script refuses and doesn't touch the existing folder. An old folder is history: use another slug.