---
description: Agent-to-agent orchestration; when and how to use subagents
globs: ["**/*"]
alwaysApply: true
---

# ORCHESTRATION RULE

**Precursor:** The precursor-workflow rule runs first (goal primacy, full authority, pivot, swarm when uncertain). This rule defines how to orchestrate.

## Goal & Authority (from precursor)

- All orchestration must serve the user's goals. When not 100% sure of the best path, use a swarm: dispatch multiple subagents in parallel to ground in options or consensus, then choose and execute. You have full authority to pivot and adapt.

## Capability

- **Tool:** `mcp_task` — dispatch subagents. Use for multi-step, independent, exploratory, or uncertainty-reduction work.
- **Subagent types:** generalPurpose, explore, shell, code-architect, code-explorer, code-reviewer, code-simplifier.
- **Parallel dispatch:** When 2+ tasks have no shared state or sequential dependency, invoke multiple `mcp_task` calls in one turn (max 4 concurrent).
- **Resume:** Pass `resume` with agent ID to continue a previous subagent.

## When to Use

| Situation | Action |
|-----------|--------|
| **Not 100% sure of best path** | Swarm: dispatch 2+ subagents (e.g. explore + code-architect) in parallel; synthesize and execute best path |
| 2+ independent problems (different files/subsystems) | Parallel dispatch, one agent per domain |
| Implementation plan with independent tasks | Subagent per task; optionally spec + code review per task |
| Broad exploration (structure, patterns, "how does X work?") | `subagent_type: explore`, thoroughness: quick/medium/very thorough |
| Shell/git/commands | `subagent_type: shell` |
| Need architecture/design before coding | `subagent_type: code-architect` |
| Deep code analysis (execution paths, dependencies) | `subagent_type: code-explorer` |
| Review before merge/PR | `subagent_type: code-reviewer` |
| Narrow question (single file/symbol) | Prefer direct tools (grep, read_file) over subagent |

## Grounding (Skills)

- **Dispatching parallel agents:** dispatching-parallel-agents SKILL (when 2+ independent tasks).
- **Subagent-driven development:** subagent-driven-development SKILL (plan execution with independent tasks).
- **Using skills:** Invoke relevant skill before response when ≥1% applicable.
- **Verification before completion:** Run verification command, read output, then claim success.

## Constraints

- All installs and execution: in Docker only (user rule, when applicable).
- Subagent has no access to parent message; provide full context in `prompt` and `attachments` if needed.
- Do not delegate when a single agent can do the work with grep/read/run in one turn.
