Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops in Claude Code.
Ralph Loop 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.
This plugin implements Ralph using a Stop hook that intercepts Claude's exit attempts:
# You run ONCE:
/ralph-loop "Your task description" --completion-promise "DONE"
# Then Claude Code automatically:
# 1. Works on the task
# 2. Tries to exit
# 3. Stop hook blocks exit
# 4. Stop hook feeds the SAME prompt back
# 5. Repeat until completionThe loop happens inside your current session - you don't need external bash loops.
# Clone this repo
git clone https://github.com/mgluck/ralph-loop-plugin.git
# Install in Claude Code
claude plugins install /path/to/ralph-loop-pluginCopy the plugin files to your Claude Code plugins directory:
mkdir -p ~/.claude/plugins/marketplaces/local-plugins/plugins/ralph-loop
cp -r * ~/.claude/plugins/marketplaces/local-plugins/plugins/ralph-loop/Then run /refresh in Claude Code.
/ralph-loop "Build a REST API for todos. Output <promise>COMPLETE</promise> when done." --completion-promise "COMPLETE" --max-iterations 20Claude will iterate until:
- It outputs
<promise>COMPLETE</promise>(task done) - Or reaches 20 iterations (safety limit)
Start a Ralph loop in your current session.
Usage:
/ralph-loop "<prompt>" --max-iterations <n> --completion-promise "<text>"Options:
--max-iterations <n>- Stop after N iterations (default: unlimited)--completion-promise <text>- Phrase that signals completion
Cancel the active Ralph loop.
/cancel-ralphShow help and examples.
Build a REST API for todos.
When complete:
- All CRUD endpoints working
- Tests passing
- Output: <promise>COMPLETE</promise># Always set --max-iterations to prevent infinite loops
/ralph-loop "Implement feature X" --max-iterations 20/ralph-loopcreates a state file at.claude/ralph-loop.local.md- When Claude tries to exit, the Stop hook reads the state
- If completion promise not detected, hook blocks exit and feeds the same prompt back
- Claude sees its previous work in files and continues
- Loop ends when promise is detected or max iterations reached
ralph-loop-plugin/
├── .claude-plugin/
│ └── plugin.json # Plugin metadata
├── commands/
│ ├── ralph-loop.md # Start loop command
│ ├── cancel-ralph.md # Cancel loop command
│ └── help.md # Help command
├── hooks/
│ ├── hooks.json # Hook definitions
│ ├── stop-hook.sh # Main loop logic
│ └── post-tool-reminder.sh
├── scripts/
│ └── setup-ralph-loop.sh
└── README.md
- Claude Code v2.1.0+
jqinstalled (for JSON parsing)perlinstalled (for regex in promise detection)- Bash 4.0+
- Original technique: https://ghuntley.com/ralph/
- Ralph Orchestrator: https://github.com/mikeyobrien/ralph-orchestrator
MIT