Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops in Claude Code. 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. The technique is named af
Add this skill
npx mdskills install anthropics/claude-codeImplements iterative AI development loops with clear instructions, examples, and safety mechanisms
1# Ralph Wiggum Plugin23Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops in Claude Code.45## What is Ralph?67Ralph 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.89The technique is named after Ralph Wiggum from The Simpsons, embodying the philosophy of persistent iteration despite setbacks.1011### Core Concept1213This plugin implements Ralph using a **Stop hook** that intercepts Claude's exit attempts:1415```bash16# You run ONCE:17/ralph-loop "Your task description" --completion-promise "DONE"1819# Then Claude Code automatically:20# 1. Works on the task21# 2. Tries to exit22# 3. Stop hook blocks exit23# 4. Stop hook feeds the SAME prompt back24# 5. Repeat until completion25```2627The 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.2829This creates a **self-referential feedback loop** where:30- The prompt never changes between iterations31- Claude's previous work persists in files32- Each iteration sees modified files and git history33- Claude autonomously improves by reading its own past work in files3435## Quick Start3637```bash38/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 5039```4041Claude will:42- Implement the API iteratively43- Run tests and see failures44- Fix bugs based on test output45- Iterate until all requirements met46- Output the completion promise when done4748## Commands4950### /ralph-loop5152Start a Ralph loop in your current session.5354**Usage:**55```bash56/ralph-loop "<prompt>" --max-iterations <n> --completion-promise "<text>"57```5859**Options:**60- `--max-iterations <n>` - Stop after N iterations (default: unlimited)61- `--completion-promise <text>` - Phrase that signals completion6263### /cancel-ralph6465Cancel the active Ralph loop.6667**Usage:**68```bash69/cancel-ralph70```7172## Prompt Writing Best Practices7374### 1. Clear Completion Criteria7576❌ Bad: "Build a todo API and make it good."7778✅ Good:79```markdown80Build a REST API for todos.8182When complete:83- All CRUD endpoints working84- Input validation in place85- Tests passing (coverage > 80%)86- README with API docs87- Output: <promise>COMPLETE</promise>88```8990### 2. Incremental Goals9192❌ Bad: "Create a complete e-commerce platform."9394✅ Good:95```markdown96Phase 1: User authentication (JWT, tests)97Phase 2: Product catalog (list/search, tests)98Phase 3: Shopping cart (add/remove, tests)99100Output <promise>COMPLETE</promise> when all phases done.101```102103### 3. Self-Correction104105❌ Bad: "Write code for feature X."106107✅ Good:108```markdown109Implement feature X following TDD:1101. Write failing tests1112. Implement feature1123. Run tests1134. If any fail, debug and fix1145. Refactor if needed1156. Repeat until all green1167. Output: <promise>COMPLETE</promise>117```118119### 4. Escape Hatches120121Always use `--max-iterations` as a safety net to prevent infinite loops on impossible tasks:122123```bash124# Recommended: Always set a reasonable iteration limit125/ralph-loop "Try to implement feature X" --max-iterations 20126127# In your prompt, include what to do if stuck:128# "After 15 iterations, if not complete:129# - Document what's blocking progress130# - List what was attempted131# - Suggest alternative approaches"132```133134**Note**: The `--completion-promise` uses exact string matching, so you cannot use it for multiple completion conditions (like "SUCCESS" vs "BLOCKED"). Always rely on `--max-iterations` as your primary safety mechanism.135136## Philosophy137138Ralph embodies several key principles:139140### 1. Iteration > Perfection141Don't aim for perfect on first try. Let the loop refine the work.142143### 2. Failures Are Data144"Deterministically bad" means failures are predictable and informative. Use them to tune prompts.145146### 3. Operator Skill Matters147Success depends on writing good prompts, not just having a good model.148149### 4. Persistence Wins150Keep trying until success. The loop handles retry logic automatically.151152## When to Use Ralph153154**Good for:**155- Well-defined tasks with clear success criteria156- Tasks requiring iteration and refinement (e.g., getting tests to pass)157- Greenfield projects where you can walk away158- Tasks with automatic verification (tests, linters)159160**Not good for:**161- Tasks requiring human judgment or design decisions162- One-shot operations163- Tasks with unclear success criteria164- Production debugging (use targeted debugging instead)165166## Real-World Results167168- Successfully generated 6 repositories overnight in Y Combinator hackathon testing169- One $50k contract completed for $297 in API costs170- Created entire programming language ("cursed") over 3 months using this approach171172## Learn More173174- Original technique: https://ghuntley.com/ralph/175- Ralph Orchestrator: https://github.com/mikeyobrien/ralph-orchestrator176177## For Help178179Run `/help` in Claude Code for detailed command reference and examples.180
Full transparency — inspect the skill content before installing.