Why subagents
Ask Claude to run your tests and 2,000 lines of output land in your conversation: context fills up, and the next answer is pricier and worse. A subagent does the same job in a separate context window and returns three lines: “214 passed, 2 failed, here’s why”.
- Clean context. Noisy work — test runs, logs, searching hundreds of files — stays out of your main thread.
- The right model for each job. Haiku for test runs, Opus for architecture plans, Sonnet for reviews.
- Least privilege. A security auditor can be read-only — it physically can’t change your code.
Subagent, skill or hook?
Rule of thumb: a skill is “how to do it” instructions in your current conversation; a subagent is a separate worker with an isolated context; a hook is something that must always happen. Skills can even run inside a subagent with context: fork.
Built-in subagents
- Explore — fast, read-only code search;
- Plan — read-only research in plan mode;
- general-purpose — a capable helper with all tools.
Your own subagents add project-specific roles on top.
Create a subagent
A subagent is a Markdown file with YAML frontmatter in .claude/agents/ (project, shared via git) or ~/.claude/agents/ (all your projects):
---
name: test-runner
description: "Runs the test suite or specific tests and reports only failures with their likely cause. Use when tests need to be run."
tools: Bash, Read, Grep, Glob
model: haiku
---
You run tests and summarise results. Find the right test command
in package.json, pyproject.toml, Makefile or CLAUDE.md.
Report: passed / failed / skipped; for each failure — test name,
file:line, the error in 1-3 lines and the likely cause.
Do not paste full logs. Do not modify code.
Only name and description are required; the body is the subagent’s system prompt. Note that a subagent does not see your conversation or Claude Code’s system prompt — only these instructions and the task — so make them self-contained.
description. An unquoted colon breaks the YAML and the file is silently skipped — I hit exactly this while building the pack.Key settings
| Field | What it does |
|---|---|
description | when to use it — Claude delegates based on this. Add “Use proactively…” to have it invoked automatically |
tools | allowed tools; omit to inherit all. Reviewers and planners: Read, Grep, Glob |
model | haiku, sonnet, opus, a full model ID, or inherit (default) |
permissionMode | e.g. plan for research-only agents |
maxTurns | cap the number of steps |
memory | the subagent’s own memory: user, project or local |
isolation: worktree | work in a separate git worktree so edits never collide with yours |
skills, mcpServers, hooks | per-subagent skills, MCP servers and hooks |
Restart Claude Code if a new subagent doesn’t show up. To force one model for all subagents, set CLAUDE_CODE_SUBAGENT_MODEL.
Invoking subagents
> Run the tests with the test-runner subagent
> Use code-reviewer to check my changes before I commit
> Ask security-auditor to review the payments module
> Have researcher compare 3 job-queue libraries for Node.js
Claude also delegates on its own when a task matches a subagent’s description. See running tasks and their models with /tasks.
The 8 subagents in the pack
| Subagent | Model | Tools | Job |
|---|---|---|---|
code-reviewer | sonnet | read + git | reviews the diff by severity |
test-runner | haiku | bash, read | runs tests, reports only failures |
debugger | inherit | read, edit, bash | root cause, fix and regression test |
security-auditor | sonnet | read-only | security audit table |
docs-writer | sonnet | read, write | README and API docs from real code |
researcher | sonnet | read + web | sourced answers, library comparisons |
refactor-planner | opus | read-only | step-by-step refactoring plan |
copywriter | sonnet | read, write, web | marketing copy without invented claims |
Install: unzip and copy the files into your project’s .claude/agents/ or ~/.claude/agents/.
Workflows that work
- Feature end to end: you describe it → main agent codes →
test-runnerruns tests →code-reviewerreviews the diff → main agent addresses the comments. - Pre-release:
security-auditor+docs-writerfor README and changelog. - Big refactor:
refactor-plannerdrafts the plan → you approve → the main agent executes step by step.
Common mistakes
- Vague descriptions — Claude can’t tell when to delegate.
- Every tool for everyone — grant the minimum, especially for reviewer roles.
- Opus everywhere — slow and expensive. Haiku handles routine work well.
- Too many subagents per task — each one costs tokens. Two or three specialists beat ten generalists.
Wrap-up
Start with test-runner and code-reviewer — you’ll notice shorter conversations, lower usage and better quality on day one. Then add roles that match your process. See also hooks, skills and MCP.
FAQ
What is a subagent in Claude Code?
A separate AI helper with its own role, model, tools and context window. The main agent delegates a task to it and receives only the result.
Where do subagents live?
In .claude/agents/ inside the project (shared with the team) or ~/.claude/agents/ for all your projects. Each subagent is a Markdown file with YAML frontmatter.
What’s the difference between a subagent and a skill?
A skill is instructions that run in your current conversation. A subagent is a separate worker with its own context and model that returns only its result.
Which model should a subagent use?
Haiku for routine work (tests, search), Sonnet for reviews and writing, Opus for complex planning. By default a subagent inherits the main agent’s model.
Let’s talk about your project
Describe the task in a couple of sentences — I reply within one business day. Free and no obligation.
Telegram Discuss a project