What is a Ralph loop?
Length:
6 min
Published:
December 2, 2026

What is a Ralph loop?
A Ralph loop, also called the Ralph Wiggum technique, is a way of running an AI coding agent. You give the agent the same prompt again and again, in a loop, until the task is done. Geoffrey Huntley, who described the technique in July 2025, puts it in one sentence: "In its purest form, Ralph is a Bash loop."
while :; do cat PROMPT.md | claude-code ; done
In the original bash loop, the agent remembers nothing from one round to the next, because every round starts with an empty context window. What carries the work forward is what it leaves on disk: changed files, commits and a plan with finished items ticked off. Each round reads that state, picks the next piece of work, does it and exits.
The name comes from Ralph Wiggum, a character from The Simpsons. In April 2026 the Thoughtworks Technology Radar placed the technique in its Assess ring and summed it up as "a fixed prompt is fed to an agent in an infinite loop."
In plain words
Picture a house painter who forgets everything overnight. Every morning they arrive with the same note. It says: "Read the list on the door, do the next job, tick it off and go home." The painter remembers nothing, but the list and the painted walls are still there the next day. After enough mornings the house is finished. A Ralph loop works the same way: the agent forgets, and the files remember.
How it works
A Ralph loop has three parts:
- A fixed prompt. The prompt stays the same in every round. It says what the goal is, where the plan and the specification live, and what counts as done. Huntley's rule for a round is "One item per loop": one task per round, so the agent uses as little of its context window as it can.
- State outside the model. The plan, the specification, the code and the git history are the agent's memory. Each round reads them, changes them and leaves them for the next round.
- A way to stop. A bare
while :loop never ends on its own. In practice, the loop ends when the agent reports that the task is done, or after a set number of rounds.
Anthropic publishes the technique as the Ralph Loop plugin for Claude Code. It needs no outer bash loop. A Stop hook blocks Claude's attempt to end the session and feeds the same prompt back in:
/ralph-loop "Build a REST API for todos. Requirements: CRUD operations, input validation, tests. Output <promise>COMPLETE</promise> when done." --completion-promise "COMPLETE" --max-iterations 50
The --completion-promise option names the phrase that signals completion, and --max-iterations stops the loop after that many rounds. The plugin's README tells you to always set the limit, because the completion check is an exact string match.
The two forms differ in one way that matters. The plugin loops inside your current session, so the context carries over from round to round. Huntley's bash loop starts the agent again in every round, which gives each round a fresh context window. Thoughtworks names the trade-off. A fresh context keeps quality from degrading as the context fills up, and it costs a lot of tokens. A long session runs into context rot instead.
When a Ralph loop fits
The loop pays off when a machine can tell whether the work is done. The plugin's README recommends it for four kinds of tasks:
- well-defined tasks with clear success criteria,
- tasks that need several rounds of refinement, such as getting tests to pass,
- greenfield projects you can walk away from,
- tasks with automatic verification through tests or linters.
Huntley is specific about where he uses it: "This works best as a technique for bootstrapping Greenfield, with the expectation you'll get 90% done with it."
The loop moves the work from writing code to writing the specification, the plan and the checks. A failed round is a signal about the prompt. In Huntley's words, "Each time Ralph does something bad, Ralph gets tuned - like a guitar." That is why the technique sits close to spec-driven development and test-driven development. The spec tells the loop what to build, and the tests tell it when to stop.
How we run loops like this
Our own agents run as headless Claude Code sessions on a schedule, which makes them close relatives of the Ralph loop. The same instruction starts again and again, and each scheduled run begins with a fresh context. Everything the next run needs lives outside the model: in the GitHub issue, in a checkpoint comment and in commits on the task branch. Unlike a pure Ralph loop, the agents hand their work over as pull requests, and people merge almost all of them.
What running these loops taught us:
- An idle loop still costs money. One of our agents kept starting its scheduled work although the same unsolved problem blocked all of it. Over six days it posted 31 comments on one issue, up to 13 a day, each saying in effect that the work was still blocked. Now a script with no model checks before each run on our task board whether there is any work at all, and the model starts only if there is.
- Stop when nothing changes. The same script stops a lane once it has handed out the same work three times while nothing about the task changed, and it sends the owner one message. It works like
--max-iterations, except that it counts only the rounds in which nothing changed. - Read the state from where the latest work is. In September 2026, one of our runs read its progress marker from the main branch while the previous run's result was still waiting in an open pull request. It rewrote the notes from two meetings from scratch and opened a second pull request with the same content, which we closed three minutes later. Since then, every run checks its own open pull requests and its working tree before it starts.
- Commit after every step. Our content agents commit after each phase of an article. A run that gets cut off leaves a branch that the next run can pick up, often in a separate git worktree.
What to watch out for
- A loop needs an automatic check. Without tests, a linter or another check that a machine can run, the loop cannot tell good work from bad, and it keeps going anyway. The plugin's README lists tasks with unclear success criteria and tasks that need human judgment or design decisions as a poor fit.
- Always set a limit. The README says to always use
--max-iterations"as a safety net to prevent infinite loops on impossible tasks". Without a limit, a task the agent cannot finish turns into an open-ended bill. - Each round costs tokens. A round that starts fresh reads the plan, the specification and the relevant code again. Watch what one round costs before you let the loop run overnight. Our article on tokens explains what you pay for.
- Production incidents need targeted work. The README lists production debugging as a poor fit and recommends targeted debugging instead.
- Review does not go away. A loop that ran all night leaves a lot of code to read. We keep a human in the loop at the end. The gates we use for an agent that writes code are in running autonomous coding agents in production. If you are setting up this kind of workflow for a team, our two-day training on Claude Code and Cursor covers planning, tests, review and team rules.
Related articles:
- Agentic coding – The way of working in which an agent plans, edits and tests code on its own before it hands anything back.
- What is vibe coding? – Building software through prompts while you steer every step yourself. In a Ralph loop, the prompt and the checks do the steering.
- What are Claude Code hooks? – The mechanism behind the official plugin, which uses a Stop hook to keep the session going.
- What is an agent harness? – The runtime around the model, where the loop, its limits and its tools live.
- What is context rot? – Why a long session degrades, and why the original loop starts every round fresh.
- What is spec-driven development? – Writing the specification first, which gives a loop something to converge on.
Want to stay one step ahead?
Don't miss our best insights. No spam, just practical analyses, invitations to exclusive events, and podcast summaries delivered straight to your inbox.