---
name: multi-agent
description: "Task orchestrator: runs the full pipeline from a Jira ID or GitHub Issue URL  -  analysis → plan → TDD development → parallel review (Fable + Opus + Sonnet on Claude Code, GPT + Opus + Sonnet on Copilot CLI) → commit → log. Every step is written to agent-log.md. Use when given a Jira ID, a GitHub issue or a free-text task and the whole pipeline should run."
user-invocable: true
argument-hint: 'PROJ-12345 feature/PROJ-12345-order-filter | https://github.com/.../issues/316 | "task text" [autopilot [--loop N]] [--review-rounds N] | status | log #1 | resume #1 | kill #1 | clear-logs | purge | review'
metadata:
  language: en
---

Read and follow the instructions in this file's INSTRUCTION.md section below.

---

# Multi-Agent Task Orchestrator

References under `$HOME/.claude/multi-agent-refs/` are installed with Claude Code. Before routing, read `$HOME/.claude/multi-agent-refs/orchestrator/copilot-pipeline.md`: project detection (cwd decides which input format is accepted, and the wrong format gets a warning), the five input types, the full routing rows, the autopilot matrix, the persona models and the per-phase summaries.

**Access check, before anything else.** Every route runs it, a task input, `jira`, `issue`, `resume`, `autopilot` and `review` included, except `status`, `log` and `help`, which only read; the commands kept open (`feedback`, `setup`, `update`) have their own entries and never reach this check.

```bash
ACCESS_LINE=$(node "$HOME/.copilot/scripts/usage-access.mjs"); ACCESS_RC=$?
```

`ACCESS_RC` 3: print `$ACCESS_LINE` as written and stop: no picker, no assignee change, no comment, no state, attended or unattended. Any other exit continues (the check fails open). Contract: `$HOME/.claude/multi-agent-refs/features/usage-reporting.md` "The access check".

## Routing

`status`, `log [id]`, `resume [id]`, `review` (current diff only), the `autopilot` flag, and no args / `help`. `kill [id]` and `purge` are user-only commands, and `clear-logs` is superseded: name `/multi-agent-kill`, `/multi-agent-purge` or `/multi-agent-prune-logs` for the user to type and stop. Anything else is a task input (Jira ID + branch, GitHub issue URL or number, free text) and enters Phase 0.

**Quoting**: For a double-quoted first argument, strip the surrounding double quotes and unescape (`\"` becomes `"`, and `\\` becomes `\` before a quote or at the end). If the resulting value as a whole is a Jira key, a Jira or GitHub issue URL, `repo#N` or `#N`, it is that structured reference; otherwise it is free text, and a structured token inside a sentence stays free text. Everything after the closing quote is modifiers (`autopilot`, `--loop N`, `--review-rounds N`, the branch name after a Jira key) (`$HOME/.claude/multi-agent-refs/_input-parser.md` "Quoting").

## Task operations

- **kill** is user-only: name `/multi-agent-kill` for the user to type and stop. Its own skill asks before deleting anything.
- **purge** is user-only: name `/multi-agent-purge` for the user to type and stop. Its own skill confirms twice.
- **resume** reads `$HOME/.claude/logs/multi-agent/{project}/{task-id}/agent-state.json` (or `.../artifacts/agent-state.json`) and restarts from `currentPhase + 1`.
- **clear-logs**: **do not run it.** Say it was superseded and name `/multi-agent-prune-logs` or `/multi-agent-garbage-collect` for the user to type.

Read `$HOME/.claude/multi-agent-refs/orchestrator/operations.md` when the input is `status` or `resume`.

## Autopilot

`autopilot` skips confirmations: the Plan Approval Gate becomes a **Gate skip** (log the plan, go to Phase 2), the user test is skipped, commit, push and PR run automatically. **Never skipped:** a blocking review finding returns to Phase 2; kill / purge confirmations always ask; a build failure retries at most 3 times, then pauses and asks. Read `$HOME/.claude/multi-agent-refs/phases/modes.md` when `autopilot` is set. `autopilot --loop N` does not run the task here: it starts `autopilot-loop.mjs start` in the background and reports the loop id (modes.md "Loop mode").

## Agent dispatch - per-persona model routing

Every persona under `$HOME/.claude/agents/*.md` declares `preferredModel`; honor it on every dispatch, on both CLIs.

```bash
persona_file="$HOME/.claude/agents/${persona}.md"
pref_model="$(awk '/^preferredModel:/ {print $2; exit}' "$persona_file")"
override="${PHASE_MODEL_OVERRIDE:-}"
routed="${override:-$("$HOME/.claude/lib/model-dispatch.sh" subagent --persona "$persona" --phase "$currentPhase" --task-kind "$taskType" --default "${pref_model:-opus}" 2>/dev/null)}"
resolved_model="${routed:-${pref_model:-opus}}"
export CLAUDE_CODE_SUBAGENT_MODEL="$resolved_model"
```

The last line is this host's way of handing a child its model and is the only
host-specific step: elsewhere the same rung is passed as a flag on the CLI call
or as a field on the spawn call, and one host also carries a reasoning effort
and a ceiling on how many children run at once. The table of all of them, and
what each host's personas are written in, is
`$HOME/.claude/multi-agent-refs/features/model-fallback.md` "Routing at
dispatch". Resolve the rung the same way everywhere; only that last line moves.

**Precedence:** per-dispatch `PHASE_MODEL_OVERRIDE` > `prefs.global.modelRouting` rule > persona `preferredModel` > global default (`opus`). A rule naming a rung this host does not offer is skipped and the next one answers: features/model-fallback.md "Routing at dispatch". Simple text tasks ask `model-dispatch.sh delegate --default host` first; `free` means `multi-agent:llm_delegate`, never for code, plans, reviews or triage (`$HOME/.claude/multi-agent-refs/features/free-models.md`).

Skill injection (`prefs.global.dynamicSkillLoading`): read `$HOME/.claude/multi-agent-refs/orchestrator/skill-loading.md` when it is on or when composing a sub-agent prompt.

## Phase Pipeline

Run phases sequentially, log every step to `agent-log.md`, and on a failure mark the task `paused` and stop. Each phase's contract is `$HOME/.claude/multi-agent-refs/phases/phase-N-<name>.md`, read when that phase starts; the ref wins over any summary. Update `agent-state.json` at EVERY phase transition.

### Canonical phase labels (TaskCreate + banner)

| # | Label |
| --- | -------------------- |
| 0 | Phase 0: Init |
| 1 | Phase 1: Plan |
| 2 | Phase 2: Dev |
| 3 | Phase 3: Review |
| 4 | Phase 4: Commit & PR |
| 5 | Phase 5: Report |

TaskCreate subjects and `phase-banner.sh` headers (`auto`, `PHASE_LANG=en`) use these labels only, in English on every host. Never invent a label.

#### TaskCreate ordering (strict)

All TaskCreate calls fire in strict phase-number order BEFORE any TaskUpdate (Claude Code only; Copilot CLI has no widget). Never pre-mark a phase completed or skipped: register every tile as `pending`, then flip it. `multi-agent` (autopilot included): 0-5; `multi-agent-analysis`: 0, 1, 3, 4, 5. Contract: `refs/tracker-contract.md`.

### Phase 0: Init

Run all **8 sequential interactive steps** in `$HOME/.claude/multi-agent-refs/phases/phase-0-init.md`; never short-circuit. Step 0: `bash "$HOME/.copilot/lib/credential-inventory.sh" --json` into `agent-state.json.credentialInventory`; never ask for data a mapped credential can fetch. **Exit gate (BLOCKING)**: `node "$HOME/.copilot/scripts/phase0-exit-gate.mjs" "$TASK_ID" --input "$USER_INPUT"`; non-zero means Phase 0 skipped its own output (`taskType`, `baseBranch`, `baseFetchStatus`, a worktree distinct from the project root, the Figma tier for a Figma URL): fix the missing step. Per-project parsing and worktree: `$HOME/.claude/multi-agent-refs/orchestrator/phase-0-projects.md`. Jira input: `bash "$HOME/.copilot/lib/jira-family-write.sh" resolve --state "$STATE_FILE"` (records, writes nothing).

### Phases 1-5

- **1 Plan**: analysis (`explorer`), planning, then the **Plan Approval Gate** (interactive only): clarification max 2 rounds, approval loop `onayla` / `iptal` / free-text.
- **2 Dev**: TDD per todo, build, max 3 fix attempts.
- **3 Review**: three parallel reviewers + one triage pass; blocking goes back to Phase 2 for rework, at most 1 to 3 times (default 2; `review-rounds.mjs next`). Interactive user test via `AskUserQuestion`, saying yes removes the worktree and checks the branch out: `$HOME/.claude/multi-agent-refs/orchestrator/phase-3-user-test.md`.
- **4 Commit & PR**: ask before commit (No pauses; `resume` later) and before the PR; `git add` specific files, never `git add -A`; author from `prefs.global.identities[]`. Read `$HOME/.claude/multi-agent-refs/orchestrator/phase-4-5-projects.md`.
- **5 Report**: finalize `agent-log.md` (`$HOME/.claude/multi-agent-refs/phases/log-format.md`), print the summary.

Component generation: `$HOME/.claude/multi-agent-refs/component-generation.md` and `component-dispatch.md`, only for a design-to-component task.

## Rules

- NEVER put "Copilot", "AI", "generated by" in code or commits
- NEVER commit without passing build or review
- NEVER auto-close an issue (GitHub or Jira); PR bodies use `Ref: #N` / `Related: #N`, never `Closes/Fixes/Resolves`
- Follow existing code style; design tokens, no magic numbers; every public method tested; Xcode header on new Swift files
- Commit: `{type}({scope}): description [PROJ-{id}]`, or `[#{shortId}]` without Jira
- Git author from `prefs.global.identities[]`, never hardcoded

Help: the `multi-agent-help` skill (`/multi-agent-help`).
