Agent Routing Guide
Read this file at the start of every session. It tells you which agents are available and when to use them.
How Agents Work
- Agents are specialist subprocesses. Spawn them to keep your main context clean.
- Worktree agents run in isolation — safe to run in parallel with your work.
- Non-worktree agents share your context — don't edit the same files they're reading.
- Never spawn more than 3 agents simultaneously.
- If a task is small enough to do yourself in 2 minutes, don't spawn an agent for it.
Background-Agent Concurrency
Two background agents on the same branch coexist cleanly:
- Worktree-isolated agents (
isolation: "worktree") each create their own
sibling worktree off origin/HEAD. They never collide on files, refs, or the
index — running multiple in parallel is safe by design.
- Non-isolated agents share the main checkout but are read-only by
convention. The main session and these agents must avoid editing the same
files concurrently; otherwise behavior is up to whoever writes last.
Worktree lock semantics: Claude Code locks each agent worktree with the agent's
pid; the lock survives agent completion. Stale locks are normal. Clean up with
git worktree remove -f -f <path> or the project's worktree-cleanup helper.
The earlier "lock file per branch" plan was rejected after the 2026-04-26
concurrency test — worktree isolation already provides the guarantee a lock
file would have, and a lock would block the legitimate parallel-agents case.
Automatic Triggers
These agents should be spawned without being asked when their trigger condition is met.
build-validator
- Model: Haiku | Isolation: None
- When: Before every commit. After merging worktree branches.
- Trigger: Automatic — spawn when trigger condition is met
- What it does: Quick validation — tests pass, build succeeds, lint clean. Fast and cheap (Haiku model).
- Expect back: Pass/fail with specific errors if failed.
code-simplifier
- Model: Sonnet | Isolation: Worktree
- When: After a feature is implemented and tests pass. Also when you notice growing complexity or duplication.
- Trigger: Automatic — spawn when trigger condition is met (also: /simplify)
- What it does: Reviews code for duplication, unnecessary abstraction, missed reuse opportunities. Simplifies without changing behavior.
- Expect back: Cleanup commits on worktree branch. Diff review before merge.
test-writer
- Model: Sonnet | Isolation: Worktree
- When: After completing implementation of any feature or module.
- Trigger: Automatic — spawn when trigger condition is met
- What it does: Writes unit tests, integration tests, edge case tests. Covers happy path, error cases, boundary conditions.
- Expect back: Test files committed to worktree branch. Merge when reviewed.
Manual Triggers
These agents are spawned when you or the user explicitly requests them.
bug-fixer
- Model: Sonnet | Isolation: Worktree
- When: Bug reported. Test failing. Error in logs. Something broke but you don't want to derail current work.
- Trigger: Manual — spawn when needed
- What it does: Investigates the bug in isolation. Reads logs, reproduces, finds root cause, implements fix, writes regression test.
- Expect back: Fix committed to worktree branch with regression test.
build-fixer
- Model: Sonnet | Isolation: Worktree
- When: Build is broken. Tests failing. Lint errors blocking commit. Type errors after a merge or dependency update.
- Trigger: Manual — spawn when needed
- What it does: Reads error output, categorizes failures (build/test/lint/type), fixes in priority order, verifies each fix. Works in worktree isolation.
- Expect back: All checks passing, with a summary of what was fixed and why.
changelog-generator
- Model: Haiku | Isolation: None
- When: Before releasing a new version. After merging a batch of PRs. When preparing release notes.
- Trigger: Manual — spawn when needed
- What it does: Generates changelogs from git history, PR descriptions, and commit messages. Formats for release notes.
- Expect back: Formatted changelog entry for the release.
doc-writer
- Model: Sonnet | Isolation: Worktree
- When: After implementing new features. After API changes. When README is outdated. Before release.
- Trigger: Manual — spawn when needed
- What it does: Updates documentation, README, API docs from code changes. Keeps docs in sync with implementation.
- Expect back: Updated docs committed to worktree branch.
performance-auditor
- Model: Sonnet | Isolation: None
- When: Performance concern raised. Slow endpoint discovered. Before releasing to production. After major changes.
- Trigger: Manual — spawn when needed
- What it does: Profiles code, identifies bottlenecks, checks database query efficiency, measures response times, suggests optimizations.
- Expect back: Performance report with benchmarks and recommendations.
plan-reviewer
- Model: Opus | Isolation: None
- When: Before executing any implementation prompt. Always.
- Trigger: Manual — /review-plan
- What it does: Reviews implementation plans as a senior staff engineer. Challenges assumptions, finds ambiguity, checks verification strategy, identifies missing edge cases.
- Expect back: Refined plan with concerns addressed, or list of blocking questions.
refactorer
- Model: Sonnet | Isolation: Worktree
- When: Large-scale renames. Architectural pattern changes. Library migrations. Moving code between modules.
- Trigger: Manual — spawn when needed
- What it does: Handles large-scale refactoring in worktree isolation. Renames, architectural changes, pattern migrations with full test verification.
- Expect back: Refactored code on worktree branch with all tests passing.
security-reviewer
- Model: Opus | Isolation: None
- When: Auth changes. User input handling. New API endpoints exposed to external users. Dependency updates.
- Trigger: Manual — spawn when needed
- What it does: Scans for injection vulnerabilities, auth bypasses, data exposure, insecure defaults, dependency vulnerabilities.
- Expect back: Security report with severity ratings.
verify-app
- Model: Sonnet | Isolation: Worktree
- When: Before creating a PR. After major changes.
- Trigger: Manual — /verify
- What it does: Full end-to-end verification. Runs the app, tests all major flows, checks for regressions. More thorough than build-validator.
- Expect back: Detailed verification report. Blocking issues listed.
Reserved
upstream-watcher
- Model: Sonnet | Isolation: None
- Status: Reserved — no in-session command currently invokes this agent.
- Why kept: Reserved for future revival. The /upstream-check slash command was retired in Phase 2 (2026-04); the agent definition is preserved so the scheduled GitHub Actions workflow (.github/workflows/upstream-check.yml) and any future on-demand variant have an established contract to revive.
- Do NOT spawn this agent in regular sessions. It exists for scheduled
automation (CI/Actions) and for future revival; spawning it manually has no
defined entry path today.
Decision Matrix
| You just... |
Spawn this |
Auto? |
| Got a bug report mid-task |
bug-fixer |
Manual |
| Build or tests are broken |
build-fixer |
Manual |
| Are about to commit |
build-validator |
Yes |
| Preparing a release |
changelog-generator |
Manual |
| Notice code getting complex |
code-simplifier |
Yes |
| Need docs updated after implementation |
doc-writer |
Manual |
| Suspect performance issues |
performance-auditor |
Manual |
| Got an implementation prompt |
plan-reviewer |
Manual |
| Need large-scale refactoring |
refactorer |
Manual |
| Made security-sensitive changes |
security-reviewer |
Manual |
| Finished implementing a feature |
test-writer |
Yes |
| Finished a task, ready for PR |
verify-app |
Manual |
Rules
- Universal agents are your defaults. Use them every session.
- Project agents are specialists. Use them when their domain is relevant.
- Worktree agents are safe to run in parallel — they can't break your work.
- Non-worktree agents share your context — don't edit the same files they're reading.
- When in doubt, spawn the agent. A wasted agent run costs less than a missed bug.
- If you spawn an agent and it's not useful, tell the user — they may remove it.
1---2name: agent-routing3description: Agent Routing Guide — when to spawn each installed agent4---56<!-- AUTO-GENERATED-START -->7# Agent Routing Guide89Read this file at the start of every session. It tells you which agents are available and when to use them.1011## How Agents Work12- Agents are specialist subprocesses. Spawn them to keep your main context clean.13- Worktree agents run in isolation — safe to run in parallel with your work.14- Non-worktree agents share your context — don't edit the same files they're reading.15- Never spawn more than 3 agents simultaneously.16- If a task is small enough to do yourself in 2 minutes, don't spawn an agent for it.1718## Background-Agent Concurrency1920Two background agents on the same branch coexist cleanly:2122- **Worktree-isolated agents** (`isolation: "worktree"`) each create their own23 sibling worktree off `origin/HEAD`. They never collide on files, refs, or the24 index — running multiple in parallel is safe by design.25- **Non-isolated agents** share the main checkout but are read-only by26 convention. The main session and these agents must avoid editing the same27 files concurrently; otherwise behavior is up to whoever writes last.2829Worktree lock semantics: Claude Code locks each agent worktree with the agent's30pid; the lock survives agent completion. Stale locks are normal. Clean up with31`git worktree remove -f -f <path>` or the project's worktree-cleanup helper.3233The earlier "lock file per branch" plan was rejected after the 2026-04-2634concurrency test — worktree isolation already provides the guarantee a lock35file would have, and a lock would block the legitimate parallel-agents case.3637---3839## Automatic Triggers4041These agents should be spawned without being asked when their trigger condition is met.4243### build-validator44- **Model:** Haiku | **Isolation:** None45- **When:** Before every commit. After merging worktree branches.46- **Trigger:** Automatic — spawn when trigger condition is met47- **What it does:** Quick validation — tests pass, build succeeds, lint clean. Fast and cheap (Haiku model).48- **Expect back:** Pass/fail with specific errors if failed.4950### code-simplifier51- **Model:** Sonnet | **Isolation:** Worktree52- **When:** After a feature is implemented and tests pass. Also when you notice growing complexity or duplication.53- **Trigger:** Automatic — spawn when trigger condition is met (also: /simplify)54- **What it does:** Reviews code for duplication, unnecessary abstraction, missed reuse opportunities. Simplifies without changing behavior.55- **Expect back:** Cleanup commits on worktree branch. Diff review before merge.5657### test-writer58- **Model:** Sonnet | **Isolation:** Worktree59- **When:** After completing implementation of any feature or module.60- **Trigger:** Automatic — spawn when trigger condition is met61- **What it does:** Writes unit tests, integration tests, edge case tests. Covers happy path, error cases, boundary conditions.62- **Expect back:** Test files committed to worktree branch. Merge when reviewed.63---6465## Manual Triggers6667These agents are spawned when you or the user explicitly requests them.6869### bug-fixer70- **Model:** Sonnet | **Isolation:** Worktree71- **When:** Bug reported. Test failing. Error in logs. Something broke but you don't want to derail current work.72- **Trigger:** Manual — spawn when needed73- **What it does:** Investigates the bug in isolation. Reads logs, reproduces, finds root cause, implements fix, writes regression test.74- **Expect back:** Fix committed to worktree branch with regression test.7576### build-fixer77- **Model:** Sonnet | **Isolation:** Worktree78- **When:** Build is broken. Tests failing. Lint errors blocking commit. Type errors after a merge or dependency update.79- **Trigger:** Manual — spawn when needed80- **What it does:** Reads error output, categorizes failures (build/test/lint/type), fixes in priority order, verifies each fix. Works in worktree isolation.81- **Expect back:** All checks passing, with a summary of what was fixed and why.8283### changelog-generator84- **Model:** Haiku | **Isolation:** None85- **When:** Before releasing a new version. After merging a batch of PRs. When preparing release notes.86- **Trigger:** Manual — spawn when needed87- **What it does:** Generates changelogs from git history, PR descriptions, and commit messages. Formats for release notes.88- **Expect back:** Formatted changelog entry for the release.8990### doc-writer91- **Model:** Sonnet | **Isolation:** Worktree92- **When:** After implementing new features. After API changes. When README is outdated. Before release.93- **Trigger:** Manual — spawn when needed94- **What it does:** Updates documentation, README, API docs from code changes. Keeps docs in sync with implementation.95- **Expect back:** Updated docs committed to worktree branch.9697### performance-auditor98- **Model:** Sonnet | **Isolation:** None99- **When:** Performance concern raised. Slow endpoint discovered. Before releasing to production. After major changes.100- **Trigger:** Manual — spawn when needed101- **What it does:** Profiles code, identifies bottlenecks, checks database query efficiency, measures response times, suggests optimizations.102- **Expect back:** Performance report with benchmarks and recommendations.103104### plan-reviewer105- **Model:** Opus | **Isolation:** None106- **When:** Before executing any implementation prompt. Always.107- **Trigger:** Manual — /review-plan108- **What it does:** Reviews implementation plans as a senior staff engineer. Challenges assumptions, finds ambiguity, checks verification strategy, identifies missing edge cases.109- **Expect back:** Refined plan with concerns addressed, or list of blocking questions.110111### refactorer112- **Model:** Sonnet | **Isolation:** Worktree113- **When:** Large-scale renames. Architectural pattern changes. Library migrations. Moving code between modules.114- **Trigger:** Manual — spawn when needed115- **What it does:** Handles large-scale refactoring in worktree isolation. Renames, architectural changes, pattern migrations with full test verification.116- **Expect back:** Refactored code on worktree branch with all tests passing.117118### security-reviewer119- **Model:** Opus | **Isolation:** None120- **When:** Auth changes. User input handling. New API endpoints exposed to external users. Dependency updates.121- **Trigger:** Manual — spawn when needed122- **What it does:** Scans for injection vulnerabilities, auth bypasses, data exposure, insecure defaults, dependency vulnerabilities.123- **Expect back:** Security report with severity ratings.124125### verify-app126- **Model:** Sonnet | **Isolation:** Worktree127- **When:** Before creating a PR. After major changes.128- **Trigger:** Manual — /verify129- **What it does:** Full end-to-end verification. Runs the app, tests all major flows, checks for regressions. More thorough than build-validator.130- **Expect back:** Detailed verification report. Blocking issues listed.131---132133## Reserved134135### upstream-watcher136- **Model:** Sonnet | **Isolation:** None137- **Status:** Reserved — no in-session command currently invokes this agent.138- **Why kept:** Reserved for future revival. The /upstream-check slash command was retired in Phase 2 (2026-04); the agent definition is preserved so the scheduled GitHub Actions workflow (.github/workflows/upstream-check.yml) and any future on-demand variant have an established contract to revive.139- **Do NOT spawn this agent in regular sessions.** It exists for scheduled140 automation (CI/Actions) and for future revival; spawning it manually has no141 defined entry path today.142---143144## Decision Matrix145146| You just... | Spawn this | Auto? |147|---|---|---|148| Got a bug report mid-task | bug-fixer | Manual |149| Build or tests are broken | build-fixer | Manual |150| Are about to commit | build-validator | Yes |151| Preparing a release | changelog-generator | Manual |152| Notice code getting complex | code-simplifier | Yes |153| Need docs updated after implementation | doc-writer | Manual |154| Suspect performance issues | performance-auditor | Manual |155| Got an implementation prompt | plan-reviewer | Manual |156| Need large-scale refactoring | refactorer | Manual |157| Made security-sensitive changes | security-reviewer | Manual |158| Finished implementing a feature | test-writer | Yes |159| Finished a task, ready for PR | verify-app | Manual |160161---162163## Rules1641. Universal agents are your defaults. Use them every session.1652. Project agents are specialists. Use them when their domain is relevant.1663. Worktree agents are safe to run in parallel — they can't break your work.1674. Non-worktree agents share your context — don't edit the same files they're reading.1685. When in doubt, spawn the agent. A wasted agent run costs less than a missed bug.1696. If you spawn an agent and it's not useful, tell the user — they may remove it.170<!-- AUTO-GENERATED-END -->