TL;DR

Claude Code subagents are isolated Claude instances with their own context window, tools, and system prompt. Use one when a side task would otherwise dump a pile of logs, search results, or file bodies into your main conversation. They shine for parallel exploration, cheap-model routing, and enforcing read-only boundaries, and they stop being worth the setup cost the moment the task is small enough that copying the output back by hand is easier.

Subagent behavior and model pricing last verified against the Claude Code docs and Anthropic’s pricing page: November 20, 2026.

Why subagents matter

The case for subagents shows up on the first big codebase audit. The main conversation burns most of its context window reading files nobody will look at again, and the actual recommendations come out thin because there’s no room left to think. A dedicated repo-explorer subagent does that reading in its own context and hands back a summary, so the main session keeps its room for the analysis.

Subagents are a context-management tool first and a cost-management tool second. Everything else (parallelism, tool scoping, model routing) follows from those two.

What a subagent actually is

Each subagent is a Markdown file with YAML frontmatter, stored in .claude/agents/ (project) or ~/.claude/agents/ (user). Claude Code loads them at session start and watches both directories for changes. When a request matches a subagent’s description, Claude delegates: the subagent runs in a fresh context window, uses whatever tools you allowed it, and returns only a summary to the main thread (Anthropic’s subagent docs describe this as “preserving context” and list it as the primary motivation).

The minimal file is embarrassingly short:

---
name: repo-explorer
description: Explore and summarize an unfamiliar codebase. Use proactively before planning changes.
tools: Read, Grep, Glob, Bash
model: haiku
---

You are a repo-exploration specialist. When given a path or question,
walk the codebase with Read, Grep, and Glob. Return a concise summary:
directory layout, build and test commands, entry points, and any
obvious architectural patterns. Do not edit files.

The frontmatter says who it is and what it can touch; the body is the system prompt. Claude Code also ships several built-in subagents; the three you meet first are Explore (read-only, tuned for fast codebase search), Plan (plan mode), and general-purpose (full tools). One thing worth knowing: Explore used to be pinned to Haiku, but it now runs on your main session’s model. The one exception is a Fable session. There, Explore drops to the model the opus alias points at if you connect through a Claude subscription, the Console, or an ANTHROPIC_BASE_URL gateway, and it stays on Fable on Bedrock, Google’s Agent Platform, or Microsoft Foundry. If you want exploration locked to a cheaper model, define your own subagent named Explore with model: haiku. The docs state that a user or project subagent named Explore overrides the built-in and keeps its own model field. Built-ins are usually where people start before they realize custom ones fit their actual workflow better.

When to spin one up (and when to skip it)

Spinning one up is cheap — you ask Claude to write the file, or drop the Markdown in yourself — so the real question is whether a subagent pays back its setup cost. My rough rule:

SituationSubagent?
Task produces logs or file bodies you won’t rereadYes
You keep copy-pasting the same “find X in the codebase” requestYes
You want read-only enforcement (e.g., a reviewer that can’t edit)Yes
Task runs cheap on Haiku while main runs on OpusYes
You’ll reuse this in other projectsYes (user scope)
One-off question with a short answerNo, just ask Claude directly
The logic depends on state held in the main conversationNo, keep it in-thread

The second column flips to “no” fast when the task is genuinely small. Wrapping a 4-line grep inside a subagent “for cleanliness” just adds a YAML file to debug. The tool wants to help with noise reduction; it isn’t a replacement for being willing to read the file yourself.

Your first custom subagent, step by step

The fastest path is to ask Claude to write the file for you — something like Create a pr-reviewer subagent in .claude/agents/ that reviews diffs for security and test coverage. (The old interactive /agents creation wizard is gone after v2.1.197; typing /agents now just reminds you to ask Claude or edit .claude/agents/ directly.) If you’d rather see the raw mechanics, here’s a read-only PR reviewer:

---
name: pr-reviewer
description: Review diffs for quality, security, and test coverage. Use proactively after code changes.
tools: Read, Grep, Glob, Bash
disallowedTools: Write, Edit
model: sonnet
memory: project
color: blue
---

You are a senior code reviewer. When invoked:

1. Run `git diff --staged` (or the diff the user names) and read the
   full touched files for context, not just the hunks.
2. Check for: obvious bugs, missing error handling on new code paths,
   N+1 queries, secrets, tests for new behavior.
3. Respond with at most 10 findings, each as: file:line, severity
   (blocking / nit / suggestion), and a concrete rewrite.

Update your agent memory with patterns you see more than once.

Drop that at .claude/agents/pr-reviewer.md. Claude Code watches the agents directory and picks the new file up within a few seconds, with no restart needed. Two documented exceptions: Claude Code doesn’t watch .claude/agents/ inside directories added with --add-dir, and sessions started with --disable-slash-commands don’t watch the agents directories at all. Restart in those cases. From there Claude routes PR reviews there automatically if your message sounds like a review request. To force it, @agent-pr-reviewer look at the auth changes. The @-mention guarantees the subagent runs; plain natural language leaves the decision to Claude’s router.

A few of those fields deserve a closer look.

The tools + disallowedTools combination has subtle ordering. If both are set, disallowedTools applies first, then tools picks from what’s left. Use the denylist to inherit everything except writes, and the allowlist for a tight whitelist. Don’t set both unless you’ve thought through the ordering: it’s easy to ship a subagent that silently has no tools because the allowlist and denylist cancel each other out.

Setting memory: project gives the subagent its own directory at .claude/agent-memory/pr-reviewer/ to build up a MEMORY.md over time. Over time, a reviewer can record there that your team argues about naming conventions on every PR, and stop flagging them. The docs also list user scope (~/.claude/agent-memory/<name>/) and local scope (.claude/agent-memory-local/<name>/) for memory you don’t want in the repo.

color feels cosmetic but earns its place when three subagents run in parallel — the tinted task labels are how you know which transcript is which without reading them all.

Subagents vs skills vs agent teams

People search this comparison constantly, so here’s the quick rundown:

FeatureSubagentSkillAgent team
Runs in own context windowYesNo by default (injects into yours); context: fork runs it in a subagentYes, each teammate has its own
Separate tool setYesNoYes
Can run in parallelYesOnly with context: fork (forked skills run in the background by default)Yes, explicitly designed for it
Agents message each otherOnly named subagents that have the SendMessage toolNoYes, teammates message each other directly
AvailabilityStableStableExperimental, off by default
Good forHeavy, self-contained side tasksInjecting domain knowledge or proceduresMulti-agent workflows that need message passing

The practical heuristic: if you need knowledge (how we write migrations, where our API conventions live), write a skill. If you need capability (go off and audit the whole repo, come back with a summary), write a subagent. If you need multiple specialists talking to each other across jobs (a researcher handing findings to a writer who hands the draft to a reviewer), that’s agent teams. Agent teams are still experimental and disabled by default: the agent teams docs say to set CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 and list known limitations around session resumption, task coordination, and shutdown.

The line between skills and subagents also got blurrier this year. A skill with context: fork in its frontmatter runs in a forked subagent, and its agent field picks which subagent type runs it. That gives you a skill’s on-demand loading with a subagent’s separate context. Use it for procedures that read a lot (say, a “regenerate the API client” skill) and keep plain skills for short conventions.

You can also combine them. A subagent’s frontmatter accepts a skills: list that preloads skill content into its startup context. For example, an api-implementer subagent can preload api-conventions and error-handling-patterns; the subagent gets the knowledge without burning tokens discovering it.

Tool scoping: less is actually more

The strongest argument for subagents is blast radius, more than context. A subagent with tools: Read, Grep, Glob physically cannot write a file. No prompt injection, no misread instruction, no rogue tool call can turn a reviewer into a deleter, which is a much stronger guarantee than “we told it not to.”

Two patterns that come up often:

  1. The read-only researcher inherits nothing and explicitly lists Read, Grep, Glob, Bash. Bash is safe here because the subagent’s prompt says “never write or execute destructive commands,” and, if you’re paranoid, a PreToolUse hook can block rm, curl | sh, and friends before they run. My Claude Code hooks guide walks through building exactly this kind of command-blocking hook from scratch.
  2. The scoped Bash executor has full Bash, but a hook script rejects any command not starting with pytest, go test, or npm test. Now the subagent can run tests and only run tests.

Hooks are where this gets serious. A subagent can validate every tool call against a script you control. That’s how you let Claude do useful unattended work without letting it nuke the repo. The four production wipes in our agent guardrails write-up (PocketOS, Replit, Amazon) share one failure: an agent with root-equivalent credentials and no gate on destructive actions. A tight tools list plus a blocking hook is that gate at the subagent level.

Model selection: the cheapest optimization

A subagent with no model field runs on the same model as the conversation that starts it, which is what model: inherit does too. That’s the single most expensive default in Claude Code. If your main session runs on Opus 5.5 (the Claude Code default on paid plans and the API) and you spawn four subagents for a codebase audit, all four run on Opus too.

The split I’d recommend: Haiku handles file walking, grep, and anything that’s “find this, summarize that.” Sonnet handles code review, refactor proposals, and anything where the quality of reasoning shows up in the output. Opus comes out only when the subagent is doing the hard thinking: architecture analysis, spec synthesis, adversarial review. The price gap is wider than it was in the 4.x generation, when Opus 4.x at $5/$25 per MTok was 5× the price of Haiku 4.5 at $1/$5. On Anthropic's API pricing today, Opus 5.5 costs $4/$20 per MTok and Haiku 5.5 costs $0.10/$0.50 for prompts up to 100K tokens, a 40× gap. Above 100K tokens Haiku 5.5 bills $0.50/$2.50, still 8× under Opus.

To put numbers on that, I priced a four-subagent audit with a short script. The assumptions: each subagent reads 150K input tokens across about 15 turns, its largest single prompt stays near 40K tokens (so Haiku 5.5 stays in its cheaper tier), and it writes 8K output tokens. Cache discounts are left out. Running it prints:

model                      per audit  vs Opus  100 audits
Opus 5.5 (inherit)             3.040     1.0x      304.00
Sonnet 5.5                     1.520     2.0x      152.00
Haiku 5.5 (<100K prompt)       0.076    40.0x        7.60
Haiku 5.5 (>100K prompt)       0.380     8.0x       38.00
3x Haiku + 1x Sonnet           0.437     7.0x       43.70

Dollar amounts are USD. The mixed row is the split above: three explorers on Haiku and one reviewer on Sonnet cost $0.44 per audit against $3.04 when everything inherits Opus. On a team that runs a hundred audits a month, that’s roughly $44 versus $304. Prompt caching narrows the gap somewhat, since Opus 5.5 cache hits bill at $0.20 per MTok, but the order of magnitude holds. For “tell me the directory layout and build commands,” I wouldn’t expect Opus to buy you a better answer. Save the expensive models for the places where reasoning depth actually changes the answer.

Two newer knobs matter here. Claude can pass a model alias when it spawns a subagent, and the docs rank that per-call choice above the definition’s model field, so a model: haiku line is a default, not a lock. And if you want one model for every subagent, set CLAUDE_CODE_SUBAGENT_MODEL (for example to haiku) together with CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1. The force flag needs Claude Code v2.1.257 or later. On its own, the first variable doesn’t change the built-in Explore and Plan subagents.

Where parallel execution actually pays off

Claude can run multiple subagents in parallel by spawning them in a single response. This is the feature that turns a long sequential audit into a few passes that run at the same time. Ask for a codebase review and Claude can fire off security-reviewer, test-coverage-reviewer, and style-reviewer at once, each with its own context, its own tools, its own transcript.

Two things worth knowing before you lean on this:

  1. Subagents can nest now — up to three layers deep by default. This flipped from the early behavior, where a subagent couldn’t spawn anything. Today, a subagent that lists the Agent tool can spawn its own subagents, and the default depth limit is three layers below your main conversation (tune it with CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH, or set it to 1 to turn nesting off). Nesting earns its keep when a delegated task itself fans out — a reviewer that dispatches a verifier per finding, say — because only the top-level summary comes back to your main thread. Don’t treat a verifier layer as a guarantee, though. In the research on error cascades in multi-agent LLM systems, one false claim planted in a single agent spread to every agent in five of six frameworks, reviewer and QA agents included. Give a verifier subagent the source files to check against, not just the summary it is meant to verify. At the depth limit, Claude Code withholds the Agent tool, so the deepest subagent does its work itself and returns one summary. If you want a subagent to stay read-only and never spawn, just omit Agent from its tools.
  2. Parallel subagents mostly report back, not sideways. By default they return to the main thread, which merges their outputs. Subagents that Claude named when it spawned them can now message each other through the SendMessage tool, but only if that tool is in their tools list. For real cross-talk (the reviewer asking the researcher a follow-up, a shared task list), agent teams are still the better fit.

Common mistakes

The pitfalls below are the common ones:

  1. Writing vague descriptions. description: "helps with code" won’t get delegated to, because Claude has nothing to match against. Be specific about the trigger: “Review staged diffs for security and test coverage. Use proactively after code changes.”
  2. Inheriting all tools out of habit. If you don’t list tools, the subagent gets everything the main conversation has, including MCP servers you didn’t intend to expose. Start from the denylist or a tight allowlist. (If you’re building your own MCP servers to give those subagents access to private data or APIs, my FastMCP tutorial walks through the Python framework most people reach for.)
  3. Giving it write access “just in case.” Most subagents should never edit, and limiting to read-only makes the thing safer and easier to trust the first time it runs unattended.
  4. Skipping the memory flag on reviewers. A pr-reviewer with memory: project gets better every week; without it, you re-teach the same conventions every session.
  5. Defaulting to Opus everywhere. Leaving model unset means the subagent runs on your main session’s model, and in Claude Code that is Opus 5.5 by default. Set model: haiku or model: sonnet explicitly unless the subagent really needs frontier reasoning.
  6. One giant subagent. A do-everything subagent is just the main thread with extra YAML. Split by job-shape: test-runner, docs-researcher, migration-writer. Narrow is what makes them delegatable.

If you’re hitting the ceiling of what 5-6 subagents can handle, dynamic workflows let you orchestrate dozens to hundreds of agents from a script with parallel(), pipeline(), and structured schemas.

Subagents multiply context windows, but the harder question is what to put in them — context engineering digs into that.

Sources

FAQ

What are Claude Code subagents?

Subagents are specialized Claude instances that Claude Code can delegate tasks to. Each one runs in its own context window with its own system prompt, tools, and optional model, then returns a summary to the main session. You define them as Markdown files with YAML frontmatter in .claude/agents/ (project-scoped) or ~/.claude/agents/ (user-scoped).

Claude Code subagents vs skills: which should I use?

Use a skill when you want to inject knowledge or procedures into Claude’s context (e.g., “how we write migrations”). Use a subagent when you want a side task handled in an isolated context with its own tools (e.g., “audit the codebase and summarize”). By default, skills don’t get their own context window and subagents do. A skill with context: fork in its frontmatter is the exception: it runs in a forked subagent. You can also list skills in a subagent’s frontmatter to preload them at startup.

How do I invoke a Claude Code subagent?

Three ways, from implicit to explicit: (1) phrase your request so it matches the subagent’s description and let Claude delegate automatically, (2) name it in natural language (“use the pr-reviewer to look at the auth changes”), or (3) @-mention it, which guarantees that subagent runs. For session-wide use, launch Claude with --agent pr-reviewer and the whole session uses that subagent’s prompt and tools.

Can Claude Code subagents run in parallel?

Yes. Claude spawns multiple subagents in a single response when the tasks are independent. That’s the main time-saving feature: three read-only reviewers running in parallel finish in roughly the time of the slowest one, instead of the sum of all three. Subagents can also spawn their own subagents now — up to three layers deep by default — so nested fan-out works too, though orchestrating from the main thread is still the common pattern.

Do Claude Code subagents cost extra tokens?

Each subagent runs its own conversation, so yes, they consume tokens, but often fewer than doing the same work in the main thread, because the main thread doesn’t have to hold all the intermediate search results and file bodies. Setting model: haiku for exploration-heavy subagents is where most of the savings come from. At November 2026 API prices, Haiku 5.5 is 40× cheaper than Opus 5.5 for prompts under 100K tokens, and the four-subagent audit priced above drops from $3.04 to $0.44 with three Haiku explorers and one Sonnet reviewer.

Bottom line

Subagents earn their keep in exactly three places: context preservation on tasks that would otherwise flood the main thread, cost control by routing noisy work to cheaper models, and blast-radius control via tool scoping. Everything else the docs list is downstream of those three.

If you’ve tried Claude Code and felt your main context filling up with stuff you’ll never reread, write two subagents this week: a read-only repo-explorer on Haiku, and a pr-reviewer on Sonnet with memory: project. You’ll know by Friday whether they pay back.