Claude Code Loops
Stop Prompting, Start Shipping
You are the bottleneck. You prompt, you wait, you read the diff, you prompt again, and the agent stops the second you stop typing. This book hands you the fleet that ships without you. Your first loop runs on a real repository in Chapter 1, in ten minutes. By Chapter 4 you have built the same task four ways and priced each one, so you reach for the right loop instead of the loud one. By Chapter 6 a separate verifier signs off before code reaches your branch, and the working agent cannot talk its way past it. By Chapter 9 a night of agent work has a price you knew before you pressed enter. By Chapter 12 your loops run on a thirty-day schedule, wired so one loop's verified output becomes the next one's input.
Loop engineering is not a rebrand of the software development lifecycle. It is iterative development where the iteration is executed by something that cannot be trusted to report its own results, and that one difference changes every piece of the engineering around it.
This book refuses to print numbers it cannot verify. The four-bill comparison table in Chapter 4 ships blank on purpose, the rate sheet in Chapter 9 ships with underscores, and the most-quoted dollar-per-hour figure on the internet is named and then left unprinted. You fill those in from your own runs, because a printed rate is a wrong rate eventually.
Every loop, hook, gate, and receipt ships in a free companion GitHub repo: one folder per chapter, and one command that installs the whole set into a project you already own. Every command is tested on Linux, WSL, and macOS.
What You'll Build
Run a complete loop on your own repository in ten minutes, with a hard cap and a dollar ceiling set before the first iteration.
Measure which rung you are actually on from your own session transcripts, not your own opinion.
Write the four contract files your loop reads every iteration, then watch it refuse work outside the scope boundary.
Build the same task four ways and record iterations, wall clock, and dollars for each. The cost spread is the lesson.
Replace 'loop until done' with an exit condition a computer evaluates, plus four enforced invariants that halt a runaway.
Stand up a separate verifier that gates on evidence on disk, then make the working agent lie on purpose and watch it get refused.
Build the four-rung escalation ladder so a stuck run climbs instead of replaying the same prompt into the same context.
Build the state store and harness, then measure re-fetched tokens before and after on your own run.
Instrument the loop to meter itself, enforce a hard dollar ceiling that halts mid-run, and print a per-iteration receipt.
Build a break-even model from your real rate and your metered cost, then reconcile it against one overnight run.
Ship loop-doctor: a diagnostic that reads a run's logs and names which failure mode fired and which guard would have caught it.
Wire two loops into a dependency graph where the second refuses to start if the first fails its gate, then schedule the fleet.