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

Lesson 3 · 18 min

Today's loop engines: /goal, /loop, Ralph, routines, codex exec

There are five common ways to put an agent in a loop, and they answer two questions differently: what triggers the next turn and who decides when to stop. Choosing wrong gets expensive: a /loop waiting for a condition that never comes, a /goal that believes what the agent said. Here is only what the official documentation confirms, read on 10/19/2026.

Start the lesson
Stopwatch, stepper motor, mechanical timer, cloud-shaped part and server module lined up on a dark workbench.

In this lesson you will

  1. 1/goal: by condition, with an evaluator that only reads the conversation
  2. 2/loop and routines: by time or by event, and where each one runs
  3. 3Ralph and codex exec: the disposable session inside a loop of your own
  4. 4A simple rule for choosing

Goal: choose the right loop engine for a task by knowing where it runs, what triggers the next turn, who decides when to stop, and the limit of each one.

01Five engines, five limits

Click each engine: what triggers the next turn, who decides when to stop, and the limit the official docs give.

Scroll the page: each step below lights up its part of the diagram.

  1. 1/6

    /goal

    After each turn, a small model judges your condition: met, not met, or impossible. It's a prompt-based Stop hook, per session. Limit: the evaluator doesn't run commands or read files, it only judges the conversation; the proof has to be printed out. It doesn't change the permission mode. With -p it runs to the end in a single call.

  2. 2/6

    /loop

    Repeats a prompt at a fixed interval (/loop 5m …) or at one Claude picks on each round, from 1 minute to 1 hour. Limits: it belongs to the session and only fires while Claude Code is open and idle; minimum of 1 minute; a recurring task expires after 7 days; the self-paced one doesn't come back on --resume. It's for watching, not for chasing a condition.

  3. 3/6

    Ralph

    A technique described by Geoffrey Huntley: in its pure form, a bash loop that calls the agent with the same prompt, endlessly. Each session is disposable; what remains is in the files and in git. Anthropic cites the pattern as a community convergence. Limit: it has no stop or verification out of the box; you add those yourself (lessons 6 and 7).

  4. 4/6

    Routines

    A saved configuration (prompt, repositories, connectors) that runs on Anthropic's infrastructure, with your laptop closed. Limits: it's in research preview (behavior and limits may change); it works on a fresh clone, with no access to your local files; minimum interval of 1 hour on the schedule.

  5. 5/6

    codex exec

    Runs Codex without an interface: it takes the request as an argument or via stdin, works, and exits. By default the sandbox is read-only; --sandbox workspace-write allows editing. --json gives the events as JSONL, -o saves the last message, exec resume --last continues the previous one. Limit: it isn't a loop; the loop, the test, and the stop live in a script of your own (the headless loop is course 2).

  6. 6/6

    Two questions pick the engine

    Does the next turn come from a condition, a clock, or a loop of your own? And who decides to stop: an evaluator that reads the conversation, you, or a test that actually runs? The engine that runs the test outside the conversation is the hardest to fool.

Sources: official Claude Code docs (/goal, scheduled tasks, routines) and Codex docs (non-interactive mode), read on 10/19/2026; ghuntley.com/ralph.

02Which one to use

A rule of thumb based on the limits above.

1. A task with a provable end

Migrate a module until it compiles and the tests pass, empty a queue of issues. The condition needs an end state, the command that proves it, and what must not change along the way.

Put a cap on the condition itself, as the doc suggests: "or stop after 20 turns".

Conditionpython3 -m pytest -q tests/ prints 6 passed, no file in tests/ was modified, or stop after 15 turns

03The five in one line each

Commands from the official documentation and from the Ralph article. Run only the ones you will actually use.

Claude Code · interactive and headless /goal
/goal python3 -m pytest -q tests/ prints 6 passed and git diff --stat -- tests/ comes out empty, or stop after 15 turns
/goal clear

claude -p "/goal CHANGELOG.md has an entry for each PR this week" --output-format stream-json --verbose
Claude Code · /loop by time
/loop 5m check whether the deploy finished and tell me what happened
/loop check whether CI passed and reply to the review comments
Ralph · the pure form (ghuntley.com/ralph)
while :; do cat PROMPT.md | claude-code ; done
Codex · a headless run
codex exec "count the .md files in this folder and reply with just the number"
codex exec --sandbox workspace-write "create ola.txt with the word ola"
codex exec --json "summarize the repository structure" > eventos.jsonl
codex exec resume --last "now fix what you found"
Simulation: illustrative example

As written, the loop has no stop and no verification: it runs until you press Ctrl+C. The executable name in the article is the author's; on your machine it would be claude -p or codex exec -. In lessons 6 and 7 you add the done criterion and the caps that are missing.

04Practice

On your machine. These are short runs: they use little of your quota.

E1 · A /goal with proof in the output

10 min

In an empty folder with git initialized, open Claude Code and run: /goal the file ola.txt exists and cat ola.txt prints ola in the conversation, or stop after 5 turns.

Done when: cat ola.txt → ola, and the goal status in Claude Code shows the condition as met, with the turn count.

E2 · codex exec read-only

5 min

In the same folder, ask Codex in headless mode to count files, writing the last message to a file.

Done when: codex exec -o resposta.txt "how many .txt files are in this folder? answer with just the number"; echo "saída: $?" → saída: 0, and grep -cE '^[0-9]+$' resposta.txt → 1 (the answer is a single line with just a number; the criterion checks the format, not what the model answered).

E3 · Justified choice

10 min

List three real tasks of yours in a file motores.md, one per line, in the format task → engine → why (trigger and who decides to stop).

Done when: grep -c '→.*→' motores.md → 3, and no task with a verifiable end was left with /loop.

05Lesson quiz

Question 1 of 5

Your /goal condition is "all tests pass". The agent writes "I ran the tests, all pass" without showing the output. What happens?competency

06In three sentences

Trigger and judgeEach engine differs in what triggers the next turn (condition, time, loop, event) and in who decides to stop.
Official limits/goal judges only the conversation; /loop lives in the session and expires in 7 days; routines run in the cloud without your files; codex exec is a single run, not a loop.
Ralph is the baseA loop that calls the agent with state in files; you add the stopping and verification.

Going further

Previous lessonNext lesson