Ralph Wiggum Guide
Complete guide to using Ralph Wiggum, Claude Craft's continuous AI agent loop.
What is Ralph Wiggum?
Ralph Wiggum is a continuous execution system that runs Claude iteratively until a task is complete. Named after the Simpson's character known for his persistence, Ralph keeps working until:
- All Definition of Done (DoD) validators pass
- Maximum iterations reached
- Circuit breaker triggers
Quick Start
Basic Usage
# In Claude Code
/common:ralph-run "Implement user authentication"
# Or via CLI
npx @the-bearded-bear/claude-craft ralph "Implement user authentication"With Full DoD Checks
/common:ralph-run --full "Fix the login bug"How It Works
┌─────────────────────────────────────────────────────────────┐
│ Ralph Wiggum Loop │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. Load Task Description │
│ │ │
│ ▼ │
│ 2. Execute Claude (1 iteration) │
│ │ │
│ ▼ │
│ 3. Run DoD Validators ─────────┐ │
│ │ │ │
│ │ All Pass? │ Any Fail? │
│ ▼ ▼ │
│ 4a. SUCCESS ─────────── 4b. Check Iteration Count │
│ Return result │ │
│ │ < Max? │
│ ▼ │
│ Go to Step 2 │
│ │
│ │ >= Max? │
│ ▼ │
│ Circuit Breaker │
│ Stop with partial │
│ │
└─────────────────────────────────────────────────────────────┘Configuration
ralph.yml
Create a ralph.yml in your project root:
# Ralph Wiggum Configuration
version: 1
# Maximum iterations before stopping
max_iterations: 10
# Circuit breaker settings
circuit_breaker:
enabled: true
# Number of consecutive failures before stopping
threshold: 3
# Profile: conservative, moderate, aggressive, learning, custom
profile: moderate
# Git checkpointing
git:
enabled: true
# Create checkpoint commit after each iteration
checkpoint: true
# Prefix for checkpoint commits
prefix: "[ralph]"
# Observability
observability:
dashboard: true
metrics:
format: json # json, prometheus
path: .ralph/metrics.json
health:
enabled: true
port: 9090
# Definition of Done validators
dod:
- type: command
name: "Tests pass"
command: "npm test"
expect_exit_code: 0
- type: command
name: "Lint passes"
command: "npm run lint"
expect_exit_code: 0
- type: output_contains
name: "Implementation complete"
pattern: "✅ Done|Implementation complete"
- type: file_changed
name: "Source modified"
path: "src/**/*.ts"
# Technology-specific DoD templates
technology: symfony # symfony, flutter, react, python, etc.DoD Validators
1. Command Validator
Runs a shell command and checks the exit code.
dod:
- type: command
name: "Tests pass"
command: "npm test"
expect_exit_code: 0
timeout: 120000 # 2 minutesUse for:
- Running tests
- Linting
- Type checking
- Build verification
2. Output Contains Validator
Checks if Claude's output contains a specific pattern.
dod:
- type: output_contains
name: "Task marked complete"
pattern: "✅ Done"
case_sensitive: falseUse for:
- Completion markers
- Success messages
- Specific outputs
3. File Changed Validator
Verifies that specific files were modified.
dod:
- type: file_changed
name: "Documentation updated"
path: "docs/**/*.md"
since: "last_iteration" # or "start"Use for:
- Ensuring code changes
- Documentation updates
- Config modifications
4. Hook Validator
Integrates with existing hook scripts.
dod:
- type: hook
name: "Quality gate"
script: ".claude/hooks/quality-gate.sh"
args: ["--strict"]Use for:
- Custom validation logic
- External tool integration
- Complex checks
5. Human Validator
Requires manual approval to continue.
dod:
- type: human
name: "Manual review"
prompt: "Does the implementation look correct?"
options:
- label: "Yes, continue"
action: pass
- label: "No, retry"
action: fail
- label: "Stop"
action: stopUse for:
- Critical changes
- UI/UX validation
- Final approval
Technology Templates
Ralph includes pre-configured DoD templates for common technologies.
Symfony
technology: symfony
# Automatically includes:
# - PHPUnit tests
# - PHPStan analysis
# - PHP CS Fixer
# - Doctrine migrations checkFlutter
technology: flutter
# Automatically includes:
# - flutter test
# - flutter analyze
# - dart format checkReact
technology: react
# Automatically includes:
# - npm test
# - eslint
# - typescript check
# - build verificationPython
technology: python
# Automatically includes:
# - pytest
# - mypy
# - black --check
# - ruffCircuit Breaker
The circuit breaker prevents infinite loops and wasted resources.
Profiles
| Profile | Threshold | Behavior |
|---|---|---|
conservative | 2 failures | Stop quickly |
moderate | 3 failures | Balanced |
aggressive | 5 failures | Keep trying |
learning | Adaptive | Learns from patterns |
custom | User-defined | Full control |
Configuration
circuit_breaker:
enabled: true
profile: moderate
# Custom settings (when profile: custom)
threshold: 3
reset_after: 300 # seconds
half_open_requests: 1States
- Closed (normal) - All requests pass through
- Open (tripped) - Requests blocked
- Half-Open (testing) - Limited requests to test recovery
Git Checkpointing
Ralph can create Git commits after each iteration for easy rollback.
git:
enabled: true
checkpoint: true
prefix: "[ralph]"
branch: null # Use current branchRecovery
# View Ralph commits
git log --oneline --grep="[ralph]"
# Rollback to before Ralph
git reset --hard HEAD~5 # Undo last 5 Ralph commits
# Cherry-pick specific iteration
git cherry-pick abc123Observability
Dashboard
Enable real-time monitoring:
observability:
dashboard: trueView at: http://localhost:9090/ralph
Metrics
observability:
metrics:
format: json
path: .ralph/metrics.jsonExported metrics:
ralph_iterations_totalralph_dod_pass_rateralph_duration_secondsralph_circuit_breaker_state
Health Check
observability:
health:
enabled: true
port: 9090Endpoint: http://localhost:9090/health
Advanced Usage
TDD Mode
Combine Ralph with TDD phases:
/common:ralph-run --tdd "Implement user registration"This enforces:
- 🔴 Red - Write failing test first
- 🟢 Green - Implement to pass
- 🔵 Refactor - Clean up
Batch Mode
Run Ralph on multiple tasks:
# Queue tasks
echo "Task 1: Add validation" >> .ralph/queue.txt
echo "Task 2: Add error handling" >> .ralph/queue.txt
# Process queue
npx @the-bearded-bear/claude-craft ralph --batch .ralph/queue.txtInteractive Mode
Get prompts between iterations:
/common:ralph-run --interactive "Refactor the payment module"Best Practices
1. Start with Simple DoD
Begin with basic validators:
dod:
- type: command
command: "npm test"
expect_exit_code: 0Add more as needed.
2. Use Reasonable Iteration Limits
# For bug fixes
max_iterations: 5
# For features
max_iterations: 10
# For complex refactoring
max_iterations: 153. Enable Git Checkpointing
Always enable for production work:
git:
enabled: true
checkpoint: true4. Monitor with Dashboard
Enable for long-running tasks:
observability:
dashboard: true5. Use Technology Templates
Leverage pre-built DoD:
technology: symfony # Instead of custom validatorsTroubleshooting
Ralph Never Completes
Symptoms: Keeps iterating without passing DoD
Solutions:
Check DoD validators are achievable:
bash# Run manually npm test npm run lintReduce complexity of the task
Add
output_containsvalidator for completion marker
Circuit Breaker Trips Too Early
Solutions:
Switch to aggressive profile:
yamlcircuit_breaker: profile: aggressiveIncrease threshold:
yamlcircuit_breaker: threshold: 5
File Changed Validator Fails
Solutions:
Check path pattern:
yamlpath: "src/**/*.ts" # Use glob patternsUse correct
since:yamlsince: "start" # Since Ralph started # or since: "last_iteration" # Since last iteration
Command Validator Timeout
Solutions:
Increase timeout:
yamltimeout: 300000 # 5 minutesUse Docker for isolation:
yamlcommand: "docker compose exec app npm test"
Example Configurations
Bug Fix
version: 1
max_iterations: 5
circuit_breaker:
profile: conservative
dod:
- type: command
name: "Tests pass"
command: "npm test"
expect_exit_code: 0
- type: output_contains
name: "Bug fixed"
pattern: "fix|Fixed|resolved"Feature Implementation
version: 1
max_iterations: 10
circuit_breaker:
profile: moderate
technology: react
dod:
- type: command
name: "Tests pass"
command: "npm test"
- type: command
name: "Lint passes"
command: "npm run lint"
- type: file_changed
name: "Component created"
path: "src/components/**/*.tsx"
- type: file_changed
name: "Tests created"
path: "src/components/**/*.test.tsx"Full TDD Cycle
version: 1
max_iterations: 15
circuit_breaker:
profile: aggressive
technology: symfony
git:
enabled: true
checkpoint: true
prefix: "[ralph-tdd]"
dod:
- type: command
name: "PHPUnit"
command: "docker compose exec app ./vendor/bin/phpunit"
- type: command
name: "PHPStan"
command: "docker compose exec app ./vendor/bin/phpstan"
- type: command
name: "PHP CS Fixer"
command: "docker compose exec app ./vendor/bin/php-cs-fixer fix --dry-run"
- type: file_changed
name: "Tests written"
path: "tests/**/*.php"
- type: output_contains
name: "TDD complete"
pattern: "🔵 Refactor.*complete|refactoring done"