32dots HEIDELBERG AI

Loop Engineering

Build the system that drives the agent — loops that run while you sleep

The step after spec engineering: once an agent can run multi-step tasks for hours, you stop typing each turn and build the loop that drives it. A ladder of real, runnable patterns — the closed loop, the Ralph loop (`while :; do cat PROMPT.md | claude-code; done`), Claude Code's /loop, /goal and /batch, headless `claude -p`, stop-conditions and maker/checker verification — with a copy-ready cheat sheet, three worked examples, and videos from Cole Medin and Nate Herk.

After this chapter you can
Close the loop: make the agent verify its own work (tests, /goal) before it stops
Run a loop unattended — the Ralph loop, anchor files, and headless `claude -p`
Always give a loop a way to stop: iteration caps, no-progress and budget limits
Scale up safely with /batch worktrees, maker/checker subagents, and scheduled routines
Anatomy of a loop you design the system that prompts the agent — not each turn 1 · Trigger schedule · event · you 2 · Act agent does one step 3 · Check tests · a separate reviewer pass ✓ done — goal verified fail → fix & retry stop after N tries · budget three rungs — hand off more of the driving 1 · Closed loop verify every change 2 · Run unattended Ralph + anchor files 3 · Orchestrate batch · subagents · schedule the whole technique, in one line: while :; do cat PROMPT.md | claude-code ; done
The loop at a glance — Trigger · Act · Check · repeat, until a verified goal.