Base: anatomy of the loop|INEMA.CLUB-PRO

Lesson 8 · 20 min

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.

Start the lesson
A small circuit board on a dark workbench, with a thin cable closing a loop around it.

In this lesson you will

  1. 1Set up the project with frozen tests and a hash
  2. 2Write the /goal condition at level 3, with a cap
  3. 3Check it yourself, without trusting the summary
  4. 4The map of the six courses and your dated plan

Goal: run your first loop with /goal on a small project, with frozen tests, a level 3 criterion, and a turn cap, and leave with the track plan.

01What you built in this course

Four deliverables that become your first loop. Tap an exercise to see its "done when".

Lesson 1Pieces

goal, state, action, verification, stop

3 exercises

A loop that stops on the test or on the cap.

View the lesson
Lesson 5State

files and git

3 exercises

A disposable cycle that resumes without redoing work.

View the lesson
Lesson 6Criterion

0–4 scale

3 exercises

A level 3 criterion that runs and locks the shortcut.

View the lesson
Lesson 7Caps

turns, time, memory, stagnation, cost

3 exercises

A loop that stops on its own when it gets stuck.

View the lesson
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. 1/5

    Pieces

    The skeleton: the five pieces in a bash loop, with two exit doors and a different exit code for each.

  2. 2/5

    State

    Memory outside the model: a list with passes, progress, and one commit per verified item.

  3. 3/5

    Criterion

    The verification that can't be gamed: a command, a minimum count, and a frozen file.

  4. 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/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.

02The 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
cd ~/ensaio-loop/conta
python3 -m pytest -q -p no:cacheprovider tests/ | tail -1
sha256sum -c tests.sha256
git diff --exit-code -- tests/; echo "rc=$?"
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:

- python3 -m pytest -q -p no:cacheprovider tests/ → 6 passed in 0.01s
- sha256sum -c tests.sha256 → tests/test_conta.py: OK
- git diff --exit-code -- tests/ → saiu com código 0

Its function and yours may be different; what has to match are the three outputs.

03Practice

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.

04Generate 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.

05Lesson quiz

Question 1 of 4

Why does the /goal condition ask for "all three outputs printed in the conversation"?competency

06In 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.

Going further