Frontier Foundry

Ralph Loop

The Factory District · AI Coding & Software Factories

Running the same agent prompt in a loop until the spec is done.

Also called: ralph wiggum. In the glossary.

How it works, as a machineThe Night Shift Hut · tickets

Follow one ticket from the job wall to a ticked ledger line, in a night-shift job hut with a ticket wall and a commit gate.

  1. Take the door note
  2. Pick the next ticket
  3. Make one change
  4. Run the tests
  5. Tick and commit
Play Ralph Loop

Ralph Loop in plain words

A Ralph loop feeds the same prompt to a coding agent again and again, each time in a fresh context, until the spec is done. Progress is kept in files on disk, not in the agent's memory. It is a crude, cheap way to keep an agent working, and it needs something outside it to say when to stop.

An analogy

A night shift where each hour brings a new worker who remembers nothing of the last. Each reads the same note on the door, looks at the list on the wall, does the next unticked job, ticks it and leaves. Only the list remembers, and only the foreman can call the shift over.

How Ralph Loop connects

5 typed relations in the knowledge graph

Builds on

  • Coding Agents: Each lap is one coding agent run: read, edit, run the tests, stop.
  • Software Factory: A software factory is this lap with gates, queues and review stacked around it.

Built on by

  • Coding Agents: A goal that is re-prompted until the model reports it met is a loop around this loop.
  • Software Factory: The bare while-true loop that restarts an agent against the same spec is the simplest thing a pod can run.

Makes possible

See Ralph Loop in the knowledge graph

Who is behind Ralph Loop

people, labs, products and models

People

  • Geoffrey Huntley (coined): The Ralph loop: run the same agent prompt in a loop until the spec is done ('everything is a ralph loop').

Named in its facts

What the sources say

3 parts · 9 sources · updated 2026-11-27

A Ralph loop gives a coding agent the same prompt again and again, each lap in a fresh context, until a list of tickets is done. Progress lives in files and git, not in the agent's head. The loop is crude and cheap; the sources agree it needs a check outside the worker to say when a ticket is really done.

The same note, a fresh head

Every lap starts the same way: a new worker with an empty head reads one note that never changes, looks at the wall of tickets and picks the next one. What the last worker did is only in files and in git.

  1. The door note board holds one note that never changes; each fresh worker reads the same words.
  2. The job wall holds every ticket; the worker picks the next most important one itself.
about 100,000 tokens
Where one speaker, who runs the technique, keeps a lap's context to stay in the smart zone; raised to about 200,000 for a million-token window. A guideline, not a measurement Dex Horthy
ten dollars forty-two an hour
What a coding agent run in a loop works out to, in a calculation two of the debaters made a year earlier Geoffrey Huntley
about three days
How long a scheduled repeat started inside a Claude Code session lasts before it must be refreshed, as the workshop speaker reports Chris Parsons
  • The Ralph loop is the idea that, whenever an AI finishes a task, you give it exactly the same prompt again and see what it does. Chris Parsons
  • The technique works because an agent that stops before the job is finished will, given the prompt again, review its work and find what it missed. Chris Parsons
  • The dumbest Ralph loop is a shell while-true loop that starts the coding agent on the same command each time; an early plugin that re-ran the command from a stop hook did not get far. Chris Parsons

When it breaksTwo workers took the same ticket. The workshop speaker planned a whole project into tickets with a dependency graph and set a handful of agents on it in parallel. They could not tell what was done, both waited on a shared ticket, and both built it, a huge mess. Chris Parsons

Open questionShould every lap start with an empty context, or can one long session carry the loop?

  • Yes. Compaction loses detail every time, like uploading a video again and again, so give each lap everything it needs in a fresh window. Geoffrey Huntley
  • Not always: with a one-million-token window and a newer model Anthropic moved its harness from new context windows to one long session with compaction; which is better depends on the use case and the evals. Andrew Wilson

One change, tested by the worker

The worker makes one change and runs its own tests. How much it can do alone depends on what feedback the loop gives it, and on whether the worker can reach the things that check it.

  1. At the change bench the worker makes exactly one change for the ticket it picked, then stops.
  2. At the test bench the worker runs the tests and reads what its change does.
5% → 50%
A speaker's own illustration of compounding: a 5% chance of an error in one run, repeated over 10 to 20 loops, leaves about a 50% chance the result is right, or less. Not a measurement Greg Pstrucha
eight to nine hours
How long an unattended loop may burn tokens while its owner waits and hopes, as a maintainer describes loop-driven commit maximising Vincent Koc
  • The speaker's loop skill tells the worker to check git state first: a dirty tree with passing tests is probably done but worth a double check, failing tests mean broken mid-flight work to throw away. Chris Parsons
  • A good prompt for a lap names the method and the end: implement the next most important ticket using test-driven development and commit when done; a vague one may build a ticket and never ship it. Chris Parsons
  • On a repeat of the same prompt a newer model notices the ticket is already done instead of redoing it, where a year earlier it would have missed something. Chris Parsons

When it breaksThe worker turns off the rule that checks it. A loop that checks its work with lint rules or type settings in the same repository can have the agent switch those rules off with inline comments. The HumanLayer team instead writes its sensor with a tool that sits outside those configs. Kyle Mistele

What closes the loop

A lap ends when the worker says it is done, but the sources say the loop should close only when something outside the worker agrees: a hook on the commit, a second worker with a small context, or a person who reads what came out. Each costs money or speed.

  1. The commit gate runs checks the worker cannot edit and sends a failing change back to the bench.
  2. The ledger desk ticks the ticket done, commits the change and the worker leaves with an empty head.
about five dollars a PR
What one engineer says the team's security scans on every pull request cost, a price they chose to pay on purpose Greg Pstrucha
six months
How long migrating 150 procedures one at a time would take, the speaker says: the price of a loop that waits for review before it makes the next change Kyle Mistele
forty thousand lines
Size of the pull requests a loop piped straight to an agent can produce, which nobody wants to read Kyle Mistele
  • Huntley uses pre-commit hooks, formatters, static analysers, deterministic tests and simulators as back pressure, to prevent the loop from closing until it meets the engineering requirements. Geoffrey Huntley
  • When an agent skipped his diagnostics library, Huntley added a pre-commit hook that checks the diff, fails the commit and injects a prompt telling the agent to use the library; the result was ten out of ten. Simon Willison
  • An attendee found that validation in the same context just praises the work while a sub-agent started finding problems; the speaker agrees agents show confirmation bias and a sub-agent starts with a small context. Chris Parsons

When it breaksDone, one hundred percent, and not done. In the technique's early days an agent would end its run and declare the work finished, then on the next pass of the same prompt find something it had missed and declare it finished again. Skeptics at the loops debate say loops fail this way: the agent declares victory early on a half-finished job. Chris Parsons

Open questionIs there a gap between the hype around loops and what works?

  • No gap that matters: loops are here and inevitable, though not a silver bullet. Geoffrey Huntley
  • There is a gap: loops are fine but the hype is outrunning the discipline, and someone still has to read the code. Dex Horthy

Sources

9 in all

More in AI Coding & Software Factories

The Factory District: the whole area
  • Coding AgentsAgents that read, write, run and test code in a repo (Claude Code, Codex, Cursor agents).
  • Software FactoryRunning many coding agents as a production line: specs in, verified software out, humans as supervisors.
  • Vibe CodingBuilding software by prompting and accepting AI output without reading the code closely.
  • Spec-Driven DevelopmentWriting precise specs (and tests) first so agents can implement and verify against them.
  • AI Code ReviewModels reviewing pull requests and catching bugs before merge.
  • Parallel AgentsRunning many agent sessions at once (worktrees, cloud sandboxes) on separate tasks.
  • Verification Loops & BackpressureTests, type checks, linters and judges that push back on agent output so it self-corrects.
  • AI SlopLow-quality AI output that looks plausible and costs others time to clean up.