Ralph Wiggum is an iterative AI development methodology integrated into Gru. It enables autonomous, long-running development cycles where AI agents continuously refine their work until completion.
Named after the Simpsons character, Ralph embodies persistent iteration despite setbacks. The core principle: Iteration > Perfection. Rather than attempting perfect execution in one shot, Ralph loops allow AI agents to progressively improve their work through multiple attempts.
# Basic usage
gru ralph "Build a REST API with user authentication"
# With completion detection
gru ralph "Add tests until coverage > 90%" --completion-promise "COVERAGE_MET"
# Custom iterations
gru ralph "Refactor this codebase" --max-iterations 30
# Named loop for tracking
gru ralph "Optimize performance" --name perf-optimizer- Initial Task: Agent receives the task with Ralph loop instructions
- Execution: Agent works on the task autonomously (no approval prompts)
- Iteration Check: When agent completes:
- If completion promise found → Loop ends successfully
- If max iterations reached → Loop ends
- Otherwise → Spawn next iteration with context
- Context Preservation: Each iteration includes summary of previous work
- Progressive Refinement: Agent builds on prior attempts, fixing issues
| Option | Description | Default |
|---|---|---|
--max-iterations |
Maximum number of iterations | 20 |
--completion-promise |
String to detect task completion | None |
--name |
Custom name for the loop | ralph-[id] |
--model |
AI model to use | Default model |
--priority |
Task priority (high/normal/low) | normal |
- Large refactors: Framework migrations, dependency updates
- Test coverage: Writing comprehensive test suites
- Batch operations: Processing multiple files/records
- Greenfield projects: Building from scratch with clear requirements
- Documentation: Generating complete docs across a codebase
- Code cleanup: Linting, formatting, removing dead code
- Debugging production issues: Need human judgment
- One-shot operations: Simple tasks that don't benefit from iteration
- Unclear requirements: Success criteria must be well-defined
- Time-sensitive tasks: Iterations take time
Completion promises are exact strings the agent must output to signal completion:
# Agent must output exactly "TESTS_COMPLETE" to finish
gru ralph "Write unit tests" --completion-promise "TESTS_COMPLETE"
# Multiple conditions require multiple Ralph loops
gru ralph "Task 1" --completion-promise "TASK1_DONE"
gru ralph "Task 2" --completion-promise "TASK2_DONE"Important: Completion promises use exact string matching. The agent must output the exact string, not a variation.
# Check Ralph loop status
gru status <agent-id>
# View iteration progress
gru logs <agent-id>
# Cancel if needed
gru cancel-ralph <agent-id>gru ralph "Write tests for all components in src/ until every exported function has at least one test" \
--max-iterations 30 \
--completion-promise "ALL_FUNCTIONS_TESTED"gru ralph "Migrate from Express to Fastify, updating all routes and middleware" \
--max-iterations 50 \
--name express-to-fastifygru ralph "Add JSDoc comments to all public functions" \
--completion-promise "DOCS_COMPLETE" \
--max-iterations 25- Clear Completion Criteria: Define what "done" looks like precisely
- Reasonable Iteration Limits: Set based on task complexity
- Test in Isolated Environments: Use
--workdirto isolate changes - Monitor Progress: Check logs periodically to ensure productive iteration
- Combine with Templates: Use saved templates for repeatable Ralph tasks
Ralph loops are implemented through:
- CLI Commands:
ralphandcancel-ralphin the CLI interface - Orchestrator Integration:
spawn_ralph_loop()manages the lifecycle - Background Monitoring: Async task monitors completion and spawns iterations
- Metadata Tracking: Loop state stored in
_ralph_loopsdictionary - Context Preservation: Previous work summary included in next iteration
- Iteration Limits: Prevents infinite loops
- Cancellation: Can stop loops at any time
- Unsupervised Only: Runs without approval prompts for efficiency
- Status Tracking: Monitor progress through standard agent commands
- Automatic Cleanup: Resources cleaned up on completion/cancellation
Loop not progressing?
- Check logs to see if agent is stuck
- Verify task is clear and achievable
- Consider increasing iteration limit
Completion promise not detected?
- Ensure exact string match
- Check agent is outputting the promise
- Verify promise is in final message
Too many iterations?
- Refine task to be more specific
- Add intermediate completion promise
- Break into smaller Ralph loops