← Insights

Mental Models for the AI EconomyAI Development

Loop Engineering: The Definitive Field Guide

The leverage point in software has moved from writing prompts to designing the loops that prompt your agents. The complete field guide — Ralph, maker-checker, worktrees, AGENTS.md, memory, and MCP — from someone who runs these loops across a live portfolio.

By George MoreasJuly 202624 min read

For two years the skill was prompting — you held the agent one turn at a time. That era is closing. The new skill is designing the loop that prompts the agent for you: a system that finds work, decomposes it, hands it out, checks it, records what happened, and decides what to do next.

The loop, one iteration
  1. 1Fresh contextA brand new agent instance reads PROMPT.md. Nothing carries over from the last iteration — that is the point, not a limitation.
  2. 2Read statefix_plan.md, the specs, the git log. The disk remembers what the model cannot, so the loop picks up where the last one stopped.
  3. 3Do one thingExactly one increment — and the agent chooses which one matters most. Widen this only once the project is stable.
  4. 4Back-pressureBuild it, test it, type-check it. Anything that can reject bad output goes here. Without this station the loop is just a very fast way to be wrong.
  5. 5Commit and killWrite the plan back, commit, then destroy the context. Empty TODO means exit. Otherwise the wheel turns again.

That ring is the whole discipline in one picture. Five stations, turning without you. The leverage didn't vanish when agents got good — it moved one floor up, from the prompt to the machine that writes the prompts. This is the complete parts list, the assembly order, the maturity ladder, and the failure modes, from running these loops across a live portfolio of products.

The short version

A loop is a task plus a check plus a stop condition. Everything else — model choice, connectors, sub-agents, worktrees — is in service of making the check real enough that you can walk away. Most people build the task and skip the check, then wonder why autonomy burned them.

01 — Origin

You might be getting very good at a skill that is quietly being retired.

Where the term came from, who named it, and why the technique is a year older than the word.

In early June 2026 a phrase stabilized across the builder community almost overnight. Peter Steinberger, who built OpenClaw, put it bluntly: stop prompting your coding agents and start designing the loops that prompt them. Boris Cherny, who leads Claude Code at Anthropic, described his own workday the same way — he no longer prompts Claude; he writes loops that prompt Claude and figure out what to do next.

On June 7, 2026, Addy Osmani published the essay that turned those one-liners into a named discipline: loop engineering. He didn't invent the practice — he caught an idea moving fast, gave it a name, and gave it a parts list. O'Reilly Radar republished the essay on June 22, which is how it reached most of the industry.

But the technique predates the name by nearly a year. In July 2025, Geoffrey Huntley published "Ralph Wiggum as a 'software engineer'" — a bash while loop wrapped around a coding agent that he used to build an entire programming language. Ralph is the ancestor of everything here, and still the clearest way to understand what a loop is, because it removes everything inessential.

My stance, stated the way both authors stated theirs: this is early, the failure modes are real, and a loop that runs unattended is also a loop that makes mistakes unattended. But the shape of the work has genuinely changed. If you build software with AI agents, this is the thing worth getting good at now — not despite the difficulty, but because the difficulty is where the professional edge lives.

02 — The three floors

There are three floors to this building. Most people are still working on the ground one.

A map that tells you which floor you are on right now, and what the one above it actually gives you.

Ground floor
Prompt engineering
You hold the agent. One turn at a time: type, read, type the next thing. Your hands never leave the wheel.
First floor
Harness engineering
You shape one agent's world — its tools, context, guardrails, file layout. You still start every run.
Top floor
Loop engineering
You design the system. It runs on a schedule, spawns helpers, feeds itself, and knows when to stop.
Each floor wraps the one below it

The reason this went mainstream so fast is that it stopped being a tool thing. A year ago a loop meant a pile of bash you owned and maintained forever. Now the pieces ship inside the products — the same primitives, whether you're in Claude Code or the Codex app. Once you see the shape is identical, you stop arguing about which tool and design a loop that works regardless of which one you're sitting in.

03 — Anatomy

A loop is two things. Almost everyone builds the first one and skips the second.

The one sentence the rest of this guide is an elaboration of.

Strip away the tooling and a loop is almost embarrassingly simple:

Step 1
Do something
The task. This is the part everyone builds, and the part that is now nearly free.
Step 2
Check the result
The verifier. Not done? Back to the task. This is the part that gets skipped, and the only part that makes autonomy safe.
Step 3
Stop
The exit condition. A loop without one is not autonomous, it is unsupervised.
A task without a check is just hope, running on a schedule, billed by the token.

The entire craft is in making the check real and defining when to stop. Model choice, harness, connectors, sub-agents — all secondary to those two things.

04 — The parts list

Six parts. Four of them stop the agent guessing; two of them let you leave the room.

What each primitive gives you, why it exists, and the split that decides how you spend your time.

A working loop is built from six primitives. Five do the work; the sixth remembers it.

PrimitiveWhat it givesWhy it's in the loop
SkillsInstructionsReusable, invocable know-how, so the agent doesn't re-derive your conventions every run
MemoryStateWhat's done, what's next, what "done" even means — held on disk across runs
MCP / connectorsAccessIssue trackers, databases, staging APIs, Slack — the tools you already use
AGENTS.mdRulesHow to build, run, and reason about this repo — read first, every run
WorktreesIsolationSeparate checkouts, so agents working at once don't collide
Sub-agentsSeparationMaker/checker split — one agent proposes, a different one verifies

The distinction that matters most: skills, memory, MCP, and AGENTS.md are the four knowledge surfaces — instructions, state, access, and rules. Worktrees and sub-agents are the two structural primitives. Get the knowledge surfaces right and the agent stops guessing. Get the structural ones right and the loop can run unattended without turning into a mess. If your loop is producing confident nonsense, the problem is almost always a knowledge surface. If it's producing a tangle, the problem is structural.

The two tools have already converged

These primitives ship inside both major products and map almost one-to-one. Design for the shape, not the vendor.

PrimitiveClaude CodeCodex app
Automationsscheduled tasks, cron, /loop, /goal, hooks, GitHub ActionsAutomations tab (project, prompt, cadence); Triage inbox; /goal
Worktreesgit worktree, --worktree, worktree isolation on a subagentbuilt-in worktree per thread
SkillsAgent Skills (SKILL.md)Agent Skills (SKILL.md), $name invocation
MCP / connectorsMCP servers plus pluginsConnectors (MCP) plus plugins
Sub-agentssubagents in .claude/agents/, agent teamssubagents as TOML in .codex/agents/
StateMarkdown (AGENTS.md, progress files) or Linear via MCPMarkdown or Linear via connector

The names differ. The capability is identical. Stop being loyal to a tool and start being fluent in a pattern.

05 — Ralph

The dumbest technique in this article built a working programming language.

Why a one-line bash loop outperforms a long, careful session — and the four rules that make it survive contact with real work.

Before the primitives shipped inside the products, there was Ralph — still the purest expression of a loop. Geoffrey Huntley named it in July 2025. The name has two origins, both of which he owns: Ralph Wiggum, the cheerful Simpsons character who rams a doorframe and announces "I'm helping!" — and "ralph" as slang for vomiting, roughly how Huntley felt realizing how cheap autonomous code generation had become. His framing is that the technique is "deterministically bad in an undeterministic world." Once you see why that's a feature, the rest clicks.

Short Ralph — a while loop and a prompt

the entire technique
# Ralph, in full. There is no part two.
$ while :; do cat PROMPT.md | claude-code ; done

You feed the same prompt file to a fresh agent instance, over and over, until the work is done. Progress accumulates in files and git history — never in the model's context window. My first reaction was "that can't possibly work." It does. Huntley used exactly this shape to build CURSED, a production-grade programming language the model had no training data for. A contact of his delivered a $50k contract MVP for roughly $297 in tokens.

The fresh context every iteration is not a side effect. It is the entire point.
The counterintuitive core of the technique

LLMs degrade as context fills. Huntley pins the practical clip at around 147k–152k tokens against an advertised 170k–200k window; past that, output quality drops and tool calls start failing. A long continuous session inevitably drifts into that zone, loses the plot, and confidently makes things worse. Ralph sidesteps this by killing context after every increment and starting clean.

The cardinal rule: one thing per loop. Ask Ralph to do exactly one thing, and trust it to choose which thing matters most. Relax that as the project stabilizes — but the moment it goes off the rails, narrow back to one. You have roughly 170k of usable context and you re-spend it every iteration, so frugality is survival.

Long Ralph — persistence with structure

The naive loop works for small tasks. To ship something real, it needs structure around it without abandoning the fresh-context principle.

Rules
AGENTS.md is the heart
How to build and run the project — the first file every fresh instance reads. Let it self-improve: a command it got wrong three times becomes a line here for the next loop.
State
fix_plan.md is working memory
Each loop studies it, does one thing, writes back what remains. Huntley watches it like a hawk and throws it out often; a planning loop regenerates it from the specs.
Definition of done
Specs, one per file
Written up front through a long conversation, then saved separately. When the loop builds the wrong thing, the spec is usually the culprit — not the tool.
Division of labor
Sub-agents do I/O, never implementation
The primary context makes the changes. Helpers search, build, test, and study specs. Fan out to hundreds for reads; constrain validation hard, often a single agent, to avoid back-pressure conflicts.
Escalation
The oracle handles what jams
When stuck, consult the strongest, slowest model available. Cheap fast model for the grind; expensive smart model only when the wheel stops turning.
Verification
Back-pressure rejects bad code
Type systems, tests, static analyzers, security scanners — anything that can refuse invalid output. Dynamically typed language with no type checker? You will get a bonfire of outcomes.
The four files and one escalation path that make Ralph survive a real project

Ralph's honest caveats

Huntley is blunt about the boundaries, and any field guide has to carry them faithfully:

  • Ralph is a greenfield technique. In his words, there's no way he'd use it in an existing codebase. It bootstraps new projects, and gets you roughly 90% of the way — not 100%.
  • Senior expertise is non-negotiable. Anyone claiming a tool does 100% of the work with no engineer is, in his phrasing, peddling nonsense. Ralph gets tuned by a senior operator — like a guitar — every time it drifts.
  • You will wake up to a broken codebase sometimes. The call is whether to reset hard and re-run, or craft new prompts to rescue it. That judgment is the job.
06 — Maker / checker

Your agent is the single worst-qualified judge of the code it just wrote.

The one structural move that makes walking away from a running loop defensible.

The most valuable structural decision in any loop is separating the agent that writes from the agent that checks. The reason is simple and human: the model that wrote the code is too loyal to its own work to grade it honestly. It chases its reward function — compiling code — and will happily wave through a placeholder it wrote ninety seconds ago. A second agent, with different instructions and sometimes a different model, catches what the first one talked itself into.

Maker
Writes the diff
Introduces the change and runs a first pass of checks. Generous with itself, by design and by training.
Checker
Reviews it cold
A different agent or model. Reads the diff, runs the full tests, judges whether the change fits the architecture — not just whether it compiles.
Gate
PR or bounce
Pass, and the loop opens a pull request. Fail, and it goes back to the maker with the reason. No human needed until the gate.

This matters specifically inside a loop: the loop runs while you're not watching, so a verifier you actually trust is the only reason you can walk away. It's also, under the hood, what a goal-style stop condition does — a fresh model decides whether the work is done, applying the maker/checker split to the exit condition itself.

One caution: sub-agents burn tokens, since each runs its own model and tool calls. Spend the checker where a second opinion is worth paying for — architecture-bearing changes, security-sensitive diffs — not on trivial edits.

07 — The pipeline

You design this once. Then you stop prompting individual steps forever.

The end-to-end shape, from a planning conversation to a pull request waiting for you.

Set up
Planning and skills
A conversation that produces specs, plus the skills that load your conventions so nothing is re-derived.
Decompose
todo.md and a worktree
The goal broken into atomic items, each getting an isolated checkout so parallel work cannot collide.
Build and verify
Maker ⇄ checker
The maker writes; the checker reviews and tests independently, bouncing it back until it passes.
Act
MCP, then your gate
The loop opens the PR, links the ticket, pings the channel once CI is green. The PR is where your judgment enters.
Planning → skills → todo → worktree → maker ⇄ checker → MCP → PR

The thing to notice: you designed this once. You didn't prompt any individual step. That's the whole idea made real — and it's the same pipeline in Claude Code or Codex, because the pieces are the same pieces.

08 — The ladder

The fastest way to get burned is to climb one rung higher than your checks can carry.

Five levels of autonomy, what each one asks of you, and an honest read on where professional work actually sits.

Loop engineering isn't all-or-nothing. There's a maturity ladder, and the discipline is not climbing faster than your verification can support.

  1. 1Manual controlYou prompt every turn. The agent is a tool you hold. Nothing happens that you did not just ask for. Every engineer starts here and there is no shame in staying.
  2. 2Task reviewYou approve each task. The agent proposes the work; you sign off before it runs. This is where you find out whether your decomposition is real or wishful.
  3. 3Agent in a worktreeYou review the output. The agent works alone in its own checkout. You read the result, not the process. The worktree is what makes walking away survivable.
  4. 4Checker plus PRYou review the PR. A second agent verifies the first, then the loop opens a pull request. Your judgment moves from the diff to the decision.
  5. 5Auto-mergeYou set policy and spot-check. Green checks merge without you. Real, but reserve it for narrow, well-fenced changes where your automation genuinely carries the risk.

Most professional work today lives at levels 3 and 4. Level 5 is real, but reserve it for narrow, well-fenced changes where your automated checks genuinely carry the risk. Climbing a rung before your verification is ready is the single most common way loop engineering goes wrong.

09 — What it costs

Every risk here gets sharper as your loop gets smoother. None of them get milder.

The five failure modes, including the two that do not show up until months later.

This is the section most write-ups skip, and the one that separates a professional from a button-presser.

Money
The token furnace
A badly designed loop can spin for hours, re-deriving context it already had, chasing a goal with no real stop condition — and leave you a bill and no feature. Model this before you let anything run unattended.
Trust
False security
Passing tests do not mean the task was accomplished. A loop optimizing for green can write placeholders, delete inconvenient tests, or satisfy the letter of a spec while missing its intent. Done is a claim; your job is to make it a proof.
Design
Architecture degradation
The quiet killer. A shortcut here, a duplicated abstraction there, an adapter that should not exist. Each diff looks fine alone; the sum drifts toward incoherence. The checker's architecture judgment exists to fight this, and it is the hardest thing to automate.
Comprehension
Cognitive debt
Generation speed is not solution speed. When code appears faster than any human can absorb it, you trade technical debt for the gap between what the codebase does and what anyone understands. Technical debt you refactor. This compounds silently.
Judgment
Critical thinking, off
Automation takes work off the engineer. It does not take responsibility off the engineer. The comfortable posture — accept whatever the loop returns, stop having an opinion — is the dangerous one.
Two people can build the identical loop and get opposite outcomes. One uses it to move faster on work they understand deeply. The other uses it to avoid understanding the work at all. The loop cannot tell the difference. You can.
10 — Integration

Two checklists. One for what you feed the loop, one for the loop itself.

The practical part: what makes a task loop-ready, and what keeps a running cycle from hurting you.

Get the tasks right

Scope
Atomic
One clear unit of work. This is the one-thing-per-loop rule wearing a different hat.
Definition of done
Acceptance criteria
Testable, or the checker has nothing to check against and will approve on vibes.
Instruction
Tuned prompts
Precise, and sharpened by watching where the agent actually misbehaves. There is no perfect prompt, only a tuned one.
Input
Complete context
Specs, conventions, gotchas. Leave a gap and the agent fills it with a confident guess.

Get the cycle right

Ceiling
Limits
Token and iteration caps, so a runaway loop cannot drain the budget while you sleep.
Visibility
Logs
Every run observable after the fact. You cannot tune drift you cannot see.
Constraint
Rules
Guardrails in AGENTS.md defining what the loop may and may not do on its own authority.
Authority
A human gate that stays
The PR review, the merge policy, the call on a broken build. Design the loop so this gate is cheap to keep, not tempting to remove.

Set your loops up. But remember that prompting your agents directly is still effective. This is a balance, not a replacement.

11 — The stack

If you keep one thing from all of this, keep the stack.

Six primitives, each with one job, and the three tensions every design choice resolves.

  1. Ralph → iterations. The engine: fresh context, one thing per loop, disk as memory.
  2. Maker–checker → verification. The trust: the agent that writes never grades its own work.
  3. Worktrees → parallelism. The scale: isolated checkouts, so many agents run without collision.
  4. AGENTS.md → rules. The knowledge: how this project builds, runs, and must not be broken.
  5. Memory → state. The spine: fix_plan.md, git history, and specs holding what's done and what's next.
  6. MCP → workflow. The reach: connectors that let the loop act inside your real environment.
The agent forgets between runs — the repo doesn't. The maker is generous — the checker isn't. The window is finite — the disk isn't.
The three tensions, resolved on purpose

Build the loop. But build it like someone who intends to stay the engineer, not just the person who presses go. The leverage moved. The responsibility didn't.

Sources and further reading

  • Geoffrey HuntleyRalph Wiggum as a "software engineer" (July 14, 2025): the origin of the technique, the fresh-context philosophy, and the canonical prompts. ghuntley.com/ralph
  • Addy OsmaniLoop Engineering (June 7, 2026): the essay that named the discipline and gave it a parts list. addyosmani.com/blog/loop-engineering
  • Boris Cherny (Head of Claude Code, Anthropic) — public talks and posts on writing loops rather than prompts.
  • Peter Steinberger — the sentence that lit the fuse: design the loops that prompt your agents.
  • O'Reilly Radar — republished Osmani's essay on June 22, 2026, carrying it to the wider industry.

The framing, the maturity ladder, the risk taxonomy, and the integration checklists are my own synthesis, drawn from running these loops across a live portfolio of products.

Share
Mental Models for the AI Economy

Get the next essay the day it publishes.

A few a month, written from real builds. Unsubscribe in one click.

George Moreas
About the author
George Moreas

Senior product manager and builder — 15+ years shipping enterprise products (AT&T, BMW Group), now running his own with AI. These essays are field notes from that loop: what AI actually changes about work, product, and the economics underneath. Based in South Florida.