Claude Code Subagents Explained: What They Are and When to Use Them
A Claude Code subagent is a specialized AI assistant that works on one kind of task in its own separate context window, with its own system prompt and tool permissions. It does the work and returns only a summary to your main conversation.
That one idea explains most of what subagents are for: keeping noisy work out of your main session, limiting what a helper can touch, and running some work on a cheaper model. This article covers how delegation works, what a subagent can and cannot see, the built-in subagents, when to use them, and what they cost. To build your own, follow how to create a custom subagent. The Claude Code subagents hub links all related guides.
What a subagent is
The official docs describe subagents as helpers you use "when a side task would flood your main conversation with search results, logs, or file contents you won't reference again". The subagent does that work in its own context and returns only the summary.
Technically, a subagent is a Markdown file with YAML front matter. The text below the front matter is its system prompt. You can write your own, or use the built-in ones that ship with Claude Code.
A subagent gives you five things:
- Preserved context: exploration and implementation stay out of your main conversation.
- Enforced constraints: you limit which tools it can use.
- Reusable setups: user-level subagents work across all your projects.
- Specialized behavior: a focused system prompt for one domain.
- Cost control: you can route tasks to faster, lower-cost models such as Haiku.
How delegation works
Delegation follows a simple flow.
- You make a request in the main conversation.
- Claude decides whether a subagent fits. It uses your request, the
descriptionfield of each available subagent, and the current context. - Claude writes a delegation message that summarizes the task and starts the subagent.
- The subagent works in its own context window and may use its own tools.
- Its final report returns to Claude, which continues the main conversation.
Descriptions matter. Phrases such as "use proactively" in a description encourage Claude to delegate without being asked. You can also call a subagent yourself:
- Plain language: "Use the test-runner subagent to fix failing tests."
- @-mention:
@"code-reviewer (agent)" look at the auth changes, or typed as@agent-code-reviewer. - Whole session:
claude --agent code-reviewer.
Subagents can run in the foreground or the background. A foreground subagent blocks the main conversation until it finishes, and permission prompts come to you as they appear. A background subagent runs while you keep working, and Claude Code shows any permission prompt in your main session, naming the subagent that asks. With nothing configured, a subagent that Claude spawns from your main conversation (other than the built-in web-fetch) starts in the background.
What a subagent sees and does not see
Each subagent starts with a fresh, isolated context window. This is the key difference from the main session.
It does not see:
- Your conversation history.
- Skills you have already invoked.
- Files Claude has already read.
- Your output style.
- The main conversation's auto memory.
It does load:
- The CLAUDE.md files in the hierarchy the main conversation loads, including
~/.claude/CLAUDE.mdand project rules. The built-in Explore, Plan andweb-fetchagents skip them. - Any skills named in its own
skillsfield, with their full content preloaded. - The built-in tools and MCP tools available in the main conversation, narrowed by its
toolsanddisallowedToolssettings.
Because the subagent knows only what the delegation message tells it, a good prompt and a clear task description matter more than usual.
Forks are the exception. A fork is a subagent that inherits the entire conversation so far. It shares the parent's system prompt, tools, model and prompt cache, and only its final result returns. You can start one yourself with /subtask followed by a task. Because a fork reuses the parent's prompt cache, the docs note it costs less than a fresh subagent for tasks that need the same context.
The built-in subagents
Claude Code ships with these, and Claude uses them automatically:
| Subagent | Purpose |
|---|---|
| Explore | Fast, read-only search and codebase exploration. Write and Edit are denied. Thoroughness levels: quick, medium, very thorough. |
| Plan | Read-only research used in plan mode. |
| general-purpose | All subagent-available tools, for complex multi-step tasks that need both exploration and action. |
claude | Catch-all that follows the model order. |
statusline-setup | Helper for status line setup (runs on Sonnet). |
claude-code-guide | Answers questions about Claude Code (runs on Haiku). |
web-fetch | Fetches web pages (Haiku or the parent model). |
A user or project subagent named Explore overrides the built-in one. To turn built-ins off, deny them in permissions, for example "permissions": { "deny": ["Agent(Explore)"] }.
When to use a subagent
Use a subagent when:
- The task produces verbose output you do not need afterward. Running a test suite, fetching documentation or processing logs are the classic cases. Example prompt: "Use a subagent to run the test suite and report only the failing tests with their error messages."
- You want to enforce tool restrictions or permissions. A reviewer with
Read, Grep, Globcannot edit your files with those tools. - The work is self-contained and can return a summary.
- You want parallel research. Example: "Research the authentication, database, and API modules in parallel using separate subagents."
- You repeat the same kind of job with the same instructions. That is when a custom subagent pays off.
You can also chain subagents. Ask Claude to use them in sequence: each completes its task and returns results to Claude, which passes relevant context to the next.
When not to use a subagent
Stay in the main conversation when:
- The task needs frequent back-and-forth or iterative refinement.
- Several phases share a lot of context, such as planning, implementation and testing.
- You are making a quick, targeted change.
- Latency matters. A non-fork subagent starts fresh and may need time to gather context.
A simple rule: if you will need the details later, keep the work in the main conversation. If you only need the answer, delegate it.
Parallel versus sequential work
Independent investigations suit parallel subagents, because they do not need each other's results. Dependent steps suit a chain, because each step needs the output of the one before.
Two limits apply. Claude Code allows 20 running subagents by default (CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS changes it). By default, a subagent can also spawn subagents up to three layers below the main conversation. Set CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH to change that, or 1 to disable nesting.
The official docs add a warning: when subagents finish, their results return to your main conversation. Running many subagents that each return detailed results can consume a lot of that context.
What subagents cost
A subagent keeps noise out of your main context, but it is not free.
- Each subagent has its own context window, and its requests count toward your usage limits.
- The official costs guide says the subagent's own requests still draw on your usage. To spend less, choose a smaller model for a subagent (
model: haiku) or run every subagent on one model withCLAUDE_CODE_SUBAGENT_MODELandCLAUDE_CODE_SUBAGENT_MODEL_FORCE=1. - On subscription plans,
/usageshows a breakdown with usage attributed to skills, subagents, plugins and MCP servers. - The dollar figure in
/usageis an estimate computed locally from token counts. Subscribers have usage included in their plan.
More ways to cut spend are in how to track and reduce Claude Code token usage.
Subagents versus agent teams
Subagents report back to the session that started them. Agent teams are a separate, disabled-by-default feature in which several Claude Code instances run, each with its own context window. See Claude Code subagents vs agent teams for the differences.
Watching subagents work
Subagent runs are easy to lose track of, especially in the background. Each run writes its own transcript under ~/.claude/projects/{project}/{sessionId}/subagents/. Agent Office is a free local dashboard that tails those transcripts and shows each handoff on a live map: who assigned the task, which project, how long it has run and how many tokens it used. It reads tool names, task titles, status and token counts, not message text. To use it, follow the setup guide and then open the Office.
Next steps
- Try the built-in Explore subagent by asking Claude to search a codebase.
- Create your first custom subagent with the step-by-step guide.
- Learn where the files live in the file locations cheat sheet.
Sources
- Create custom subagents: https://code.claude.com/docs/en/sub-agents
- Manage costs effectively: https://code.claude.com/docs/en/costs
- Explore the .claude directory: https://code.claude.com/docs/en/claude-directory
Frequently asked questions
What is a Claude Code subagent?
A subagent is a specialized AI assistant that handles one type of task in its own context window, with its own system prompt and tool access. It does the work and returns only a summary to your main conversation.
Do subagents share context with the main session?
No. A normal subagent starts with a fresh, isolated context window. It does not see your conversation history, skills you already invoked or files Claude already read. It does load CLAUDE.md files. The exception is a fork, which inherits the whole conversation.
Can subagents spawn subagents?
Yes, up to three layers below the main conversation by default. You can change the limit with CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH, set it to 1 to disable nesting, or leave Agent out of a subagent's tools.
Do subagents cost more?
Each subagent sends its own requests, so it spends tokens of its own on top of the main conversation. Its verbose output stays out of your main context, which can keep that context smaller. Use a smaller model such as haiku for simple subagent work.
When should I avoid subagents?
Stay in the main conversation for tasks that need frequent back-and-forth, share a lot of context across planning, implementation and testing, are quick targeted changes, or where latency matters. A fresh subagent has to gather context first.
How many subagents can run at once?
Claude Code allows 20 running subagents by default. You can change this with the CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS environment variable.
Which subagents come built in?
Explore (fast, read-only search), Plan (read-only research used in plan mode) and general-purpose (all tools, for multi-step work). Others include claude, statusline-setup, claude-code-guide and web-fetch.