Start-Phase Execute (Team Mode)
Enhanced phase execution with multi-agent teams for parallel task execution.
Speedup: 1.5-2x faster depending on task parallelism
Reference: All TypeScript pseudocode (wave creation, TeamCreate/TaskCreate calls, the full agent spawn-prompt template, polling and shutdown loops), the complete 7-task worked example with display formats, and full error-recovery playbooks live in references/team-mode-examples.md. Read it before executing Part 3, and whenever you need the exact spawn prompt or a display/output format.
Mode Detection
Step 0: Determine Execution Mode
# Check args for --team flag
if args contains "--team":
USE_TEAM_MODE=true
echo "⚡ Team mode: ENABLED (forced)"
elif args contains "--sequential":
USE_TEAM_MODE=false
echo "📝 Team mode: DISABLED (sequential)"
else:
# Auto-detect based on task count and dependencies
task_count=$(grep -c "^## Task" "$task_list_file")
if [ $task_count -ge 7 ]; then
USE_TEAM_MODE=true
echo "⚡ Team mode: ENABLED (auto-detected $task_count tasks)"
else:
USE_TEAM_MODE=false
echo "📝 Team mode: DISABLED ($task_count tasks, threshold is 7)"
fi
fi
Part 1: Create Directories
[Same as original start-phase-execute]
Part 2: Generate Planning Docs
[Same as original start-phase-execute]
Part 3: Execute Tasks (Team-Enhanced)
Full pseudocode and worked example for every step below: references/team-mode-examples.md.
- 3.0 Parse task list — Read
$task_list_file; for each ## Task N: section extract: id, subject, agent_type, depends_on (from "Depends on:" / "Blocked by:"), estimated_time.
- 3.1 Create waves (if USE_TEAM_MODE) — Repeatedly collect all tasks whose dependencies are already completed into the next wave; an empty wave means a circular dependency (abort with error). Display the wave analysis: per-wave tasks and timing, sequential vs parallel estimate, speedup factor.
- 3.2 Create team —
TeamCreate({ team_name: "phase-execution", description, agent_type: "general-purpose" }); creates ~/.claude/teams/phase-execution/config.json and ~/.claude/tasks/phase-execution/.
- 3.3 Create task entries —
TaskCreate per task; description embeds the claim → execute → quality gates → self-review → commit → mark-complete loop, metadata carries agent_type/wave/estimated_time. Wire dependencies with TaskUpdate({ addBlockedBy }).
- 3.4 Execute waves — Per wave, spawn one
Task agent per task (subagent_type from the task, team_name: "phase-execution", model: "sonnet" — Haiku is too weak). Use the full spawn-prompt template from the reference file; it makes each agent: claim its task, read requirements, verify blockers complete (recheck every 30s), execute following project patterns (Memory Bank, Documentation Hub), pass quality gates (lint/build/tests — HARD BLOCKS, fix before committing), self-review, git commit co-authored by the agent, mark complete, then claim the next unblocked task or go idle. Team lead polls TaskList every 10s until all wave tasks are completed; any failed task aborts the wave with an error.
- 3.5 Verify all complete —
TaskList; if any task is not completed, list id/subject/status/owner and abort.
- 3.6 Shut down team — Read the team config's members,
SendMessage a shutdown_request to each, wait ~5s for confirmations, then TeamDelete.
Part 4: Task Updates & Commits
In team mode, each agent handles its own task updates and git commit during Step 3.4. Display a git-history summary of the agent commits (format in reference file).
Part 5: Phase Closeout
Display the closeout summary: tasks completed, duration, quality gates passed, commits, per-wave breakdown, speedup analysis, agent utilization, peer communication, quality summary, and next steps (/pm-db dashboard, /memory-bank-sync, phase-summary.md). Full example in reference file.
Fallback: Sequential Execution
If USE_TEAM_MODE == false: execute tasks one at a time with direct Task calls (no team), running quality gates and committing after each task — the original start-phase-execute logic.
Error Handling
Full recovery playbooks with example displays: references/team-mode-examples.md.
- Team creation fails —
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS not enabled: add it to settings.json env, retry with --team, or fall back to --sequential.
- Agent spawn fails — check
which tmux; reduce parallelism (sequential mode) or spawn a replacement agent manually.
- Task deadlock — a blocking task stuck
in_progress too long: SendMessage the owning agent, mark the task complete manually if the work is done, or spawn a replacement.
- Quality gate fails — automatic recovery: the agent fixes the issues, re-runs the gates, retries the commit. No manual intervention needed.
Best Practices
- Context — teammates don't inherit conversation history; put task details, file locations, API contracts in the spawn prompt.
- Task size — self-contained units (function, test file, component); too small wastes coordination, too large risks wasted effort.
- File conflicts — each teammate owns different files; concurrent edits to one file can overwrite.
- Monitor and steer — check progress, redirect failing approaches, synthesize findings.
- Gate with hooks —
TeammateIdle exit 2 sends feedback; TaskCompleted exit 2 prevents completion.
Token Usage & When to Use Team Mode
Team mode (7 tasks, 7 agents): ~450k tokens / 84 min vs sequential ~150k tokens / 127 min — 3x tokens for 1.5x speed.
- ✅ Complex features (2+ hours sequential), multiple independent modules, time more valuable than cost
- ❌ Simple changes (< 1 hour sequential), routine maintenance, single-file modifications
Usage Examples
/start-phase-execute ./job-queue/feature-auth/task-list.md # auto-detect: team mode at >= 7 tasks
/start-phase-execute ./job-queue/feature-profile/task-list.md --team # force team mode even if < 7 tasks
/start-phase-execute ./job-queue/feature-logout/task-list.md --sequential # force sequential even if 7+ tasks
Integration with Hooks
on-phase-run-start (phase_run_id → spawn prompts), on-task-run-start/-complete (task_run_id, duration, exit code → PM-DB), TeammateIdle (exit 2 = feedback to idle agent), TaskCompleted (exit 2 = reject completion). Details in reference file.
1---2name: start-phase-execute-team3description: Parallel task execution with multi-agent teams and quality gates4---56# Start-Phase Execute (Team Mode)78Enhanced phase execution with multi-agent teams for parallel task execution.910**Speedup:** 1.5-2x faster depending on task parallelism1112> **Reference:** All TypeScript pseudocode (wave creation, TeamCreate/TaskCreate calls, the full agent spawn-prompt template, polling and shutdown loops), the complete 7-task worked example with display formats, and full error-recovery playbooks live in `references/team-mode-examples.md`. Read it before executing Part 3, and whenever you need the exact spawn prompt or a display/output format.1314---1516## Mode Detection1718**Step 0: Determine Execution Mode**1920```bash21# Check args for --team flag22if args contains "--team":23 USE_TEAM_MODE=true24 echo "⚡ Team mode: ENABLED (forced)"25elif args contains "--sequential":26 USE_TEAM_MODE=false27 echo "📝 Team mode: DISABLED (sequential)"28else:29 # Auto-detect based on task count and dependencies30 task_count=$(grep -c "^## Task" "$task_list_file")3132 if [ $task_count -ge 7 ]; then33 USE_TEAM_MODE=true34 echo "⚡ Team mode: ENABLED (auto-detected $task_count tasks)"35 else:36 USE_TEAM_MODE=false37 echo "📝 Team mode: DISABLED ($task_count tasks, threshold is 7)"38 fi39fi40```4142---4344## Part 1: Create Directories4546[Same as original start-phase-execute]4748## Part 2: Generate Planning Docs4950[Same as original start-phase-execute]5152---5354## Part 3: Execute Tasks (Team-Enhanced)5556Full pseudocode and worked example for every step below: `references/team-mode-examples.md`.5758- **3.0 Parse task list** — Read `$task_list_file`; for each `## Task N:` section extract: id, subject, agent_type, depends_on (from "Depends on:" / "Blocked by:"), estimated_time.59- **3.1 Create waves** (if USE_TEAM_MODE) — Repeatedly collect all tasks whose dependencies are already completed into the next wave; an empty wave means a circular dependency (abort with error). Display the wave analysis: per-wave tasks and timing, sequential vs parallel estimate, speedup factor.60- **3.2 Create team** — `TeamCreate({ team_name: "phase-execution", description, agent_type: "general-purpose" })`; creates `~/.claude/teams/phase-execution/config.json` and `~/.claude/tasks/phase-execution/`.61- **3.3 Create task entries** — `TaskCreate` per task; description embeds the claim → execute → quality gates → self-review → commit → mark-complete loop, metadata carries agent_type/wave/estimated_time. Wire dependencies with `TaskUpdate({ addBlockedBy })`.62- **3.4 Execute waves** — Per wave, spawn one `Task` agent per task (`subagent_type` from the task, `team_name: "phase-execution"`, `model: "sonnet"` — Haiku is too weak). Use the full spawn-prompt template from the reference file; it makes each agent: claim its task, read requirements, verify blockers complete (recheck every 30s), execute following project patterns (Memory Bank, Documentation Hub), pass quality gates (lint/build/tests — HARD BLOCKS, fix before committing), self-review, git commit co-authored by the agent, mark complete, then claim the next unblocked task or go idle. Team lead polls `TaskList` every 10s until all wave tasks are `completed`; any `failed` task aborts the wave with an error.63- **3.5 Verify all complete** — `TaskList`; if any task is not `completed`, list id/subject/status/owner and abort.64- **3.6 Shut down team** — Read the team config's members, `SendMessage` a `shutdown_request` to each, wait ~5s for confirmations, then `TeamDelete`.6566---6768## Part 4: Task Updates & Commits6970In team mode, each agent handles its own task updates and git commit during Step 3.4. Display a git-history summary of the agent commits (format in reference file).7172## Part 5: Phase Closeout7374Display the closeout summary: tasks completed, duration, quality gates passed, commits, per-wave breakdown, speedup analysis, agent utilization, peer communication, quality summary, and next steps (`/pm-db dashboard`, `/memory-bank-sync`, phase-summary.md). Full example in reference file.7576---7778## Fallback: Sequential Execution7980**If USE_TEAM_MODE == false:** execute tasks one at a time with direct `Task` calls (no team), running quality gates and committing after each task — the original start-phase-execute logic.8182---8384## Error Handling8586Full recovery playbooks with example displays: `references/team-mode-examples.md`.8788- **Team creation fails** — `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS` not enabled: add it to `settings.json` env, retry with `--team`, or fall back to `--sequential`.89- **Agent spawn fails** — check `which tmux`; reduce parallelism (sequential mode) or spawn a replacement agent manually.90- **Task deadlock** — a blocking task stuck `in_progress` too long: `SendMessage` the owning agent, mark the task complete manually if the work is done, or spawn a replacement.91- **Quality gate fails** — automatic recovery: the agent fixes the issues, re-runs the gates, retries the commit. No manual intervention needed.9293---9495## Best Practices96971. **Context** — teammates don't inherit conversation history; put task details, file locations, API contracts in the spawn prompt.982. **Task size** — self-contained units (function, test file, component); too small wastes coordination, too large risks wasted effort.993. **File conflicts** — each teammate owns different files; concurrent edits to one file can overwrite.1004. **Monitor and steer** — check progress, redirect failing approaches, synthesize findings.1015. **Gate with hooks** — `TeammateIdle` exit 2 sends feedback; `TaskCompleted` exit 2 prevents completion.102103---104105## Token Usage & When to Use Team Mode106107Team mode (7 tasks, 7 agents): ~450k tokens / 84 min vs sequential ~150k tokens / 127 min — 3x tokens for 1.5x speed.108109- ✅ Complex features (2+ hours sequential), multiple independent modules, time more valuable than cost110- ❌ Simple changes (< 1 hour sequential), routine maintenance, single-file modifications111112---113114## Usage Examples115116```bash117/start-phase-execute ./job-queue/feature-auth/task-list.md # auto-detect: team mode at >= 7 tasks118/start-phase-execute ./job-queue/feature-profile/task-list.md --team # force team mode even if < 7 tasks119/start-phase-execute ./job-queue/feature-logout/task-list.md --sequential # force sequential even if 7+ tasks120```121122---123124## Integration with Hooks125126`on-phase-run-start` (phase_run_id → spawn prompts), `on-task-run-start`/`-complete` (task_run_id, duration, exit code → PM-DB), `TeammateIdle` (exit 2 = feedback to idle agent), `TaskCompleted` (exit 2 = reject completion). Details in reference file.