The Ralph Wiggum technique for Claude Code is a simple loop that repeatedly asks the model to work on a task until it outputs a specific completion phrase or hits a safety limit. It works by wrapping Claude Code in a bash while loop that feeds the same prompt and current project state back into the model on each iteration. The official plugin packages this pattern so you can run unattended iterations with a clear finish condition and guardrails.
What is the Ralph Wiggum technique?
Ralph Wiggum is an iterative AI development method built around persistence and clear success criteria. In practice it is a lightweight automation layer that keeps asking Claude to continue until a predefined condition is satisfied.
Ralph is a Bash loop that keep[s] trying until success, with operator skill in prompt writing as the critical factor (Awesome Claude guide).
The approach emphasizes iteration over perfection, treating failures as data that help the next attempt. It shines when tasks have objective pass or fail checks such as tests, linters, or deterministic outputs.
How does the Ralph Wiggum plugin work?
The official plugin adds a command that kicks off a loop inside Claude Code. You provide a prompt, a completion phrase to signal done, and optional limits such as maximum iterations. On each pass the model plans, edits files, runs tools, inspects results, then repeats until your finish condition appears in the models output or the loop times out.
- Input: a concrete task description and a unique completion phrase, for example DONE or FIXED.
- Loop: reissue the task with current context, allow the model to make changes, run tests or checks, summarize progress.
- Stop: exit when the exact phrase is emitted, or when max iterations is reached.
The plugin relies on Claude Codes project context and tools. Compaction helps fit evolving state back into context, but you should still write tight prompts and keep tasks scoped.
What is a completion promise?
A completion promise is the exact phrase the model must print when, and only when, the task is finished. The loop watches for this exact match and stops when it appears.
Think of it as an explicit stop token you define. It is not a fuzzy judgment call, it is a specific string the agent must output after it has verified success.
How to define a good completion promise
- Make it unambiguous and unique: pick a phrase unlikely to appear by accident, for example
<promise>FIXED</promise>or__DONE_AUTH_REFRESH__. - Tie it to verification: instruct the model to emit the phrase only after tests pass, linters are clean, or outputs match checksums.
- Embed instructions in the prompt: explicitly say when to print the promise and that the loop will continue otherwise.
Example prompt snippet: Fix the token refresh logic in auth.ts. Run tests. If all tests pass, print <promise>FIXED</promise> and stop. Otherwise, continue iterating.
When should you use or avoid Ralph Wiggum?
According to the project documentation, Ralph works best for tasks that have clear, objective end states and benefit from iterative refinement (Awesome Claude guide).
Good use cases
- Bug fixing with tests that can be run automatically
- Feature implementation with acceptance tests or CI gates
- Greenfield scaffolding where you can let it run unattended
- Refactoring with static analysis, type checks, and linters
Cases to avoid
- Design work that depends on human aesthetics or product judgment
- One-shot tasks that require immediate, precise human oversight
- Debugging in production environments
- Projects with vague or subjective success criteria
Practical tips and an example command
These practices improve convergence and control token use:
- Set a max iteration limit: always include a safety net, then rerun with adjustments if needed.
- Start small: break work into incremental goals, for example one bug or one test at a time.
- Add self-checks: ask the model to restate requirements, list failing tests, and propose the next step before editing.
- Use automated verifiers: tests, type checks, and linters keep the loop honest and reduce false done declarations.
- Keep context tight: clean up logs, commit periodically, and avoid dumping large unrelated files into context.
Example invocation pattern in Claude Code using the plugin:
/ralph-loop "Fix the token refresh logic in auth.ts. Run tests. When tests pass, print <promise>FIXED</promise> and stop." --max-iterations 10 --completion-promise "FIXED"
If you hit shell or permission errors, ensure the plugin is installed from the Claude Code marketplace, the shell has execute permissions for any helper scripts, and Claude Code is allowed to run commands in your workspace. Running your project locally with a working test command before starting the loop helps avoid environment issues.
Limitations, costs, and model considerations
Loops can consume many tokens if the task is broad or the agent drifts. Scope your prompt, cap iterations, and rely on automated checks to prevent endless tweaking. Context compaction helps, but very large codebases or long logs can still overwhelm the context window, so keep artifacts small and rotate logs.
Newer Claude models are stronger at plan following and staying on task. Users report that these improvements reduce the need for heavy orchestration, though Ralph remains useful for unattended, test-driven tasks. The project site also describes anecdotal successes, such as batch repository generation and a reported contract delivered with modest API costs, which should be taken as case studies rather than guarantees (source).
Best results come when the completion promise is tied to an external verifier, for example tests pass, rather than the models subjective judgment.
If you need higher reliability than a single agent loop can provide, consider pairing Ralph with CI, branch isolation, or running multiple smaller loops in parallel on separate worktrees, as suggested in the community patterns (guide).
