Claude Code subagents: when to use them and how to build one
When a Claude Code subagent beats a skill or slash command, how to write one as a Markdown file, and the rules that stop agents flooding your context.
Short answer
A subagent is a second Claude worker that gets one task, a fresh context window, instructions written for that role and a limited set of tools. It does the heavy reading elsewhere and sends back only the answer. My shorthand: a skill changes what Claude knows, a subagent takes work off its plate.
Key takeaways
- The real job of a subagent is guarding your main context. It absorbs the long reads so your session only receives the conclusion.
- Skills give Claude knowledge, subagents take work away. Custom slash commands now live inside skills, and both run in the conversation you're already in.
- You define a subagent as a Markdown file with YAML frontmatter, saved in .claude/agents/ for a project or ~/.claude/agents/ for yourself. It needs just a name and a description.
- One task per subagent, and only the tools that task requires. Start read-only and add write access when a job truly calls for it.
- Every extra subagent burns its own tokens and drops another report into your main thread. A few at a time beats twenty.
I see people get Claude Code subagents wrong in two opposite ways. Some never touch them. Others launch ten in one go, then scroll through ten reports their main session had no use for.
Neither works. The official documentation covers what a subagent is. It says much less about when one is the right tool, how it stacks up against skills and slash commands, and what goes wrong once you run a lot of them. I picked those lessons up while building agents for companies over the past two years, usually by making the mistake first.
This guide is the hands-on version. The concept, the comparison, how to write your own, the three setups I rely on, and what they cost you.
So what is a subagent, really?
Picture a second Claude that your main session can hand one task to. It gets a fresh context window, a system prompt written for that role, a set of tools, and permissions that can be tighter than yours. It works through the task, sends a single result back, and is gone.
The value sits in what you don't see. Say the job needs ten files opened and five searches run. All of that reading, and all the tokens it eats, happens on the subagent's side. Your conversation receives the conclusion and nothing else.
It's how you'd brief a good junior colleague. You don't want to be copied on every message they send while they figure it out. You want a short note at the end that says what they found.
Chances are you've already used a few. Claude Code comes with built-in subagents:
- Explore: quick and read-only. Claude sends it off to search a codebase and make sense of it.
- Plan: gathers context for Claude while you're in plan mode.
- General-purpose: for multi-step work that involves both reading and making changes.
Whenever Claude hands work to one of them, the raw search output stays out of your conversation.
Subagent, skill or slash command: which one fits?
People ask me this more than anything else about Claude Code. Here's the side-by-side.
| What you get | Separate context? | Use it for | |
|---|---|---|---|
| Slash command | A stored prompt. Type /name and it turns into instructions inside the conversation you're in. |
No | Prompts you repeat a lot, and actions where you decide the timing |
| Skill | A SKILL.md file, optionally with supporting files. Claude pulls it in when a task matches, or you call it with /skill-name. |
Not by default. It loads into your current conversation. | Showing Claude how you do things: your process, conventions and checklists |
| Subagent | A standalone Claude worker defined in .claude/agents/, with a prompt, tool list and model of its own. |
Yes | Handing work off: research, combing through logs, reviews, parallel jobs |
A detail that trips people up: recent Claude Code versions folded custom slash commands into skills. .claude/commands/deploy.md and .claude/skills/deploy/SKILL.md both give you a /deploy command. So the useful distinction isn't command versus skill anymore. It's whether the work happens inside your conversation or somewhere else.
My shorthand: skill = know, subagent = offload. If Claude needs to know your way of doing something, write a skill. If Claude needs to offload a chunk of work, make a subagent.
You don't have to pick one. A subagent can call your skills mid-task, and you can preload particular skills into it. Knowledge and isolation get along fine.
When should work leave your main session?
Hand a task to a subagent when it looks like one of these:
- Lots of input, small output. Combing through log files. Hunting for one pattern across twenty files. Running the full test suite when the failures are all you care about.
- You need guardrails. Lock a subagent to read-only tools and it can't change anything, even when it loses the plot.
- It's self-contained. You can explain the task in a paragraph, and the answer fits in a short report.
Keep it in the main conversation when:
- the task needs a lot of back-and-forth with you
- planning, building and testing all lean on the same context
- it's a small, targeted edit
Every subagent boots up knowing nothing. On a two-line fix, that startup time is wasted.
How do you build your own subagent?
Nothing special required. A subagent is a Markdown file that opens with YAML frontmatter. The frontmatter covers identity and permissions. Everything underneath becomes the system prompt.
The folder you save it in decides who can use it:
| Location | Scope |
|---|---|
.claude/agents/ in your repo |
Project. Commit it and everyone on the team gets the same subagent. |
~/.claude/agents/ in your home folder |
Personal. Works in every project on your machine. |
name and description are the only required fields. Two more show up in nearly all of mine: tools, which lists what it may use, and model, which takes sonnet, opus, haiku, or inherit to match whatever your main session runs. Skip tools and the subagent inherits every tool available to subagents. Handy, sure. For most jobs it's also the opposite of what I want.
You can create one in two ways. Ask Claude to write it for you ("Create a read-only research subagent in ~/.claude/agents/ that..."), or write the file by hand. In older versions, /agents opened an interactive wizard. Newer versions just point you to those two routes. The file format didn't change.
This is the read-only researcher I reach for more than any other:
---
name: research-scout
description: Read-only investigator. Call it when a question requires going through many files or docs but the answer itself is short. It never modifies anything.
tools: Read, Grep, Glob, WebFetch, WebSearch
model: sonnet
---
You investigate a single question and report what you find.
Rules:
- Read only. Do not create, change or remove any file.
- Answer the question as asked. Ignore tangents, however tempting.
- Reply with no more than 10 bullet points. Cite the file path or URL behind each one.
- Close with one line naming anything you were unable to confirm.
Drop it into .claude/agents/research-scout.md and Claude can start delegating to it. One gotcha: if there was no agents folder when your session began, restart Claude Code once so it notices the new folder. Want quick, inexpensive digging? Change the model to haiku.
The description decides when it gets called
Claude picks a subagent by reading its description. Make it fuzzy and the subagent sits unused. Make it too eager and it grabs every task in sight. Write it the way you'd brief a contractor: these jobs are yours, those aren't.
Keep it brief as well. Every description stays loaded in your context so Claude knows what's on offer. The long instructions go in the body, which only loads when the subagent actually runs.
Don't want to depend on Claude choosing? Name the subagent in your prompt ("Use the research-scout subagent to map the auth flow"). Or @-mention it, which makes sure that exact subagent runs.
Hand out as few tools as possible
tools works as an allowlist. My research subagent gets reading and searching, and nothing that writes. If it's easier to start from the full set and strip a few out, disallowedTools does the reverse and acts as a denylist.
Nobody gives a new hire the keys to production in their first week. Subagents get the same treatment.
Where do subagents actually pay off?
Enough concepts. These are the three setups I use most.
1. Research in parallel. When I have to get up to speed on a codebase or a subject quickly, I launch a few read-only subagents side by side, each with its own slice. One traces how login works. Another sketches the database. A third goes through the tests. They all run simultaneously, and a few tight summaries come back in place of one long crawl. Nothing else saves me as much time.
2. A tidy main thread. Any job that means reading a mountain to produce a paragraph gets delegated. That keeps the main session on the decision in front of it, not wading through raw output. The longer a session runs, the more this counts, since every log dump you keep out leaves room for the real work.
3. Checking the work adversarially. When something matters, I start a subagent with a single brief: find what's wrong with the first answer. It never saw the original context, so it can't inherit the same blind spot. A second opinion doesn't come cheaper.
What's the catch?
Subagents cost something. Know the trade-offs before you design a workflow around them.
| Cost | What happens | What to do about it |
|---|---|---|
| Tokens | Each subagent makes its own requests, drawn from the same usage limits as your main session. Five researchers means paying for five explorations. | Delegate only work that's worth it. Use haiku for cheap digging. |
| Lost context at handoff | The subagent can't see your conversation. It only has its own system prompt, the task message Claude writes for it, and your CLAUDE.md files. | Put anything that matters in the delegation prompt ("skip the vendor/ folder", "the cache is already ruled out"), or it will rediscover what you know. |
| Coordination | Every result flows back into your main conversation. Ten long reports can fill your context as fast as the raw files would have, and you still have to read and reconcile them. | Ask for short, structured returns. |
| Latency | A subagent starts cold and needs a moment to orient itself. | For small, quick jobs, stay in the main thread. It's faster. |
None of this argues against subagents. It argues for giving them only the jobs where working in isolation earns back what it costs.
How many subagents should run at once?
Fewer than you'd guess. These are the rules I ended up with after breaking each of them:
- Each subagent gets one job. Give it two and the output turns mushy. Make it two subagents instead.
- Hold back on parallel runs. A handful at the same time works well. By default Claude Code lets 20 run at once, but reading twenty summaries is a mess of its own. Treat that number as a ceiling, never a goal. Size the batch to the task, not to how fun it is to watch them all spin up.
- Spell out the return format. Say exactly what you expect: bullets, a table, a yes or no with the evidence. A tighter handoff gives you a more usable result.
- Write access is opt-in. Every subagent starts read-only. Add write tools only for tasks that really have to change files.
What should you remember?
A subagent won't make Claude any smarter. It keeps your main context clean and lets you run several pieces of work side by side. That's it, and that's plenty.
So keep the split in mind. Skills hold what Claude should know. Subagents take the work Claude should send away and get a short answer back on. Get that right and your sessions stop collapsing under their own output. That's what turns a setup that impresses in a demo into one that holds up on a normal Tuesday.
Frequently asked questions
What is the difference between a subagent and a skill in Claude Code?
A skill is a bundle of instructions and reference files that Claude pulls into the conversation you're in when a task calls for it, so it shapes how Claude works right there. A subagent is a separate Claude instance with a context window, tools and permissions of its own. It finishes a task elsewhere and sends back only the outcome. Skills bring knowledge. Subagents bring isolation and parallel work.
Where are Claude Code subagents stored?
In two places. Put them in .claude/agents/ inside the repository to commit them and share them with your team, or in ~/.claude/agents/ to have them in every project on your own machine. When a project subagent and a personal one have the same name, Claude Code uses the project version.
Do Claude Code subagents use more tokens?
Yes. A subagent makes its own requests, and they draw from the same usage limits as your main session. Whatever it returns also lands in your main context, so a pile of long reports eats space there as well. Setting the model field to a cheaper option such as Haiku keeps the bill down.
Does a subagent see my conversation history?
No. A standard subagent begins with an empty context window that holds its system prompt, the task message Claude writes when handing off, and your CLAUDE.md files. Earlier messages and files Claude already opened are invisible to it, so put every rule that matters for the task into the delegation prompt.
Can a Claude Code subagent use my skills and MCP tools?
Yes. Unless you narrow things down with the tools or disallowedTools fields, a subagent inherits most of the tools from your main session, MCP tools included. It can call your skills during its work, and the skills field in its frontmatter lets you preload specific ones.
The build log · newsletter
Steal my automations.
One agent I built, the workflow behind it and the tools that made it work. Copy, paste, ship.
10,000+ builders already subscribed. Free.
A shorter version of this piece first went out to newsletter readers.
- /16 jan 2026
How I Run My Business With Claude Code: The 5 Jobs It Handles
I use Claude Code as an AI employee with memory: tasks, calendar, email, n8n workflows and sales. What it does, what changed, what it costs, how to start.
- /30 sep 2026
How to Find the Warm Prospects Already in Your LinkedIn Network
I ran 25,033 LinkedIn connections through an AI ICP check in 71 seconds for under $1 and found 435 warm prospects. The process, criteria and mistakes.
- /1 sep 2026
How to Choose Which Process to Automate First With AI
Flashy AI pilots stall. Score candidates on three questions (how often, how clear, how gladly handed off) and start with the process that will really run.
