Your first loop: a small goal with a level 3 criterion
Time to put the pieces together in a real loop, small on purpose: a word-counting function, six tests frozen with a hash, and a level 3 /goal condition with a turn cap. Small enough to finish in minutes; complete enough to have all five pieces. At the end, the map of the track and your plan with dates.
By the end of course 0A small loop running with the five pieces, a level 3 criterion and a cap, and the vocabulary for the other five courses.
24 exercises
Click an exercise to see what to do and the "done when".
1/5
Pieces
The skeleton: the five pieces in a bash loop, with two exit doors and a different exit code for each.
1/5
Pieces
The skeleton: the five pieces in a bash loop, with two exit doors and a different exit code for each.
2/5
State
Memory outside the model: a list with passes, progress, and one commit per verified item.
3/5
Criterion
The verification that can't be gamed: a command, a minimum count, and a frozen file.
4/5
Caps
The safety door: each cap catches one way the loop might never end, and the human gate catches what can't be done without you.
5/5
The four deliverables together
Pieces, state, criterion and caps are what you use next. The rest of the lessons (harness, engines, LOOP-R) say where each piece lives and which course goes deeper.
The exercises from lessons 2, 3 and 4 go into the plan below.
02 · The project for your first loop
One folder, one test file frozen by hash, and not a single line of the function. The agent writes the function.
Terminal · create the folder and freeze the tests
mkdir -p ~/ensaio-loop/conta/tests && cd ~/ensaio-loop/conta && git init -q
# paste the test file from the next block into tests/test_conta.py, then:
sha256sum tests/test_conta.py > tests.sha256
git add -A && git commit -qm "testes congelados"
python3 -m pytest -q -p no:cacheprovider tests/ | tail -1 # still fails: conta.py does not exist
tests/test_conta.py
from conta import conta_palavras
def test_vazio():
assert conta_palavras("") == 0
def test_uma():
assert conta_palavras("loop") == 1
def test_espacos_repetidos():
assert conta_palavras(" o loop para ") == 3
def test_quebra_de_linha_e_tab():
assert conta_palavras("objetivo\nestado\tação") == 3
def test_pontuacao_nao_e_palavra():
assert conta_palavras("pronto , quando - passa") == 3
def test_acentos():
assert conta_palavras("verificação e parada") == 3
Claude Code · the /goal condition (level 3, with a cap)
/goal python3 -m pytest -q -p no:cacheprovider tests/ prints 6 passed, sha256sum -c tests.sha256 prints OK and git diff --exit-code -- tests/ exits with code 0, with all three outputs printed in the conversation, or stop after 8 turns
Terminal · you check it, without trusting the summary
loop-codex.sh · the same loop with codex exec (exercise 3)
#!/usr/bin/env bash
# Your own loop: at most 3 cycles of codex exec; the three commands decide when to stop.
set -u
cd ~/ensaio-loop/conta
passes() {
python3 -m pytest -q -p no:cacheprovider tests/ 2>&1 | tail -1 | grep -q '^6 passed' &&
sha256sum -c --quiet tests.sha256 &&
git diff --quiet -- tests/
}
for ciclo in 1 2 3; do
if passes; then echo "PRONTO no ciclo $((ciclo - 1))"; exit 0; fi
echo "ciclo $ciclo: codex exec"
timeout 15m codex exec --sandbox workspace-write \
"Crie conta.py com conta_palavras(texto) que faça os testes de tests/ passarem. Não altere nada em tests/."
done
if passes; then echo "PRONTO no ciclo 3"; exit 0; fi
echo "PARADO: teto de 3 ciclos"; exit 2
Example from the repository
With the same condition, in headless mode (claude -p "/goal …"), the agent wrote conta.py and finished by printing:
Its function and yours may be different; what has to match are the three outputs.
$ echo "def test_x(): pass" > tests/test_conta.py
$ sha256sum -c tests.sha256
tests/test_conta.py: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
$ echo $?
1
Swapping the test for an empty one would make pytest pass, but the hash and the git diff flag it. That's the difference between level 2 and level 3.
Objective: the /goal condition.
State: the files and the tests commit.
Action: the agent editing conta.py.
Verification: pytest with a count, hash and git diff, printed in the conversation.
Stop: the /goal evaluator or the 8-turn cap.
03 · Practice
On your machine. Exercise 2 uses little of your quota.
E1 · The project ready for the loop
10 min
Create the folder, the test file, the hash and the first commit. Run pytest before the function exists.
Done when:sha256sum -c tests.sha256 → tests/test_conta.py: OK, git log --oneline | wc -l → 1, and pytest still fails (the function doesn't exist).
E2 · The first loop running
15 min
Open Claude Code in the folder and paste the /goal condition. Let it run without interfering; if Claude asks permission to run pytest, approve it.
Done when: The goal status shows the condition met, and the three check commands, run by you, give 6 passed, tests/test_conta.py: OK and rc=0.
E3 · The same loop with Codex
15 min
Delete conta.py and run the same request through codex exec with a write sandbox, using the loop-codex.sh from the block above: at most 3 cycles, stopping when the three commands pass.
Done when: Your loop ends before the 3rd cycle, and the same three commands give 6 passed, OK and rc=0; git diff --stat -- tests/ comes out empty.
04 · Generate your plan with dates
Pick the start date and how much time you have per week. The plan lists the exercises from the eight lessons in order.
plano.md
05 · Lesson quiz
Question 1 of 4
Why does the /goal condition ask for "all three outputs printed in the conversation"?competency
Correct
It's question 4 on the scale: does the proof show up in the output? The evaluator doesn't run the commands; the agent does, and the output has to be there to be judged.
Not that one
It's question 4 on the scale: does the proof show up in the output? The evaluator doesn't run the commands; the agent does, and the output has to be there to be judged.Review: The project for your first loop
Question 2 of 4
What does the hash in tests.sha256 add to "6 passed"?
Correct
"6 passed" alone is level 2: an agent can swap the tests for six others that pass. The hash and the git diff lock the file. Together, level 3.
Not that one
"6 passed" alone is level 2: an agent can swap the tests for six others that pass. The hash and the git diff lock the file. Together, level 3.Review: The project for your first loop
Question 3 of 4
The /goal finished with the condition met. What's the next step?competency
Correct
You close it: the evaluator judged the conversation, you check the machine. It's what the execucao-longa kit asks for at the close of every run.
Not that one
You close it: the evaluator judged the conversation, you check the machine. It's what the execucao-longa kit asks for at the close of every run.Review: Practice
Question 4 of 4
After this course, what's next in the suggested order of the track?
Correct
The suggested order is 0 → 1 → 2 → 3 → 4 → 5. Course 1 takes the piece that's missing most, verification, and brings it up to level 4.
Not that one
The suggested order is 0 → 1 → 2 → 3 → 4 → 5. Course 1 takes the piece that's missing most, verification, and brings it up to level 4.Review: What you built in this course
Quiz complete
You got {a} of {n} right. Get them all right and the lesson is marked as complete.
Choose one answer. The explanation appears after you try.
06 · In three sentences
Small and completeThe first loop has all five pieces on a problem that finishes in minutes.
Freeze before you let goTests with a hash and a commit before the agent starts: that's what makes the criterion level 3.
You close itThe evaluator judges the conversation; you run the check on the machine.