| name | team-orchestrator |
| description | Orchestrate a 3-layer agent hierarchy (Department Head → Pod Leads → Sub-Agents) for complex, multi-domain tasks. Use when the user invokes /team or when auto-detect suggests team mode. |
Team Orchestrator — Department Head
You are the Department Head in a hierarchical team orchestrator. You decompose complex tasks, dispatch pod leads, coordinate merges, and report results.
Quick Reference
- You are: L0 Department Head (Opus)
- You dispatch: L1 Pod Leads (Opus/Sonnet, worktree-isolated, team members)
- Pod leads dispatch: L2 Sub-Agents (Sonnet/Haiku, same worktree, NOT team members)
- Hard cap: 25 agents total (you + pod leads + sub-agents approved)
- Communication: TeamCreate + SendMessage + TaskCreate/TaskUpdate/TaskList
- Observability: Append-only .team-log (you are the single writer)
Configuration
Read defaults from .claude/skills/team-orchestrator/config.yaml. User can override via:
/team "task" --pods N --max-agents N --yes
- Explicit skill invocation with pod/model config
Defaults:
- max_agents: 25, max_pods: 5, max_sub_per_pod: 5
- Models: head=opus, lead=opus, sub=sonnet, haiku=allowed
- worktree_cleanup: true
Orchestration Flow
Phase 1: ANALYZE
Parse the user's task. Identify:
- Distinct domains/subsystems involved
- Dependencies between domains (what must finish before what)
- Appropriate number of pods (1-5)
- Pod role assignments and model recommendations
- Estimated sub-agent count per pod
Sizing guidelines:
| Complexity | Pods | Subs/Pod | Total |
|---|
| Trivial | 1 | 0 | 2 |
| Simple | 1-2 | 1-2 | 4-7 |
| Medium | 2-3 | 2-3 | 7-12 |
| Complex | 3-4 | 3-4 | 13-21 |
| Maximum | 5 | 3-4 | 21-25 |
Default to the minimum viable team size. Most tasks need 1-2 pods.
Phase 2: AUTO-SELECT + PROCEED
Based on your analysis, select the team configuration and proceed immediately. Briefly announce the plan as you go:
Deploying team for: "[task summary]"
Pods: N ([pod-name-1] (model), [pod-name-2] (model), ...)
Estimated agents: ~X total
Do not wait for confirmation — the department head is trusted to make good team shape decisions. The user can always /team-cancel if needed.
Phase 3: SETUP
-
Archive previous log: If .claude/skills/team-orchestrator/team-state/.team-log exists, rename to .team-log.<unix-epoch-seconds>.
-
Create team:
TeamCreate(team_name: "team-<short-task-id>", description: "<task summary>")
-
Create tasks: Use TaskCreate for each pod's objective and known sub-tasks.
-
Write to audit log:
Append to .claude/skills/team-orchestrator/team-state/.team-log:
{"ts":"<ISO-8601>","event":"team_start","task":"<task>","pods_planned":<N>,"team":"<team-name>"}
Phase 4: DISPATCH
Spawn pod leads in parallel using the Agent tool. For each pod:
Agent(
name: "pod-<domain>",
model: "<opus or sonnet>",
isolation: "worktree",
team_name: "<team-name>",
run_in_background: true,
prompt: "<contents of pod-lead-prompt.md with placeholders filled:
{{TEAM_NAME}} = team name
{{POD_NAME}} = pod-<domain>
{{OBJECTIVE}} = pod's objective
{{DEPENDENCIES}} = list of pods this one depends on, or 'none'>"
)
Log each dispatch:
{"ts":"...","event":"pod_dispatched","pod":"<name>","model":"<model>","worktree":"auto"}
Phase 5: MONITOR + COORDINATE
While pods are running:
- Receive messages from pod leads (automatic delivery via SendMessage)
- Handle escalations:
- Blocked pod: hold it, check if blocker is done, send "proceed" when ready
- Failed sub-agent: advise pod lead on retry strategy or reassign work
- Spawn approval: check agent cap (read team config members array + count approved sub-agents), approve or deny
- Track progress via TaskList — monitor task completion across all pods
- Log events to .team-log as pods report status
Phase 6: MERGE
When all pods report completion:
- Determine merge order based on dependencies (e.g., backend before frontend)
- For each pod branch, sequentially:
git merge <worktree-branch> --no-ff -m "merge: pod-<domain> into main"
- Resolve conflicts directly if possible (you have full task context as Opus)
- If conflict is too complex: SendMessage to the relevant pod lead with the conflict diff, ask them to resolve
- Log each merge:
{"ts":"...","event":"merge","pod":"<name>","result":"clean|conflict_resolved"}
Phase 7: SHUTDOWN + CLEANUP
- Shutdown pod leads:
SendMessage(to: "*", message: {type: "shutdown_request"})
You are explicitly authorized to originate shutdown_request in this skill.
Wait for acknowledgments from all pod leads before proceeding.
- Clean worktrees (if worktree_cleanup is true):
git worktree remove .claude/worktrees/pod-<domain>
- Delete team:
TeamDelete(team_name: "<team-name>")
- Log completion:
{"ts":"...","event":"team_done","status":"ok","summary":"<summary>"}
Phase 8: REPORT
Summarize to user:
- Number of pods and sub-agents used
- What each pod accomplished
- Merge results (clean or conflicts resolved)
- Test status if applicable
- Any partial failures or worktrees left for inspection
Error Handling
- Pod fails entirely: Log it, preserve worktree, continue with other pods, report partial results
- Multiple pods fail: Preserve all worktrees, log failures, report what succeeded and what didn't
- Merge fails unrecoverably: Preserve worktree branches, abort remaining merges, report to user with branch names for manual recovery
- Cancel (/team-cancel): Send shutdown to all pods, wait for ack, clean up, log final state
Single Active Team
Only one /team invocation at a time. If called while a team is active, tell the user:
"A team is already active: [team-name]. Cancel it with /team-cancel first."
Check by looking for a non-archived .team-log with a team_start but no team_done event. If the user confirms no team is actually running (e.g., previous session crashed), archive the stale log and proceed.
Audit Log
You are the single writer to .claude/skills/team-orchestrator/team-state/.team-log. Never let pod leads or sub-agents write to it. Record events as you receive them via SendMessage. Format: one JSON object per line (JSONL).