The Ralph Wiggum Approach: Running AI Coding Agents for Hours (Not Minutes)
Source: Dev.to
We’ve all been there. You fire up Claude Code, drop in a prompt like “build me a REST API for todos,” and hope for the best. Maybe it works. Maybe it doesn’t. Either way, you’re staring at your screen, watching tokens burn, wondering if the agent is making progress or just spinning its wheels.
The fundamental issue? Traditional AI coding is a one‑shot deal. You get one context window, one shot at the problem, and then you’re either done or you’re not.
A Better Idea: Run the Same Agent Multiple Times
What if you ran that same agent, on the same prompt, 10 times in a row?
- Each iteration picks up where the previous one left off.
- The agent sees what it previously did (via git history and modified files).
- It iterates, improves, and gets closer to “done” each time.
That’s the Ralph Wiggum approach – and it’s genuinely game‑changing.
Try Ralph Right Now
1. Install the plugin
/plugin install ralph-wiggum@claude-plugins-official
2. Run your first loop
/ralph-loop "Add JSDoc comments to all exported functions in src/utils/" \
--max-iterations 10
3. Check the git diff when it finishes
That’s it. You just ran your first autonomous loop. Claude iterated on the same task 10 times, improving its work each time, until it was done.
The Core Insight
Iteration beats perfection.
The technique comes from Geoffrey Huntley, who described it simply:
while :; do
cat PROMPT.md | claude
done
The name comes from Ralph Wiggum of The Simpsons – perpetually confused, always making mistakes, but never stopping. That’s the vibe.
At its core, Ralph repeatedly feeds an AI agent the same prompt until a stop condition is met. The agent sees its previous work (via git history and modified files), learns from it, and iteratively improves.
“The technique is deterministically bad in an undeterministic world.
It’s better to fail predictably than succeed unpredictably.”
Even Matt Pocock is a fan:
“Ralph Wiggum + Opus 4.5 is really, really good.”
How the Plugin Works
- Invoke
/ralph-loopwith a prompt and completion criteria. - Claude works on the task.
- When Claude tries to exit (thinks it’s done), the Stop hook intercepts it using exit code 2.
- The hook checks for your completion promise (e.g.,
COMPLETE). - If the promise isn’t found, the original prompt is re‑fed and Claude continues.
- Each iteration sees the modified files and git history from previous runs.
Example Command
/ralph-loop "Migrate all tests from Jest to Vitest" \
--max-iterations 50 \
--completion-promise "All tests migrated"
The loop continues until Claude outputs the completion promise or you hit the iteration limit.
Walk‑through Example: Jest → Vitest Migration
Prompt
Migrate all tests from Jest to Vitest.
- Update all test files to use Vitest syntax
- Update package.json scripts
- Remove Jest dependencies
- Add Vitest dependencies
- Run tests after migration
Output MIGRATED when all tests pass.
What Happens
| Iteration | What Claude Does |
|---|---|
| 1 | Updates test files to Vitest syntax; tests fail |
| 2 | Fixes syntax errors; tests still fail |
| 3 | Updates package.json, removes Jest, adds Vitest |
| 4 | Runs tests, they pass, outputs MIGRATED |
You wake up to a fully migrated test suite. No manual re‑prompting, no debugging in between. Just set it up and let it run.
Real‑World Success Stories
| Project | Outcome |
|---|---|
| Cursed programming language | Built over 3 months with a single Ralph loop: functional compiler, LLVM backend, stdlib, partial editor support. Keywords include slay (function), sus (variable), based (true). |
| 6+ repositories overnight | Y Combinator hackathon teams shipped multiple repos for $297 in API costs – work that would have cost $50 K in contractor time. |
| 4‑minute → 2‑second tests | One developer migrated integration tests to unit tests while sleeping; the loop handled the mechanical conversion automatically. |
| Full APIs with TDD | Iteratively built features, ran tests, fixed failures, and repeated until all tests passed. |
These are cherry‑picked successes. For every overnight win, there are loops that burned through iterations without converging. Failed attempts still cost money. But when it works, it works remarkably well.
Ideal Use‑Cases
| Use‑Case | Example Prompt |
|---|---|
| Large refactors | "Convert all class components to functional components with hooks. Output MIGRATED when npm run typecheck passes." |
| Framework migrations | "Migrate all tests from Jest to Vitest. Output COMPLETE when all tests pass." |
| TDD workflows | "Implement the checkout flow to make all tests in checkout.test.ts pass. Output TESTS_PASS when done." |
| Test coverage | "Add tests for all uncovered functions in src/." |
| TypeScript adoption | "Add type annotations to all functions in src/utils/." |
| Greenfield builds | "Build a REST API with CRUD operations. Output COMPLETE when all endpoints work and tests pass." |
The common thread: well‑defined success metrics. If you can describe “done” precisely, Ralph can iterate toward it.
When Not to Use Ralph
- Ambiguous requirements – If you can’t define “done” precisely, the loop won’t converge.
- Architectural decisions – Novel abstractions need human reasoning, not blind iteration.
- Security‑sensitive code – Auth, payments, data handling need human review at each step.
- Exploratory debugging – “Figure out why the app is slow” isn’t a good Ralph task.
Ralph automates the mechanical execution, not the decision‑making about what’s worth building.
Common Pitfalls (and How to Avoid Them)
| ❌ Mistake | ✅ Remedy |
|---|---|
| Too ambitious on first run | Start with a small, clearly bounded sub‑task. |
| Vague completion criteria | Use an explicit “ token that can be reliably detected. |
| Forgetting to keep CI green | Run your CI after each iteration (or integrate it into the loop). |
| Not monitoring costs | Set a reasonable --max-iterations and watch token usage. |
| Using it for non‑deterministic tasks | Reserve Ralph for deterministic, mechanical work only. |
TL;DR
Traditional AI coding is a one‑shot affair. Ralph Wiggum turns it into a repeatable loop that iterates until a concrete success signal appears.
- Install the plugin.
- Define a clear “ completion token.
- Run
/ralph-loopwith a sensible iteration limit. - Monitor cost, CI status, and the promise output.
When used on well‑scoped, mechanically‑driven tasks, Ralph can turn a single prompt into a fully‑automated development pipeline. Happy looping!
Judgment‑Heavy Tasks
The agent commits its work at each iteration and appends progress to a progress.txt file. This serves as:
- A log for future iterations to read
- Documentation of what was attempted
- A way to prevent the agent from repeating mistakes
This is critical. Each iteration must pass tests and type checks. Committing broken code hamstrings future iterations and creates a debugging nightmare.
Rule: If tests fail, the agent must fix them before continuing.
Precise Exit Criteria
Most people trip up because their success criteria are vague.
| ❌ Bad Prompt | ✅ Good Prompt |
|---|---|
| “Build a todo API and make it good.” | “Build a REST API with CRUD operations. Input validation required. Tests must pass (> 80 % coverage). README with API docs. Output COMPLETE when done.” |
Note: The
--completion-promiseflag uses exact‑string matching, which is unreliable. Use--max‑iterationsas your real safety net.
Why Iteration Limits Matter
Autonomous loops burn tokens. A 50‑iteration loop on a large codebase can easily cost $50‑100+ in API credits, depending on context size. On a Claude Code subscription you’ll hit usage limits faster.
Best Practices
- Set
--max-iterationsconservatively (start with 10‑20). - Scale up once you understand the token‑consumption pattern.
- Use tests / build success as the completion criteria, not Claude’s self‑assessment.
- Monitor usage during longer runs.
Common symptoms & quick fixes
| Symptom | Quick Fix |
|---|---|
| Loop stuck in infinite cycle? | Check --max-iterations and progress.txt for the blocker. |
| Tests keep failing? | Fix the failing tests before the next iteration. |
| Costs too high? | Lower --max-iterations or narrow the task scope. |
| Claude says “done” but it isn’t? | Verify test results and CI status. |
Pros & Cons
| ✅ Pros | ❌ Cons |
|---|---|
| Ships code while you sleep | Can burn through tokens quickly |
| Great for mechanical tasks | Not ideal for judgment‑heavy work |
| Self‑correcting feedback loop | Requires good prompt engineering |
| Reduces manual re‑prompting | Can get stuck if criteria are vague |
| Builds on git history | Windows setup has a jq dependency |
| Growing ecosystem of tools | Learning curve for effective prompts |
Ecosystem Highlights
ralph-claude-code– 364 ⭐. Adds rate limiting, tmux dashboards, circuit breakers for failure recovery, and intelligent exit detection.ralph-orchestrator– Adds token tracking, spending limits, git checkpointing, and multi‑AI support.
These tools solve operational challenges: cost control, state recovery, and monitoring. The official plugin provides the core mechanism; the ecosystem builds the production wrapper.
Frequently Asked Questions
-
Can I use this with other AI tools?
Yes – the pattern is tool‑agnostic; just adapt the loop logic. -
What if Claude gets stuck?
Use a conservative--max-iterations. The loop will stop automatically. -
Can I run multiple loops at once?
Technically possible, but watch token usage and git conflicts. -
Does this work with large codebases?
It does, but you’ll need higher iteration limits and careful token budgeting. -
Can I pause and resume a loop?
Use/cancel-ralphto stop. To resume, run the same command again – Claude will pick up from git history.
Getting Started
-
Install the official plugin
/plugin install ralph-wiggum@claude-plugins-official -
Windows users: The plugin has an undocumented
jqdependency that breaks on Windows/Git Bash. Installjqfirst or use WSL. -
Available commands
/ralph-loop "" --max-iterations N /ralph-loop "" --max-iterations N --completion-promise "text" /cancel-ralph # Kill active loop -
Start small – pick a mechanical task with clear success criteria:
- Install the plugin (≈ 30 s)
- Prompt:
Add JSDoc comments to all exported functions in src/utils/ - Run with
--max-iterations 10
-
Review the git diff when it completes.
If the first attempt doesn’t converge, refine your success criteria and try again.
Community & Contribution
- Try it yourself – start with a small, safe task.
- Join the community – check out the GitHub repos and Discord.
- Share your results – post what you built with Ralph.
- Contribute – the ecosystem is growing; there’s room for new tools.
- Stay updated – follow Geoffrey Huntley and the Claude Code team.
Mindset Shift
| Traditional AI Coding | Ralph Approach |
|---|---|
| One‑shot perfection | Iteration over perfection |
| Failures are setbacks | Failures are data |
| Prompt once | Prompt, observe, repeat |
| Operator hopes | Operator designs loops |
| Direct step‑by‑step | Write prompts that converge |
The skill shifts from “directing Claude step‑by‑step” to “writing prompts that converge toward correct solutions.” Your job becomes: How do I set up conditions where iteration leads to success?
TL;DR
Stop expecting one‑shot perfection from AI coding agents. Run them in loops, track progress, keep CI green, and let iteration do the heavy lifting. Ship while you sleep.
Have you tried Ralph or a similar approach? What’s been your experience? Drop a comment below.
Sources
- Geoffrey Huntley on Ralph
- Official Claude Code Plugin
- Ralph for Claude Code (community fork)
- Ralph Orchestrator
- BetterStack YouTube Video (60 K views)
- Paddo.dev Deep Dive