What Is a Ralph Loop? The Ralph Wiggum Technique for Coding Agents

Raghav Chamadiya8 min read
On this page

A ralph loop is a way of running a coding agent: you feed the same prompt to the agent over and over, each pass in a fresh context window, and the agent picks one task from a spec, does it, commits and exits, and the loop starts the next pass. The name comes from Ralph Wiggum of The Simpsons, and the pattern is also called the ralph wiggum technique, the ralph wiggum loop or just Ralph.

It sounds too dumb to work. It does because nothing important lives in the model's memory: the task list, progress notes and code live in files and git.

What is a ralph loop?

A ralph loop is a repeated, autonomous run of one agent against a spec, where each iteration gets a fresh context and the state is kept in files, not in the conversation. Geoffrey Huntley, who named and popularized it, published the original in Ralph Wiggum as a "software engineer" (July 14, 2025). He describes it as "deterministically bad in an undeterministic world": it fails in predictable ways, and you tune it by watching the failures and fixing the setup so they do not repeat. The whole technique, as he wrote it, is one line of shell:

bash
while :; do cat PROMPT.md | claude-code ; done

Thoughtworks put it on its Technology Radar in the Assess ring in April 2026. Their description has the same shape, with the codebase converging toward the spec over repeated iterations.

How a ralph loop works, step by step

Each iteration does the same five things, and only the files change between passes.

  1. The loop starts a new agent process with an empty context window and the same PROMPT.md.
  2. The agent reads the spec and the progress record: a task list, a progress log and the git history.
  3. It picks the single most important unfinished task. One task per iteration is the rule.
  4. It implements the task and runs the checks: tests, type checker, static analysis.
  5. If the checks pass, it commits and updates the progress record. Then the process exits and the loop starts the next one.

The loop ends when the spec is satisfied or when you stop it. A small, fresh window keeps each pass focused, and the cost is that the agent remembers nothing it did not write down.

Ralph loop implementations compared

There are three implementations worth knowing: Huntley's bash loop, snarktank/ralph, and Anthropic's ralph-loop plugin. They differ most in where the loop runs and where the state lives.

Huntley's bash loopsnarktank/ralphAnthropic ralph-loop plugin
Where the loop runsAn external shell while loopAn external bash script, ralph.shInside your current Claude Code session
How it repeatsPipes PROMPT.md into the agentLaunches a fresh agent per iterationA Stop hook blocks exit and feeds the same prompt back
Context per iterationFreshFreshSame session (inferred from how it runs)
StateA plan file and gitprd.json (stories with a passes flag), progress.txt, gitFiles and git, as seen by the agent
AgentAny CLI agentAmp by default, Claude Code with --tool claudeClaude Code
Stop conditionYou stop itAll stories pass, then <promise>COMPLETE</promise>--completion-promise match or --max-iterations
Iteration capNone10 by defaultUnlimited by default

Scroll the table sideways to see every column.

The snarktank/ralph repo runs typecheck and tests before each commit and appends what it learned to progress.txt and to AGENTS.md. The official plugin (the ralph-loop entry in Anthropic's claude-plugins-official repo) works differently: it uses a Stop hook, which is a script Claude Code runs when the agent tries to finish. See Claude Code hooks for how that event works.

How to run a ralph loop in Claude Code

The shortest route is the official plugin: one command starts the loop, and a Stop hook keeps it going until a completion string appears or the iteration cap is hit. The plugin's README gives this form:

text
/ralph-loop "<your prompt>" --max-iterations <n> --completion-promise "<text>"
  • --max-iterations caps the passes. The default is unlimited, and the README recommends always setting it.
  • --completion-promise is an exact string match. The loop ends when the agent outputs that string, usually <promise>COMPLETE</promise>. It cannot express more than one end condition.
  • /cancel-ralph stops a running loop.
  • On Windows the plugin needs Git for Windows bash.

For true fresh-context passes, use the bash form: Huntley's one-liner, or ralph.sh from snarktank/ralph with --tool claude. Either way, run it in a sandbox or on a throwaway branch.

What makes a ralph loop work

A ralph loop works when three things are true: there is a spec, there is backpressure, and each pass does one task.

  • A spec. A PRD, a task list or a plan file that says what done means. A vague goal gives the loop nothing to converge toward, and it will burn passes producing plausible noise.
  • Backpressure. Huntley's term for whatever rejects bad work: tests, type checkers, static analysis. The loop is only as good as these checks, because the agent will commit whatever passes them. His prompts also forbid placeholder implementations.
  • One task per loop. The agent chooses the most important item, does it, and stops. Small passes keep the context small and each commit reviewable.

Anthropic's write-up on long-running agents (November 26, 2025) lands on the same shape. Harness engineering is the broader frame for these controls, and the ralph loop is its simplest runnable form.

Where a ralph loop struggles: existing codebases and cost

A ralph loop struggles on vague goals, on existing codebases and on your token bill.

Huntley is direct about the second one. He says you can get most of the way on a greenfield project and advises against using the technique on an existing codebase. Thoughtworks flags the third: the Radar entry warns of significant token cost, since you pay for every pass whether or not it moves the spec forward. Amplitude's week-long experiment (May 13, 2026) found verification and human judgment mattered more than the loop.

The loop is the easy part; the checks around it decide whether the output is any good. Ralph is the simplest member of the family that loop engineering designs.

On an existing codebase, every fresh-context iteration starts knowing nothing about the repository. In a greenfield project the agent wrote the code a few passes ago and the progress log describes it. In a real repo the agent has to rediscover the layout, the callers, the conventions and the hot spots each time, and it does that with grep and whole-file reads.

Run fifty iterations and you pay for the same exploration fifty times, and the agent still misses things: a caller in a module it never searched, a file that keeps breaking, a decision that forbids what it is about to do.

This is the part of the loop an index fills in. repowise indexes the repository once (dependency graph, git history, ownership, code health, recorded decisions) and serves it over MCP, so a fresh iteration can ask instead of search.

What repowise gives each ralph loop iteration

A fresh context window knows nothing about the codebase, and repowise hands each iteration that knowledge in one call. get_answer returns a cited answer to the question the task raises, get_risk says what history records about a file before the edit, and get_change_risk() checks the uncommitted diff before the commit, so backpressure knows what the change touched as well as whether the tests pass. The hooks, the opt-in health gate and the rest of the setup are in harness engineering.

A PROMPT.md that uses them

Here is the part of a PROMPT.md that wires those calls into each iteration. The task-list file and test command are placeholders for your own.

markdown
# Each iteration

1. Read `progress.txt` and the first unfinished item in `prd.json`.
2. Before searching the repo, call `get_answer` with the question the task
   raises. Use `get_context` on the files it names. Do not grep for what
   these tools can tell you.
3. Before editing any file, call `get_risk` on it. If it has a bug-fix
   history or many dependents, read the dependents it lists first.
4. Implement the one task. No placeholder implementations.
5. Run the tests and the type checker.
6. Before committing, call `get_change_risk()` on the uncommitted diff. If it
   reports a worse file or a changed line with no covering test, fix that
   first.
7. Commit, append what you learned to `progress.txt`, mark the item passing.
8. If every item passes, output <promise>COMPLETE</promise>.

With these calls, each fresh iteration starts knowing the callers, history and decisions around the file it is about to change, and the diff gets a check before it lands. To wire the tools and hooks into your agent, start at setting up your agent.

FAQ

What is the Ralph loop?
A ralph loop is a technique where one coding agent runs the same prompt in a repeated loop against a spec or task list until the work is done. Each iteration gets a fresh context window, does one task, and records progress in files and git. Geoffrey Huntley popularized it, and it is also called the ralph wiggum technique.
Why is the Ralph loop named after Ralph Wiggum?
Geoffrey Huntley named it after the Simpsons character when he published the technique in July 2025. He describes it as deterministically bad in an undeterministic world: it fails in predictable ways, so you improve it by tuning the setup each time it fails.
Are Ralph loops still relevant?
Yes, though the framing has moved. Thoughtworks placed the ralph loop in the Assess ring of its Technology Radar in April 2026, and Anthropic ships an official ralph-loop plugin for Claude Code. The idea of a fresh-context pass repeated against a spec now sits underneath the broader practice of loop engineering.
How do I stop a Ralph loop?
With the official plugin, run /cancel-ralph, or let the loop end on its own when the agent outputs the exact --completion-promise string or reaches --max-iterations. With a bash loop, interrupt the shell with Ctrl+C. Set a cap or a completion condition before you start, because the plugin's iteration default is unlimited.
How much does a Ralph loop cost?
It depends on how many iterations run and how much each one reads and writes, so no single figure applies. Thoughtworks warns of significant token cost, since every pass is a full agent run. Set --max-iterations, keep tasks small, and cut the exploration each pass does so you stop paying to rediscover the repo.