Claude Code subagents are separate agent instances that the main session launches to handle scoped tasks with their own context windows, which keeps the main conversation lean and lets independent work run in parallel. The sub-agents page in the Claude Code docs is the canonical reference. If you have been using Claude Code for any serious engineering work, you have probably hit the moment where a single context window starts to feel like a bottleneck. Subagents are the architectural answer to that problem. This guide covers exactly how they work, when to use them, and the pitfalls that will waste your time if you ignore them.
Key Takeaways
- Claude Code subagents are separate agent instances launched by a main session to handle scoped tasks with their own isolated context windows, keeping the parent conversation lean.
- Delegation can be automatic or explicit. Claude Code decides internally whether to spin up a subagent, but you can also request one directly through your instructions.
- Built-in agent types include general-purpose agents, read-only exploration and search agents, and planning agents. Custom agents are defined in markdown files with their own system prompts and tool configurations.
- Git worktree isolation lets a subagent work on a complete, independent copy of the repository so its changes cannot destabilize your main branch mid-task.
- Parallel subagents are powerful for independent work streams but consume token quota proportionally, so plan accordingly.
- Not every task needs a subagent. Single-fact lookups, small edits, and tasks that need full conversation history should stay in the main session.
What Are Claude Code Subagents and Why Do They Exist

A subagent in Claude Code is a fully independent agent instance that the main orchestrating session can spawn to handle a discrete, bounded task. Each subagent has its own context window, its own tool access, and its own execution scope. When the subagent finishes, it returns a result to the parent session.
The reason this architecture exists comes down to three problems that a single long-running session cannot solve cleanly on its own.
Context isolation is the first. Every token you spend on background explanation, earlier conversation turns, and accumulated file reads is a token not available for the actual task. Subagents start fresh with only the context they need, which means they spend their full context budget on the work at hand.
Parallelism is the second. A single session is sequential. If you have three independent modules to refactor, doing them one at a time in a single session is slower than running three subagents simultaneously. Claude Code subagents allow genuinely concurrent execution across independent work streams.
Specialization is the third. Different tasks benefit from different tool configurations and system prompt instructions. A search agent should be read-only and focused on retrieval. The Claude Code docs cover tool restriction per agent in detail. A code generation agent should have write access and specific style rules. Subagents let you match the agent configuration to the task rather than giving every task the same blunt instrument.
How Claude Code Decides to Delegate vs. You Requesting a Subagent

Claude Code can decide autonomously to spawn a subagent when it recognizes that a portion of the current task is self-contained and would benefit from a clean context. This tends to happen when the task involves a large codebase search, a long-running file analysis, or a verification pass that does not need the full history of your conversation.
You can also request a subagent explicitly. In your instructions, you describe the scope of the subtask, the tools it should use, and the output format you expect back. The more specific your scoping, the more useful the delegation. Vague instructions at the delegation boundary are one of the most common sources of wasted cycles.
The distinction matters because automatic delegation is convenience, while explicit delegation is architecture. When you are designing a complex workflow, you want to think about the delegation boundaries intentionally rather than hoping the model figures it out.
Claude Code hooks let you attach behavior to specific lifecycle events in the agent’s execution, including the moment a subagent is launched or returns a result. Understanding these extension points is worth the time investment before you build anything nontrivial. Pairing delegation with Claude Code plan mode gives you a staged execution map before any file is modified, which significantly reduces the chance of a subagent going off in an unexpected direction mid-task.
Built-In Claude Code Subagent Types
Claude Code ships with several agent types designed for common scenarios. You do not need to configure these from scratch.
The general-purpose agent is the default. It has read and write access to your workspace, can run shell commands, and handles most standard engineering tasks. This is what fires when you delegate without specifying a specialized type.
The read-only explore agent is designed for search, analysis, and codebase mapping. It cannot write files, which makes it safe to run on unfamiliar codebases without worrying about accidental side effects. I use this type when I want to build a map of how a large module is structured before I start touching anything.
The planning agent does not execute changes. It produces structured plans, dependency maps, and task breakdowns. Used together with plan mode, the planning agent maps the work before any execution starts.
These built-in types cover a large share of real-world workflows. The gaps are where custom agents come in.
Custom Claude Code Subagents Defined in Markdown Files

Custom agents are defined in markdown files that specify a system prompt, a tool list, and any constraints you want to enforce for that agent’s scope. This is analogous to how the CLAUDE.md file stores persistent memory and workflow rules for your main session, except that a custom agent definition is targeted at a single role rather than the entire workspace.
A typical custom agent file might define a security review agent that has read access to your codebase, a specific checklist to evaluate against, and instructions to output findings in a structured format. Another might define a documentation agent that knows your project’s terminology, tone, and output conventions without needing to re-read those rules from the main context every time.
The markdown-based definition format is deliberately simple. You write a system prompt the same way you would write any other instruction to Claude, then list the tools the agent is allowed to use. Claude Code reads the file and instantiates the agent with those constraints applied. This pairs naturally with plugins, which package repeatable functionality that multiple agents can call. The full guide to Claude plugins covers how to structure these packages so agents can consume them cleanly.
MCP servers are another layer worth knowing here. MCP connections let subagents pull live data from external sources, such as a database, an API, or a monitoring system, directly into the agent’s context without routing the data through your main session. The MCP servers guide covers the setup patterns in detail. When you combine a focused custom agent definition with the right MCP servers attached, the agent can perform genuinely self-contained research or data analysis tasks without ever burdening your main conversation.
Isolation Modes and Git Worktree Isolation

The most consequential isolation decision with Claude Code subagents is whether to run the agent in git worktree isolation.
Without isolation, a subagent operates on the same working directory as your main session. This is fine for read-only tasks and for small, clearly scoped writes. It becomes risky when the agent is doing anything that touches multiple files, because an error in the subagent’s execution can leave your working tree in a partial state that affects everything else.
With git worktree isolation, Claude Code creates a separate checkout of the repository for the subagent to operate on. The subagent makes all of its changes in that isolated copy. When it completes, the results can be reviewed and merged back, or discarded cleanly without any trace on your main branch. This is the mode I reach for whenever a subagent’s task is nontrivial or involves coordinated changes across multiple files.
The practical benefit is that you can run several subagents in parallel, each on its own worktree, without any risk of them interfering with each other or with your main session. The tradeoff is disk space and slightly more coordination overhead when merging results. For most engineering workflows, that tradeoff is obvious.
Running Multiple Claude Code Subagents in Parallel

Parallel execution is where Claude Code subagents deliver their most dramatic value, and where the most expensive mistakes happen.
The right candidates for parallel subagents are tasks that are genuinely independent. If task B depends on the output of task A, they cannot run in parallel. This sounds obvious, but dependency analysis at the task level is something practitioners consistently underestimate when they are excited about the throughput gains.
Good parallel candidates include searching multiple directories for usage patterns simultaneously, running verification passes on separate modules that do not share state, generating documentation for independent components, and performing research across multiple external sources via MCP servers. Running these in parallel compresses wall-clock time significantly.
Token consumption scales with the number of parallel agents. Ten concurrent subagents consume your quota at roughly ten times the rate of a single session. For teams evaluating whether to authorize parallel subagent use broadly, that math needs to factor into the decision. The agentic execution model is a genuine differentiator for Claude Code, but the cost profile is different from tools that rely on single-turn completions. The Claude Code vs Cursor comparison is a useful starting point if you are working through that evaluation.
When NOT to Use Claude Code Subagents
Subagents are not the right tool for every job, and forcing them into the wrong situations costs you more than it saves.
Single-fact lookups do not benefit from delegation. If you need to know whether a function exists in a file, asking your main session is faster than launching a subagent, waiting for it to initialize, and parsing its response.
Small, focused edits are the same story. A one-line change to a config file should stay in the main session. The overhead of subagent setup is not justified by the task size.
Tasks that need full conversation history cannot be delegated cleanly. A subagent starts with a fresh context window. If the task requires understanding a long back-and-forth about architecture decisions you made earlier in the session, the subagent will not have that history unless you explicitly summarize and pass it. That summarization step is sometimes worth it, but it is work you need to account for.
Practical Examples of Claude Code Subagents in Action

Here are three scenarios where the architecture earns its place.
Parallel codebase searches. You need to find every place in a large monorepo where a deprecated API is called. Instead of running a single sequential search agent, you launch four read-only explore agents in parallel, each assigned a quarter of the directory tree. They return their findings simultaneously and the main session assembles the full list in a fraction of the time a single sequential pass would take.
Delegated research. You are building a feature that requires understanding three external libraries. You delegate one research agent per library, each equipped with the relevant MCP server connections to pull documentation and examples. While you continue planning in the main session, the agents gather and summarize the information you need.
Verification passes. After implementing a feature, you launch a dedicated verification subagent with a read-only configuration and a checklist of things to confirm: test coverage, type annotations, documentation strings, and API contract compliance. This agent produces a structured report without modifying any files. The separation between the agent that writes code and the agent that verifies it reduces the chance that the same blind spots apply to both.
Common Pitfalls with Claude Code Subagents
Delegating then redoing the work yourself. This happens when the delegation boundary is unclear and the subagent returns something that does not quite fit, so you end up fixing it manually in the main session. The fix is tighter scoping upfront, not looser delegation in hopes the agent figures it out.
Over-parallelizing dependent tasks. Launching five subagents simultaneously where the second depends on the output of the first is not parallel execution. It is just five agents starting at the same time and four of them waiting or failing. Map your dependencies before you decide what can run in parallel. If you’d rather see this in practice, here is honest comparisons from real client work.
Losing results because the subagent’s final message is not relayed. A subagent’s output only reaches you if the main session explicitly captures and surfaces it. If you delegate and then do not instruct the parent session on how to handle the return value, that output can silently disappear. Always define the expected output format and the relay mechanism when you set up the delegation. This is a quiet, frustrating bug that is easy to miss the first few times it happens.
Claude Code hooks are one way to make the relay reliable. By attaching a hook to the subagent completion event, you ensure the result is processed and stored in a predictable location regardless of what else is happening in the parent session.
If you want to see how these architectural choices compare across tooling philosophies, the Claude Code vs Codex comparison breaks down where each tool makes different tradeoffs on context management and agent control.
Conclusion
Claude Code subagents give you a concrete mechanism for scaling what a single coding session can accomplish: isolated context windows, parallel execution across independent tasks, specialized agent types, and git-level isolation that keeps your working tree clean. Understanding the architecture is the prerequisite, and this guide has covered the core of it.
But there is a gap between reading about subagents and actually restructuring your workflow around them. The practitioners who get the most from this system are the ones who treat the delegation boundary as a design decision, not an afterthought. They define their custom agents carefully, map dependencies before parallelizing, and verify that results are actually being relayed. If you want structured, hands-on training on building these workflows rather than assembling them from scattered docs, the free Learn Claude guides at Strategized.ai teach the configuration patterns step by step.
Reading about parallel agents is easy. Delegating real work to them, with clear scoping and reliable result capture, is the actual skill. That is where the time investment pays off.
If your subagents stall, rule out a platform outage first and check Claude’s status.
Give Claude your business in twenty minutes
The free Foundation Plugin from Strategized.ai interviews you and writes the Business Blueprint every Claude conversation starts from. No account, no card.
Get the Foundation Plugin →Free. Sent to your email.
Frequently Asked Questions
What exactly are Claude Code subagents and how do they differ from a regular Claude Code session?
Claude Code subagents are separate agent instances that the main session can spawn to handle a bounded task with their own independent context window. Unlike a regular session where everything runs sequentially in one shared context, subagents operate in isolation and return results to the parent, keeping the main conversation focused and lean.
Can I run Claude Code subagents in parallel, and how many at once?
Yes, you can run multiple Claude Code subagents simultaneously as long as the tasks are genuinely independent of each other. The practical limit depends on your token quota and task complexity, since each parallel agent consumes quota at its own rate, so capacity planning matters.
How does git worktree isolation work for subagents in Claude Code?
Git worktree isolation creates a separate checkout of the repository for a subagent to work in, so its changes do not affect your main working directory while it runs. When the agent finishes, you review and merge its output or discard it cleanly. This is the recommended mode for any subagent making coordinated changes across multiple files.
What is the difference between a built-in Claude Code subagent type and a custom agent?
Built-in types like the read-only explore agent or planning agent come preconfigured for common scenarios and require no setup. Custom agents are defined in markdown files where you write a system prompt and specify tool access, giving you a specialized agent tuned to your project’s specific requirements and conventions.
Why would a Claude Code subagent lose its results and how do I prevent it?
A subagent’s output only reaches your main session if the parent is explicitly configured to capture and surface it. If you do not define the return format and relay mechanism when setting up the delegation, the result can disappear silently. Using Claude Code hooks on the subagent completion event is a reliable way to ensure results are always captured and stored predictably.
Is Claude Code subagent support better than what you get in Cursor?
Claude Code and Cursor take different architectural approaches, and the subagent model is specific to Claude Code’s agentic execution environment. Claude Code subagents offer deep configurability through markdown definitions, MCP server connections, and git worktree isolation that Cursor’s architecture does not replicate in the same way. The full comparison is worth reading if you are choosing between the two for a team workflow.
What are the most common mistakes practitioners make with Claude Code subagents?
The three most consistent mistakes are delegating with unclear scoping and then manually redoing the work, over-parallelizing tasks that actually have dependencies, and failing to define how subagent results should be relayed back to the main session. All three are avoidable with upfront design of your delegation boundaries before you start launching agents.
Related reading: Claude Agents Explained: Code Agents vs Claude Subagents.
See also: What Is Claude CLI? Code, Claude, and the Command Line.



