"Me fail migrations? That's unpossible!" - Ralph Wiggum
A pattern for orchestrating complex, multi-phase migrations using AI agents with git worktrees and tmux.
Ralph Wiggum is an orchestration pattern for running multiple AI agents in parallel during large-scale codebase migrations. It was battle-tested during a Next.js 15→16 + Sanity 3→5 + Tailwind 3→4 migration involving 200+ file changes across 28 phases.
- Wave-based execution: Tasks grouped into waves with max 4 parallel agents
- Git worktrees: Each agent works in isolation to prevent merge conflicts
- Explicit file ownership: Matrix defining which agent owns which files
- Chrome queue: Serialized access to browser for visual verification
- Verification gates: Per-wave validation before proceeding
├── scripts/ # Orchestration shell scripts
│ ├── ralph-migration.sh # Main orchestrator
│ ├── ralph-phase.sh # Single phase executor
│ ├── ralph-once.sh # One-shot phase runner
│ └── afk-ralph.sh # AFK mode runner
├── verification/ # Wave verification scripts
│ ├── verify-wave-0.sh
│ ├── verify-wave-1.sh
│ └── verify-final.sh
├── examples/ # Templates and examples
│ ├── prd-template.md # Phase PRD template
│ └── wave-structure.md # Example wave organization
└── .claude/rules/ # Agent instruction files
├── 08-ralph-wiggum-orchestration-risk-analysis.md
└── 09-ralph-wiggum-quick-reference.md
Break your migration into phases with explicit dependencies. Each phase should be:
- Small enough for one agent session
- Have clear inputs and outputs
- Have verifiable completion criteria
Document each phase with:
- Context and goals
- Specific tasks with file paths
- Verification commands
- Rollback procedures
Create a file ownership matrix for each wave. Critical rule: No file can be owned by more than one agent per wave.
Run agents in parallel using tmux + git worktrees:
- Each agent gets an isolated worktree
- Agents work simultaneously on non-overlapping files
- Wave completes when all agents finish
Run gate scripts before merging:
./verification/verify-wave-1.sh
# Only proceed if exit code is 0Sequential merge with conflict detection. If conflicts occur, stop and investigate the ownership matrix.
The .claude/rules/ files document:
08-ralph-wiggum-orchestration-risk-analysis.md:
- 10 identified failure modes (merge conflicts, stale worktrees, Chrome contention, etc.)
- Prevention strategies for each
- Recovery procedures
- Monitoring checklists
09-ralph-wiggum-quick-reference.md:
- Pre-wave checklists
- Alert response procedures
- Worktree lifecycle management
- Chrome queue operations
- Copy the scripts to your project
- Adapt
ralph-migration.shfor your phases - Create PRDs for each phase using the template
- Set up verification scripts for each wave
- Run with:
./scripts/ralph-migration.sh
Ralph is designed for migrations that are:
- Large: 100+ file changes
- Complex: Multiple interconnected systems
- Parallelizable: Work can be divided by file/directory ownership
- Risky: Need isolation and rollback capabilities
MIT