# Claude Code Loop Engineering
Build Self-Correcting Agentic Loops That Ship Trusted Code, Not a $200 Overnight Bill

- Price: $12.99 (Kindle ebook)
- Level: Advanced
- Pages: 191
- Best for: Builders burned by a runaway overnight loop
- You finish with: A bounded, self-correcting Claude Code loop that ships trusted code overnight without burning $200
- Series: Loop Engineering: Stop Prompting, Start Shipping, book 1 of 2
- Buy on Amazon: https://amzn.to/4ecjxtB
- Web page: https://youcanbuildthings.com/books/claude-code-loop-engineering

## What you get

You start an overnight loop and go to bed. You wake up to a $200 bill and code you still can't trust. Meanwhile builders are running nine-hour loops and waking up to clean, merged pull requests. The difference isn't a smarter model, it's a loop that knows when to stop, how to verify its own work, and when to quit before it empties your wallet. This is the complete loop-engineering system: build your first self-correcting loop in Chapter 4, add a metrics-driven exit condition and hard cap that end a runaway in 1-4 iterations, wire a deterministic verification gate so 'done' means tested, layer an adversarial Generator-Evaluator review, cap the spend with a budget gate and model router, and run a checkpointed loop overnight that survives a dropped connection. Stop babysitting your agent.

Every week more "agentic AI" books hit the Kindle Store, written by the very agents they claim to explain. This one is different: roughly 190 pages of dense, build-every-step content, every command run before it reached the page, in a human voice you'll actually want to read. By Chapter 4 you have a working self-correcting loop. By Chapter 6 "done" means tested, not guessed. By Chapter 9 a hard budget cap kills the loop before $200 ever happens. By Chapter 10 it ships real work overnight and survives a dropped connection. Stop babysitting your agent.

## Chapters

1. The Night the Loop Burned $200: Get the mental model: why unbounded loops fail and bounded ones ship, and the four things every trustworthy loop has.
2. What a Loop Actually Is (and What /loop and /goal Really Do): Untangle workflows, subagents, teams, /loop, and /goal on one anatomy diagram you can annotate.
3. The Loop Lifecycle: Start, Steps, Stop: Fill a lifecycle worksheet for your own task: start trigger, max-steps ceiling, stop criteria, and where tool calls get permissioned.
4. Build Your First Self-Correcting Loop: Build a loop that fixes a failing test and stops on green by itself, no human turn in between.
5. The Exit Condition: Teaching the Loop When to Stop: Add a metrics-driven exit and a hard cap so a runaway ends in 1-4 iterations instead of a $200 night.
6. Deterministic Verification: How Output Becomes Trusted: Wire a test + typecheck + lint + build gate the loop must clear before it can claim success.
7. Adversarial Review: The Generator-Evaluator Loop: Add a separate evaluator that tries to break the answer and a judge that grades it against the original spec.
8. When to Loop, When to Fan Out, When to Just Ask Once: Apply a one-page rubric that sorts any task into single-call, loop, or fan-out before you spend a token.
9. Stop the $200 Overnight: Token and Cost Control: Add a budget kill-switch and a cheap/expensive model router so the loop halts at a set dollar ceiling.
10. Loops That Run While You Sleep: Schedule a checkpointed overnight loop that survives a dropped connection and ships a diff you'd actually merge.
11. Why Loops Fail, and How to Steer Them: Reproduce real failure modes (oscillation, hallucination-promotion, taste-arguing) and suppress each with a specific control.
12. Become a Loop Engineer: Assemble the full bounded, verified, cost-capped loop into a reusable template you point at any new project.

## Free guides from this book

- [/loop vs /goal in Claude Code: The Real Difference](https://youcanbuildthings.com/articles/claude-code-loop-vs-goal.md): Claude Code /loop vs /goal confuses everyone. /goal is the self-correcting loop that fixes code; /loop is a scheduler that polls. Here's each in its place.
- [Agent Loop vs Single Prompt vs Fan-Out: When to Use Each](https://youcanbuildthings.com/articles/when-to-use-agent-loop-vs-single-prompt.md): When to use an agent loop vs a single prompt vs fan-out comes down to task shape. A 3-question test routes any coding task to the cheapest tool that fits.
- [Build a Self-Correcting Loop in Claude Code](https://youcanbuildthings.com/articles/claude-code-self-correcting-loop.md): A Claude Code self-correcting loop fixes a failing test and stops on green by itself. Build one in 10 minutes with /goal, a turn cap, and the test as oracle.
- [How to Cap a Claude Code Loop's Spend](https://youcanbuildthings.com/articles/claude-code-budget-limit.md): Set a Claude Code budget limit per run so an unattended loop can't burn $200 overnight: a hard --max-budget-usd cap, a model router, and context trimming.
- [How to Give an Agentic Loop an Exit Condition](https://youcanbuildthings.com/articles/agentic-loop-exit-condition.md): An agentic loop exit condition has two halves: a measurable pass criterion and a hard cap. Wire both in Claude Code so a runaway loop stops in 1-4 turns.
