| name | pi-swarm |
| description | Spawns parallel pi agents to work on multiple GitHub issues or PRs using git worktrees. Use when asked to process multiple items in parallel, perform bulk reviews/fixes, or orchestrate entire projects. |
Pi Swarm
Orchestrates parallel headless pi agents across isolated git worktrees to process GitHub issues, PRs, epics, and entire projects.
Command Hierarchy
Commander (Project/Milestone level)
โ
โโโบ Captain (Epic level)
โ โโโบ swarm.sh (Issue wave 1)
โ โโโบ pr-swarm.sh (Review PRs)
โ โโโบ swarm.sh (Issue wave 2)
โ โโโบ ...
โ
โโโบ Captain (Another Epic)
โโโบ ...
Scripts
Issue Swarm
Process multiple issues in parallel:
scripts/swarm.sh 48 50 52
PR Swarm
Review and fix multiple PRs in parallel:
scripts/pr-swarm.sh 101 105
Captain (Epic Orchestrator)
Orchestrate an entire epic with dependency-aware wave execution:
scripts/captain.sh --epic 151
Commander (Project/Milestone Orchestrator)
Orchestrate multiple epics or generate a project from scratch:
scripts/commander.sh --milestone 200
scripts/commander.sh --epics 151 160 175
scripts/commander.sh --project "Build a CLI todo app with SQLite backend"
What Each Script Does
swarm.sh
For each issue:
- Fetches details from GitHub API
- Creates isolated git worktree
- Spawns headless pi agent
- Commits and creates PR
pr-swarm.sh
For each PR:
- Fetches PR and checks out branch
- Reviews with pi agent
- Fixes issues directly
- Pushes and posts comment
captain.sh
For an epic:
- Parses epic โ extracts issues & dependencies
- Plans execution waves
- Dispatches swarm.sh per wave
- Reviews PRs with pr-swarm.sh
- Validates success criteria
- Reports to epic issue
commander.sh
For a project/milestone:
- Parses milestone OR generates project plan
- Creates GitHub issues (if --project mode)
- Plans epic waves with dependencies
- Dispatches captain.sh per epic
- Monitors cross-epic progress
- Reports final status
Options
swarm.sh / pr-swarm.sh
| Flag | Description | Default |
|---|
--model <name> | Model to use | (default) |
--push / --no-push | Push changes | enabled |
--pr / --no-pr | Create PRs | enabled |
--cleanup / --no-cleanup | Delete worktrees | enabled |
-j, --jobs <n> | Max parallel jobs | unlimited |
--timeout <min> | Timeout per task | no timeout |
--dry-run | Preview only | disabled |
captain.sh
| Flag | Description | Default |
|---|
--epic <num> | Epic issue number | required |
--model <name> | Model for agents | (default) |
--max-retries <n> | Retries per task | 2 |
--wave-timeout <m> | Timeout per wave | 60 min |
--resume | Resume from state | disabled |
--force | Force start (override stale lock) | disabled |
-j, --jobs <n> | Jobs per wave | unlimited |
--dry-run | Plan only | disabled |
commander.sh
| Flag | Description | Default |
|---|
--milestone <num> | Milestone issue | - |
--epics <n> ... | Epic numbers | - |
--project <spec> | Project description | - |
--model <name> | Model for agents | (default) |
--max-parallel <n> | Parallel captains | 2 |
--max-retries <n> | Retries per epic | 1 |
--epic-timeout <m> | Timeout per epic | 120 min |
--resume | Resume from state | disabled |
--force | Force start (override stale lock) | disabled |
-j, --jobs <n> | Jobs per captain | unlimited |
--dry-run | Plan only | disabled |
Monitoring
tail -f .worktrees/*.log
cat .captain/epic-151.json | jq .
cat .commander/milestone-200.json | jq .
tail -f .worktrees/*.log .captain/*.log .commander/*.log
Output Structure
.worktrees/
โโโ issue-48/ # Worktree
โโโ issue-48.log # Log
โโโ issue-48.jsonl # Agent JSON log
โโโ issue-48.pr # PR URL
.captain/
โโโ epic-151.json # State
โโโ epic-151-plan.json # Plan
โโโ epic-151.log # Log
.commander/
โโโ milestone-200.json # State
โโโ milestone-200-plan.json # Plan
โโโ epic-151.log # Captain logs
โโโ epic-160.log
Full Workflow
commander.sh --project "Todo CLI app"
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Generate Plan โ โ Pi creates epics & issues
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Create GH Issues โ โ Creates epic + sub-issues
โโโโโโโโโโโโฌโโโโโโโโโโโ
โ
โโโโโโโโดโโโโโโโ
โผ โผ
โโโโโโโโโโ โโโโโโโโโโ
โCaptain โ โCaptain โ โ Parallel epics
โEpic #1 โ โEpic #2 โ
โโโโโฌโโโโโ โโโโโฌโโโโโ
โ โ
โผ โผ
โโโโโโโโโโ โโโโโโโโโโ
โ Waves โ โ Waves โ โ swarm.sh + pr-swarm.sh
โโโโโฌโโโโโ โโโโโฌโโโโโ
โ โ
โโโโโโโฌโโโโโโโ
โผ
โโโโโโโโโโโโโโโโโโโโโโโ
โ Final Report โ โ Posted to milestone/project
โโโโโโโโโโโโโโโโโโโโโโโ
Error Handling
The scripts detect and handle various error types:
| Error Type | Detection | Behavior |
|---|
| Rate Limit (429) | "rate limit", "too many requests" | Retry with exponential backoff |
| Auth (401/403) | "unauthorized", "forbidden" | Fatal - stop immediately |
| Quota Exceeded | "quota", "billing", "insufficient" | Fatal - stop immediately |
| Timeout | Exit code 124 | Retry with backoff |
| Network | "connection", "ECONNREFUSED" | Retry with backoff |
| API Error (5xx) | "500", "502", "503" | Retry with backoff |
Fatal Errors
When quota/auth errors are detected:
- Task marked as
fatal (won't retry)
- Error recorded in state file
- Execution stops after current wave
- Summary includes error details
Resuming After Errors
scripts/captain.sh --epic 151 --resume
scripts/captain.sh --epic 151 --resume --force
Process Liveness
- Lock files prevent duplicate runs
- Heartbeat files detect stale processes
--force overrides stale locks
Examples
scripts/swarm.sh --timeout 30 -j 2 48 50 52
scripts/pr-swarm.sh --no-push 101 102
scripts/captain.sh --epic 151 --dry-run
scripts/captain.sh --epic 151 --model opus -j 3
scripts/captain.sh --epic 151 --resume
scripts/captain.sh --epic 151 --resume --force
scripts/commander.sh --milestone 200 --max-parallel 3
scripts/commander.sh --epics 151 160 175
scripts/commander.sh --project "Build REST API for user management with JWT auth"
scripts/commander.sh --project "CLI todo app" --dry-run
scripts/commander.sh --milestone 200 --cleanup
scripts/commander.sh --epics 151 160 --merge-prs