Autonomous AI coding loop for unattended development - lets Claude work continuously on tasks while you sleep, with mandatory sandbox enforcement for safety
"Me fail English? That's unpossible!" - Ralph Wiggum
Ralph Wiggum Mode is an autonomous AI coding loop that enables Claude Code to work continuously on tasks without human intervention. Named after the persistently optimistic Simpsons character, this technique lets Claude work "overnight shifts" while you sleep.
Progress persists in files and git, not in the LLM's context window.
When context fills up, the loop restarts Claude with fresh context. The new instance picks up from the filesystem state (your code, git history, and task tracking files).
Use Ralph Wiggum mode for:
CRITICAL: Ralph requires a sandboxed environment.
Ralph uses --dangerously-skip-permissions which can:
Ralph will REFUSE to start unless it detects:
# Run the init script to scaffold Ralph files
./ralph-init.sh
This creates:
RALPH_PROMPT.md - The prompt fed to Claude each iterationIMPLEMENTATION_PLAN.md - Task tracking fileralph.sh - The main loop scriptralph-sandbox.sh - Docker wrapperDockerfile.ralph - Sandbox container definition# Create specs directory for requirements
mkdir -p specs
# Write your requirements
cat > specs/my-feature.md << 'EOF'
## Feature: User Dashboard
### Requirements
- Show user's recent activity
- Display usage statistics
- Allow date range filtering
EOF
# Update the implementation plan
cat > IMPLEMENTATION_PLAN.md << 'EOF'
## Tasks
- [ ] Create Dashboard component
- [ ] Add activity feed API endpoint
- [ ] Implement date range picker
- [ ] Write tests for dashboard
EOF
# Recommended: Use the Docker wrapper
./ralph-sandbox.sh
# With iteration limit
./ralph-sandbox.sh . 20
# Check progress from another terminal
tail -f ralph.log
git log --oneline -10
# See what Ralph did
git log --oneline
# Check task completion
cat IMPLEMENTATION_PLAN.md
# Verify tests pass
pytest
┌─────────────────────────────────────────────────────────────────┐
│ EXTERNAL BASH LOOP │
│ │
│ while :; do │
│ ┌─────────────────────────────────────────────────┐ │
│ │ CLAUDE SESSION │ │
│ │ │ │
│ │ 1. Read RALPH_PROMPT.md │ │
│ │ 2. Check IMPLEMENTATION_PLAN.md │ │
│ │ 3. Pick a task, implement it │ │
│ │ 4. Run tests, commit changes │ │
│ │ 5. Context fills → Session ends │ │
│ └─────────────────────────────────────────────────┘ │
│ ↓ │
│ Git commit saves progress │
│ Loop restarts with fresh context │
│ done │
└─────────────────────────────────────────────────────────────────┘
The prompt loaded each iteration. Customize this for your use case:
# Ralph Mode Instructions
You are operating in autonomous Ralph mode.
## Each Iteration
1. Read IMPLEMENTATION_PLAN.md and git log
2. Pick ONE pending task, mark it in-progress
3. Implement fully with tests
4. Mark complete, commit changes
## Rules
- Never skip tests
- Commit after each meaningful change
- If blocked, document why and continue
Persistent task tracking (survives context resets):
## Tasks
- [x] Task 1 (completed in iteration 1)
- [x] Task 2 (completed in iteration 2)
- [ ] Task 3 (in progress)
- [ ] Task 4 (pending)
The main loop with sandbox enforcement. Key features:
Docker wrapper that:
--network none)| Variable | Default | Description |
|---|---|---|
RALPH_MAX_ITERATIONS |
0 (unlimited) |
Stop after N iterations |
RALPH_MODEL |
sonnet |
Claude model to use |
RALPH_COST_LIMIT |
50.00 |
Max spend in USD (with cost monitor hook) |
ANTHROPIC_API_KEY |
optional | API key (not needed with Claude Code subscription) |
Only for custom sandbox environments you've verified:
RALPH_I_KNOW_WHAT_IM_DOING=sandboxed ./ralph.sh
Break large tasks into small, atomic pieces:
## Bad
- [ ] Implement user authentication
## Good
- [ ] Create User model with email, password_hash
- [ ] Add POST /api/register endpoint
- [ ] Add POST /api/login endpoint
- [ ] Add password reset flow
- [ ] Add JWT middleware
- [ ] Write auth tests
# Watch iterations in real-time
tail -f ralph.log
# Check commits
watch -n 5 'git log --oneline -10'
# Monitor resource usage
docker stats
Install these hooks for additional safety:
# Block dangerous operations
skillz hooks install ralph-safety-check
# Track API costs
skillz hooks install ralph-cost-monitor
Check sandbox detection output. You need at least 3 checks passing:
ralph.log for errorsIMPLEMENTATION_PLAN.md to unblockRALPH_PROMPT.mdSet MAX_ITERATIONS or use the cost monitor hook:
./ralph-sandbox.sh . 20 # Stop after 20 iterations