Ralph Wiggum AI Loops
The Ralph Wiggum technique is an iterative AI development methodology. At its core, it's a simple while loop that repeatedly feeds Claude a prompt until completion.
while :; do cat PROMPT.md | claude ; done
Named after The Simpsons character, it embodies persistent iteration despite setbacks.
Philosophy
- Iteration > Perfection - Don't aim for perfect on first try
- Failures Are Data - Deterministically bad means failures are predictable
- Operator Skill Matters - Success depends on writing good prompts
- Persistence Wins - Keep trying until success
When to Use
Good for:
- Well-defined tasks with clear success criteria
- Tasks requiring iteration (getting tests to pass)
- Greenfield projects you can walk away from
- Tasks with automatic verification (tests, linters)
- Overnight/weekend automated development
Not good for:
- Tasks requiring human judgment
- One-shot operations
- Unclear/subjective success criteria
- Production debugging
Skillflow
Use the ralph-loop skillflow:
mcpammer_skillflow_execute ralph-loop inputs={
"prompt": "Your task prompt here...",
"completion_promise": "COMPLETE",
"max_iterations": 30
}
Prompt 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
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 Pattern
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>
Templates
Feature Implementation
Implement [FEATURE_NAME].
Requirements:
- [Requirement 1]
- [Requirement 2]
Success criteria:
- All requirements implemented
- Tests passing with >80% coverage
- No linter errors
- Documentation updated
Output <promise>COMPLETE</promise> when done.
Bug Fixing
Fix bug: [DESCRIPTION]
Steps:
1. Reproduce the bug
2. Identify root cause
3. Implement fix
4. Write regression test
5. Verify fix works
After 15 iterations if not fixed:
- Document blocking issues
- List attempted approaches
Output <promise>FIXED</promise> when resolved.
Safety
- Always set max_iterations - Prevents infinite loops
- Include stuck handling - Document what to do after N failures
- Use completion promise - Clear signal for success