The Ralph loop
Feed the same prompt to an agent forever, with progress kept in files. The bash one-liner that started the loop discourse.
The dumbest smart way to run coding agents.
The idea
Named after Ralph Wiggum, the Simpsons character known for cheerful, oblivious persistence, the technique was described by Geoffrey Huntley in July 2025. In its purest form:
while :; do cat PROMPT.md | claude -p; donePROMPT.md describes the whole job, for example "implement the spec in SPEC.md, one item at a time; update PROGRESS.md; commit when tests pass." The agent runs headless, does some work, exits, and is immediately started again with the same prompt and a fresh context window.
Why it works better than it should
Fresh context every iteration
No context rot. Each run starts clean, reads the plan and the progress file, does one chunk of work, and writes back. A practitioner who measured this found fresh-context iteration with state on the filesystem was the most effective fix for degradation, at a 15–20% "orient" overhead per pass (Blake Crosley). anecdotal
The workspace is the memory
Each iteration re-enters a workspace that already contains evidence of the previous attempts: commits, test output, notes (Steve Kinney). "The files are the memory."
Mistakes are cheap to retry
A bad iteration is one iteration. The next one starts fresh and can see that the tests are red.
Where it breaks
- It only works if the agent can verify its own work. Without tests, type checks or another signal, Ralph happily loops on broken code (Sid Bharath).
- It never stops on its own. The naive loop burns API credits and produces inconsistent results (Kingy AI).
- It can thrash. A stuck loop can hammer the same error for hours.
From hack to feature
The evolution of Ralph mirrors the evolution of the whole field:
- The bash loop. No exit, no budget. Ctrl+C is the judge.
- Hardened scripts. Community versions such as frankbria/ralph-claude-code add exit detection, rate limiting and circuit breakers. open-ralph-wiggum runs Claude Code, Codex, Copilot or OpenCode in the same loop.
- The official plugin. Anthropic's ralph-wiggum / ralph-loop plugin moves the loop inside a Claude Code session: a Stop hook catches the agent's attempt to finish, returns exit code 2 to block it, and re-injects the prompt.
--max-iterationscaps it and--completion-promisedefines a string that ends it (plugin, DeepWiki, listing). /goal. The loop becomes a harness primitive with an evaluator, a budget and states. Simon Willison described Codex's version as "a built-in Ralph loop" (blog); Hermes' docs call its/goal"our take on the Ralph loop" (docs).
Ralph vs. /goal: one real difference
Classic Ralph uses fresh context on every iteration. Built-in /goal modes continue in the same session, so the
context grows (with compaction) unless the harness resets it. That affects both quality (context rot) and cost (context
re-read on every turn). See Cost.
Further reading
- Entering the Mind of Ralph Wiggum by Steve Kinney
- Ship Features in Your Sleep with Ralph Loops from geocod.io
- What Is a "Ralph Loop"? How a Bash One-Liner Became an AI Coding Pattern
- What is Codex /goal? How it replaces "keep going" prompts
- No plugins needed: I built a fully automated coding loop in OpenCode