|
| 1 | +# Ralph Wiggum Plugin |
| 2 | + |
| 3 | +Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops in Claude Code. |
| 4 | + |
| 5 | +## What is Ralph? |
| 6 | + |
| 7 | +Ralph is a development methodology based on continuous AI agent loops. As Geoffrey Huntley describes it: **"Ralph is a Bash loop"** - a simple `while true` that repeatedly feeds an AI agent a prompt file, allowing it to iteratively improve its work until completion. |
| 8 | + |
| 9 | +The technique is named after Ralph Wiggum from The Simpsons, embodying the philosophy of persistent iteration despite setbacks. |
| 10 | + |
| 11 | +### Core Concept |
| 12 | + |
| 13 | +This plugin implements Ralph using a **Stop hook** that intercepts Claude's exit attempts: |
| 14 | + |
| 15 | +```bash |
| 16 | +# You run ONCE: |
| 17 | +/ralph-loop "Your task description" --completion-promise "DONE" |
| 18 | + |
| 19 | +# Then Claude Code automatically: |
| 20 | +# 1. Works on the task |
| 21 | +# 2. Tries to exit |
| 22 | +# 3. Stop hook blocks exit |
| 23 | +# 4. Stop hook feeds the SAME prompt back |
| 24 | +# 5. Repeat until completion |
| 25 | +``` |
| 26 | + |
| 27 | +The loop happens **inside your current session** - you don't need external bash loops. The Stop hook in `hooks/stop-hook.sh` creates the self-referential feedback loop by blocking normal session exit. |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +### Option 1: Via StackMemory |
| 32 | + |
| 33 | +```bash |
| 34 | +# If using StackMemory |
| 35 | +stackmemory setup-mcp # Includes Ralph plugin registration |
| 36 | +``` |
| 37 | + |
| 38 | +### Option 2: Manual Installation |
| 39 | + |
| 40 | +Copy this plugin directory to your Claude Code plugins location: |
| 41 | + |
| 42 | +```bash |
| 43 | +cp -r plugins/ralph-wiggum ~/.claude/plugins/ |
| 44 | +``` |
| 45 | + |
| 46 | +Or symlink it: |
| 47 | + |
| 48 | +```bash |
| 49 | +ln -s "$(pwd)/plugins/ralph-wiggum" ~/.claude/plugins/ralph-wiggum |
| 50 | +``` |
| 51 | + |
| 52 | +## Quick Start |
| 53 | + |
| 54 | +```bash |
| 55 | +/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 |
| 56 | +``` |
| 57 | + |
| 58 | +Claude will: |
| 59 | +- Implement the API iteratively |
| 60 | +- Run tests and see failures |
| 61 | +- Fix bugs based on test output |
| 62 | +- Iterate until all requirements met |
| 63 | +- Output the completion promise when done |
| 64 | + |
| 65 | +## Commands |
| 66 | + |
| 67 | +### /ralph-loop |
| 68 | + |
| 69 | +Start a Ralph loop in your current session. |
| 70 | + |
| 71 | +**Usage:** |
| 72 | +```bash |
| 73 | +/ralph-loop "<prompt>" --max-iterations <n> --completion-promise "<text>" |
| 74 | +``` |
| 75 | + |
| 76 | +**Options:** |
| 77 | +- `--max-iterations <n>` - Stop after N iterations (default: unlimited) |
| 78 | +- `--completion-promise <text>` - Phrase that signals completion |
| 79 | + |
| 80 | +### /cancel-ralph |
| 81 | + |
| 82 | +Cancel the active Ralph loop. |
| 83 | + |
| 84 | +**Usage:** |
| 85 | +```bash |
| 86 | +/cancel-ralph |
| 87 | +``` |
| 88 | + |
| 89 | +## Prompt Writing Best Practices |
| 90 | + |
| 91 | +### 1. Clear Completion Criteria |
| 92 | + |
| 93 | +Bad: "Build a todo API and make it good." |
| 94 | + |
| 95 | +Good: |
| 96 | +```markdown |
| 97 | +Build a REST API for todos. |
| 98 | + |
| 99 | +When complete: |
| 100 | +- All CRUD endpoints working |
| 101 | +- Input validation in place |
| 102 | +- Tests passing (coverage > 80%) |
| 103 | +- README with API docs |
| 104 | +- Output: <promise>COMPLETE</promise> |
| 105 | +``` |
| 106 | + |
| 107 | +### 2. Incremental Goals |
| 108 | + |
| 109 | +Bad: "Create a complete e-commerce platform." |
| 110 | + |
| 111 | +Good: |
| 112 | +```markdown |
| 113 | +Phase 1: User authentication (JWT, tests) |
| 114 | +Phase 2: Product catalog (list/search, tests) |
| 115 | +Phase 3: Shopping cart (add/remove, tests) |
| 116 | + |
| 117 | +Output <promise>COMPLETE</promise> when all phases done. |
| 118 | +``` |
| 119 | + |
| 120 | +### 3. Self-Correction |
| 121 | + |
| 122 | +Bad: "Write code for feature X." |
| 123 | + |
| 124 | +Good: |
| 125 | +```markdown |
| 126 | +Implement feature X following TDD: |
| 127 | +1. Write failing tests |
| 128 | +2. Implement feature |
| 129 | +3. Run tests |
| 130 | +4. If any fail, debug and fix |
| 131 | +5. Refactor if needed |
| 132 | +6. Repeat until all green |
| 133 | +7. Output: <promise>COMPLETE</promise> |
| 134 | +``` |
| 135 | + |
| 136 | +### 4. Escape Hatches |
| 137 | + |
| 138 | +Always use `--max-iterations` as a safety net: |
| 139 | + |
| 140 | +```bash |
| 141 | +# Recommended: Always set a reasonable iteration limit |
| 142 | +/ralph-loop "Try to implement feature X" --max-iterations 20 |
| 143 | +``` |
| 144 | + |
| 145 | +## When to Use Ralph |
| 146 | + |
| 147 | +**Good for:** |
| 148 | +- Well-defined tasks with clear success criteria |
| 149 | +- Tasks requiring iteration and refinement (e.g., getting tests to pass) |
| 150 | +- Greenfield projects where you can walk away |
| 151 | +- Tasks with automatic verification (tests, linters) |
| 152 | + |
| 153 | +**Not good for:** |
| 154 | +- Tasks requiring human judgment or design decisions |
| 155 | +- One-shot operations |
| 156 | +- Tasks with unclear success criteria |
| 157 | +- Production debugging (use targeted debugging instead) |
| 158 | + |
| 159 | +## Learn More |
| 160 | + |
| 161 | +- Original technique: https://ghuntley.com/ralph/ |
| 162 | +- Ralph Orchestrator: https://github.com/mikeyobrien/ralph-orchestrator |
| 163 | +- Official Claude Code plugin: https://github.com/anthropics/claude-code/tree/main/plugins/ralph-wiggum |
0 commit comments