---
name: route-task
description: Decides which subagent and which skills should handle a task by reading CLAUDE-agents.md and CLAUDE-skills.md, applying the routing-rules.json heuristics, and returning a structured recommendation. Called by `orchestrate` after the local inventory phase.
when_to_use: |
  Called by the `orchestrate` skill in step 3. Can also be invoked directly:
  "qual subagente e skills para refatorar este componente shadcn?",
  "rote esta tarefa: <descrição>".
disable-model-invocation: false
allowed-tools: Read Bash(test *) Bash(jq *)
---

# Route task

Task: $ARGUMENTS

## Workflow

### 1. Read context files (best-effort)

```bash
test -f ~/.claude/CLAUDE-agents.md && echo "agents-md found"
test -f ~/.claude/CLAUDE-skills.md && echo "skills-md found"
```

- `Read ~/.claude/CLAUDE-agents.md` (subagents cheatsheet — model routing, blueprints, stack mapping).
- `Read ~/.claude/CLAUDE-skills.md` (skills cheatsheet — by stack, top skills, patterns).
- If either is missing, proceed with the routing-rules.json fallback.

### 2. Read routing rules

`Read ${CLAUDE_SKILL_DIR}/../discover-skill/references/routing-rules.json`

Note: `route-task` lives in the same plugin as `discover-skill`, so its rules are siblings under `skills/discover-skill/references/`.

### 3. Score candidates

For each rule in `routing-rules.json`:

- Compute match score:
  - `+10` per `any_keyword` hit in the task text (case-insensitive)
  - `+5` per `any_path` glob that matches files mentioned in the task or open in context
  - `+priority/10` from the rule itself
- Track which rule won.

### 4. Cross-reference with `CLAUDE-agents.md` and `CLAUDE-skills.md`

- Use the winning rule's `subagent_primary` and look it up in `CLAUDE-agents.md` to confirm:
  - Model tier (Opus/Sonnet/Haiku) and rationale
  - Permissions/role restrictions
  - Whether it appears in the user's installed plugins (`voltagent-*`, etc.)
- Use the winning rule's `skills` and look them up in `CLAUDE-skills.md`:
  - Pull the top recommended one per stack-row that matches.
  - Add `superpowers:*` skills based on task type (planning, TDD, debugging).

### 5. Decide on `context: fork` vs subagent skills field

- **`context: fork`** is right when the task is **isolable research/planning** with no need for the conversation history. Mark it in the recommendation.
- **subagent `skills:` field** is right when the subagent will be reused across the project (recommend creating `.claude/agents/<name>.md` in the project).

### 6. Output

Return a structured block:

```markdown
## Routing decision for: <task>

**Primary subagent:** `react-specialist` (voltagent-lang, Sonnet)
- Reason: rule "shadcn/tailwind" matched (+10 for shadcn keyword, +5 for **/*.tsx path), priority 90.
- Source: voltagent-lang plugin v1.0.4.

**Secondary subagent(s):** `test-automator` (voltagent-qa-sec, Sonnet)
- Reason: task contains "tests" keyword, paired automatically with frontend work.

**Skills required:**
| Skill | Source | Already local? | Why |
|---|---|---|---|
| anthropic-skills:frontend-design | anthropic-skills plugin | ✓ | Stack match (frontend) |
| shadcn/ui | shadcn-ui/ui repo | ✗ | Stack match (shadcn) — needs install |
| superpowers:test-driven-development | superpowers plugin | ✓ | TDD for the test side |

**Execution hint:**
- Use `context: fork` with `agent: Explore` for the initial codebase scan if needed.
- For permanent dispatch: create `.claude/agents/react-specialist.md` in the project with `skills: [frontend-design, shadcn-ui]` so future tasks preload skill content.

**No-match disclaimer:** if no rule scored above 0, fallback rule `priority: 30` was used. Recommend asking the user to clarify scope.
```

## Guardrails

- **Never dispatch automatically.** This skill only **recommends**. The orchestrator decides whether to execute.
- **Never recommend `general-purpose` Agent** — it is denied by user policy in `.claude/settings.local.json`.
- **Cap parallel subagents at 3-4.** If more than 4 candidates score high, list them but mark the bottom ones as "candidates pruned for parallelism budget".
- **Honor user CLAUDE.md / CLAUDE-agents.md guidance over routing-rules.json** — if the user's cheatsheet says "X stack uses Y agent", that wins over the catalog default.
