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