Free playbooks in your inbox
Hands-on tutorials for people who want to build with AI.
Cover of Claude Code Loop Engineering
From the youcanbuildthings catalog · ▸ Build-tested

Claude Code Loop Engineering

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

eBook: $9.99 191 pages
Get on Amazon →

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.

What You'll Build

01
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.

02
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.

03
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.

04
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.

05
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.

06
Deterministic Verification: How Output Becomes Trusted

Wire a test + typecheck + lint + build gate the loop must clear before it can claim success.

07
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.

08
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.

09
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.