Ralph Wiggum
Youβve probably been here: you ask an AI agent to implement a feature, it writes some code, declares victory, andβ¦ the tests fail. You prompt again. It tries a different approach. Still broken. Three iterations later, youβre doing it yourself.
Ralph Wiggum flips this dynamic. Instead of hoping for first-try perfection, you design for iteration. The agent keeps running until the work is actually completeβtests pass, types check, linting clears. No premature exits. No false victories.
The core idea
Section titled βThe core ideaβAt its simplest, Ralph is a bash loop:
while :; do cat PROMPT.md | claude ; doneThatβs it. Feed the agent the same task repeatedly. Each iteration builds on the last through git history and progress tracking. The agent doesnβt need to be perfectβit just needs to be persistent.
The philosophy: Iteration beats perfection. Deterministic failures are data. Keep trying until success.
How it works
Section titled βHow it worksβRalph wraps the standard AI tool loop with an outer verification layer:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ Ralph Loop (outer) ββ ββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β AI SDK Tool Loop (inner) β ββ β LLM β tools β LLM β tools ... until done β ββ ββββββββββββββββββββββββββββββββββββββββββββββββββ ββ β ββ verifyCompletion: "Is the TASK actually complete?" ββ β ββ No? β Inject feedback β Run another iteration ββ Yes? β Return final result βββββββββββββββββββββββββββββββββββββββββββββββββββββββββThe key mechanisms:
- Stop hook: This intercepts exit attempts and checks completion criteria before allowing the agent to stop.
- Progress tracking: A
progress.txtfile tracks whatβs been done, decisions made, and blockers encountered. - Git commits: Each iteration commits work, creating context for future iterations.
- Feedback loops: Types, tests, and linting verify quality before continuing.
- Verification: Custom completion criteria determine when the task is truly done.
Two operating modes
Section titled βTwo operating modesβHITL (Human-In-The-Loop)
Section titled βHITL (Human-In-The-Loop)βRun one iteration at a time. Watch the agent work. Intervene when needed.
This is pair programming with AI. You see every decision, catch mistakes early, and guide the direction.
Best for:
- Learning the technique
- Refining prompts
- Working on risky tasks where you want eyes on every change
AFK (Away From Keyboard)
Section titled βAFK (Away From Keyboard)βSet a maximum iteration count and let it run. Come back to results.
This is overnight work. You define clear success criteria, cap the iterations, and let the agent grind through mechanical tasks while you sleep.
Best for well-defined work like:
- Test migrations
- Coverage improvements
- Large refactors with clear patterns
Critical for AFK mode: Use Docker sandboxes. Youβre giving an agent autonomous access to your system. Contain it.
docker sandbox run claudeWhen Ralph works
Section titled βWhen Ralph worksβRalph excels at tasks with clear completion criteria:
| Task type | Why it works |
|---|---|
| Large refactors | Converting class components to hooks, Jest to Vitest |
| Framework migrations | Test suite conversions with clear before/after states |
| TDD workflows | Implement features until tests pass |
| Test coverage | Add tests to uncovered code until coverage threshold met |
| Greenfield builds | REST APIs, complete features with defined specs |
| Mechanical cleanup | Linting fixes, duplicate removal, code smell elimination |
When Ralph doesnβt work
Section titled βWhen Ralph doesnβt workβSome tasks resist iteration:
- Ambiguous requirements: If you canβt define βdone,β the loop canβt verify completion.
- Architectural decisions: These need human judgment, not persistence.
- Security-sensitive code: Auth, payments, and crypto require human review regardless of test results.
- Exploration tasks: βFigure out why the app is slowβ has no clear stopping point.
- One-shot operations: If you need immediate results, the loop overhead isnβt worth it.
Practical tips
Section titled βPractical tipsβDefine clear scope
Section titled βDefine clear scopeβUse structured completion criteria:
{ "category": "functional", "description": "New chat button creates conversation", "steps": ["Click button", "Verify conversation", "Check welcome state"], "passes": false}The agent knows exactly what βdoneβ means.
Track progress
Section titled βTrack progressβMaintain a progress.txt with:
- Tasks completed
- Decisions made and why
- Blockers encountered
- Files changed
This gives future iterations context about past work.
Use feedback loops
Section titled βUse feedback loopsβBlock commits unless ALL feedback loops pass:
- TypeScript type checking
- Unit tests
- E2E tests (Playwright, Cypress)
- Linting
- Pre-commit hooks
If any check fails, the iteration isnβt complete.
Take small steps
Section titled βTake small stepsβKeep it to one logical change per commit. Break large tasks into subtasks, and run feedback loops after each change. You want quality over speed.
Cap iterations
Section titled βCap iterationsβ- HITL: Watch every iteration
- AFK: Set max-iterations (10-20 for small tasks, 30-50 for large)
- Never use unlimited iterations
A 50-iteration loop on a large codebase can cost $50-100+ in API credits. Start with 10-20 iterations to understand token consumption before scaling up.
Commit after each feature
Section titled βCommit after each featureβGood git hygiene creates a clean git history and clear rollback points. If iteration 15 breaks something, you can revert to iteration 14.
Getting started
Section titled βGetting startedβClaude Code Plugin
Section titled βClaude Code Pluginβ/plugin install ralph-loop@claude-plugins-official/ralph-loop "Add JSDoc comments to all exported functions" --max-iterations 10NPM Package
Section titled βNPM Packageβnpm install ralph-loop-agent ai zodconst agent = new RalphLoopAgent({ model: "anthropic/claude-opus-4.5", instructions: "You are a helpful coding assistant.", stopWhen: iterationCountIs(10), verifyCompletion: async ({ result }) => ({ complete: result.text.includes("DONE"), reason: "Task completed successfully", }),});The skill shift
Section titled βThe skill shiftβTraditional AI coding asks: βHow do I get the perfect prompt?β
Ralph asks: βHow do I design conditions where iteration leads to success?β
You stop directing the AI step-by-step and start designing loops that converge on solutions. The agentβs job is persistence. Your job is defining what βdoneβ looks like and ensuring the feedback loops catch failures.
This is continuous autonomyβthe agent works until the job is actually done, not just until the LLM stops calling tools.
Resources
Section titled βResourcesβOfficial
Section titled βOfficialβ- Ralph Wiggum as a Software Engineer
- GitHub - vercel-labs/ralph-loop-agent β Core NPM package
- Ralph Wiggum - AI Loop Technique for Claude Code β Complete guide and examples
Tutorials
Section titled βTutorialsβ- 11 Tips For AI Coding With Ralph Wiggum β Practical tips for autonomous loops
- The Ralph Wiggum Approach: Running AI Coding Agents for Hours β DEV Community tutorial
Community tools
Section titled βCommunity toolsβ- ralph-claude-code β Rate limiting, tmux dashboards, circuit breakers
- ralph-orchestrator β Token tracking, spending limits, checkpointing
Using Ralph in production? Share your experienceβwhat worked, what didnβt, and what you learned along the way.