
Ralph Loop
Plugin用 Stop 钩子实现 Ralph Wiggum 循环:把同一个提示词反复交给 Claude,让它基于上一轮留下的文件改动持续迭代,直到输出完成标记或达到迭代上限。Anthropic 官方插件。
Ralph Loop Plugin
Implementation of the Ralph Wiggum technique for iterative, self-referential AI development loops in Claude Code.
What is Ralph Loop?
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 technique is inspired by the Ralph Wiggum coding technique (named after the character from The Simpsons), embodying the philosophy of persistent iteration despite setbacks.
Core Concept
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 completion
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.
This creates a self-referential feedback loop where:
- The prompt never changes between iterations
- Claude's previous work persists in files
- Each iteration sees modified files and git history
- Claude autonomously improves by reading its own past work in files
Quick Start
/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
Claude will:
- Implement the API iteratively
- Run tests and see failures
- Fix bugs based on test output
- Iterate until all requirements met
- Output the completion promise when done
Commands
/ralph-loop
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-ralph
Cancel the active Ralph loop.
Usage:
/cancel-ralph
Prompt Writing Best Practices
1. Clear Completion Criteria
❌ Bad: "Build a todo API and make it good."
✅ Good:
Build a REST API for todos.
When complete:
- All CRUD endpoints working
- Input validation in place
- Tests passing (coverage > 80%)
- README with API docs
- Output: <promise>COMPLETE</promise>
2. Incremental Goals
❌ Bad: "Create a complete e-commerce platform."
✅ Good:
Phase 1: User authentication (JWT, tests)
Phase 2: Product catalog (list/search, tests)
Phase 3: Shopping cart (add/remove, tests)
Output <promise>COMPLETE</promise> when all phases done.
3. Self-Correction
❌ Bad: "Write code for feature X."
✅ Good:
Implement feature X following TDD:
1. Write failing tests
2. Implement feature
3. Run tests
4. If any fail, debug and fix
5. Refactor if needed
6. Repeat until all green
7. Output: <promise>COMPLETE</promise>
4. Escape Hatches
Always use --max-iterations as a safety net to prevent infinite loops on impossible tasks:
# Recommended: Always set a reasonable iteration limit
/ralph-loop "Try to implement feature X" --max-iterations 20
# In your prompt, include what to do if stuck:
# "After 15 iterations, if not complete:
# - Document what's blocking progress
# - List what was attempted
# - Suggest alternative approaches"
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.
Philosophy
Ralph embodies several key principles:
1. Iteration > Perfection
Don't aim for perfect on first try. Let the loop refine the work.
2. Failures Are Data
"Deterministically bad" means failures are predictable and informative. Use them to tune prompts.
3. Operator Skill Matters
Success depends on writing good prompts, not just having a good model.
4. Persistence Wins
Keep trying until success. The loop handles retry logic automatically.
When to Use Ralph
Good for:
- Well-defined tasks with clear success criteria
- Tasks requiring iteration and refinement (e.g., getting tests to pass)
- Greenfield projects where you can walk away
- Tasks with automatic verification (tests, linters)
Not good for:
- Tasks requiring human judgment or design decisions
- One-shot operations
- Tasks with unclear success criteria
- Production debugging (use targeted debugging instead)
Real-World Results
- Successfully generated 6 repositories overnight in Y Combinator hackathon testing
- One $50k contract completed for $297 in API costs
- Created entire programming language ("cursed") over 3 months using this approach
Windows Compatibility
The stop hook uses a bash script that requires Git for Windows to run properly.
Issue: On Windows, the bash command may resolve to WSL bash (often misconfigured) instead of Git Bash, causing the hook to fail with errors like:
wsl: Unknown key 'automount.crossDistro'execvpe(/bin/bash) failed: No such file or directory
Workaround: Edit the cached plugin's hooks/hooks.json to use Git Bash explicitly:
"command": "\"C:/Program Files/Git/bin/bash.exe\" ${CLAUDE_PLUGIN_ROOT}/hooks/stop-hook.sh"
Location: ~/.claude/plugins/cache/claude-plugins-official/ralph-wiggum/<hash>/hooks/hooks.json
Note: Use Git/bin/bash.exe (the wrapper with proper PATH), not Git/usr/bin/bash.exe (raw MinGW bash without utilities in PATH).
Learn More
- Original technique: https://ghuntley.com/ralph/
- Ralph Orchestrator: https://github.com/mikeyobrien/ralph-orchestrator
For Help
Run /help in Claude Code for detailed command reference and examples.
相關資源

Ponytail
Plugin「最懒资深工程师」模式:动手前依次判断是否需要、能否复用现有代码、标准库或平台原生能力能否解决,只写最少的必要代码,但不删校验、错误处理与安全逻辑。支持 Claude Code 与 Codex,常驻激活的钩子需要本机 Node.js。
DietrichGebert/ponytail165k
Hookify
Plugin用一句话描述或分析近期对话自动生成钩子规则,以 Markdown 文件配置匹配条件,拦截或警告危险命令与不想要的写法,无需重启即生效。Anthropic 官方插件。
anthropics/claude-code151k
Claude Code Setup
Plugin扫描代码库,按类别推荐最合适的钩子、技能、MCP 服务器、子代理与斜杠命令;只分析不改文件,适合给项目快速配好 Claude Code。Anthropic 官方插件。
anthropics/claude-plugins-official40.3k
Claude Plugins Official
PluginAnthropic 官方插件市场,Claude Code 默认内置,收录 300 多个官方与合作方插件,覆盖开发、安全、设计与办公协作,用 /plugin 即可浏览安装。
anthropics/claude-plugins-official40.2k
Plannotator
Plugin在浏览器里批注和评审 agent 生成的计划、文档与代码 diff,一键把修改意见发回 agent;通过钩子接入计划模式,支持 Claude Code、Codex 等多种 agent。需先运行官方安装脚本装好命令行。
backnotprop/plannotator9.5k
Plugin Dev
Plugin开发 Claude Code 插件的工具包:7 个技能覆盖插件结构、钩子、MCP 集成、命令、子代理与技能编写,附八阶段引导式创建命令,以及代理生成、插件校验、技能评审三个子代理。Anthropic 官方维护。
anthropics/claude-code151k