Loop Engineering 101 — How to Ship Code While You Sleep
By: Daniel Moka — Craft Better Software (Jun 12, 2026)
What Is a Loop?
A loop is just a prompt that asks the agent to loop until some condition is met. Instead of asking an agent to make one edit and stop, you write: “Keep working on this until X happens” — where X is something you can check.
The Loop Anatomy
Prompt → Execute → Gate → Feedback → Repeat
- Prompt — Decompose the work, but don’t plan every step. Give the agent a clear end condition and let it figure out the path.
- Execute — Write code, run commands, make changes. The agent drives.
- Gate — A hard check the output must pass before the loop moves on.
- Feedback — The gate’s result feeds back into the next iteration.
- Repeat — Until the gate passes the work through.
The Quality Gate
A loop without a gate produces slop faster.
The gate is the check work must pass before it ships. Your gate cannot be a polite review comment — an agent can rationalize past a comment but not past a failing compile, a red test, or a blocked CI job.
Build the gate from things the agent cannot argue with:
- The compiler
- The type system
- Integration tests
- Mutation tests
- Property-based tests
- Linters and analyzers
- CI
The loop does the work. The guardrails decide whether it is allowed to pass.
A Loop That Learns
Your agent fixes a bug today and reintroduces it tomorrow. Not because it’s dumb — because it forgot. A loop only improves if it can carry its lessons forward.
The fix: RULES.md — memory that survives between runs.
The loop catches the failure and reports why it broke. You decide whether it’s worth a permanent rule and write it into RULES.md. Each time something breaks, the file grows.
Your job is not designing loops that prompt your agents. It’s designing loops that learn from experience.
From Operator to Engineer
Prompting one task at a time makes you the operator. Designing the loop makes you the engineer. You step in only at decision points while the loop decomposes, executes, gates, and learns.
But be pragmatic: Loops are worth it for work that repeats and can be checked. Prompting by hand is still fine for the rest. Since loops burn real tokens, often less is more.
Full article: Loop Engineering 101