Modern Code Consulting

Claude Code

Claude Code Subagents: Setup, Config and When to Use

Claude Code subagents explained: where the files go, the frontmatter that matters, which model runs, a recorded parallel example and mistakes we would avoid.

By
Published

Last verified

Claude Code subagents are separate workers that your main session delegates a task to. Each one gets its own context window, instructions and tool access, then sends back a result. Use them when a side task would bury your conversation in search results and logs, or when a batch splits into pieces that don't depend on each other.

We use them in our own builds for batch judgment work. If you want them designed around your team's repeat jobs, that's part of our Claude Code setup and consulting.

When to use a Claude Code subagent

The test we use: do you need the work, or only the answer? If Claude has to read 30 files to tell you where a webhook is validated, you want the file path and a short explanation. The reading can stay in a subagent's context.

JobWhat we'd useWhy
Searching a codebase for one answerSubagentOnly the conclusion needs to come back
Cleaning a list in independent chunksOne subagent per chunkNo chunk needs another chunk's result
Merging rows or doing mathA scriptThe output has to be exact every run
A written procedure you repeatA skillIt loads instructions into the work when needed
A rule that must run every timeA hookThe harness runs it, so the model can't forget
A small edit you're steering turn by turnThe main sessionA handoff would drop context you already built

These pieces combine. A Claude Code skill can tell the main session when to launch subagents and what to hand each one. A Claude Code hook covers the checks you don't want left to judgment.

How to create a subagent: an example file

A subagent is a Markdown file. The frontmatter configures it and the body is its system prompt. Here's an example reviewer you could save as .claude/agents/webhook-reviewer.md:

---
name: webhook-reviewer
description: Reviews webhook handlers. Use after any change to a file that receives a webhook.
tools: Read, Grep, Glob
model: sonnet
---

You review webhook handlers. You do not edit files.

For each handler, check:
1. The signature is verified before the body is trusted.
2. A repeated delivery of the same event is ignored.
3. A failed step is reported, with the reason.

Return one line per problem: file path, line number, what breaks.
If you find none, say so and list the files you read.

The description matters more than it looks, because Claude reads it to decide when to delegate. "Helps with code" gives it nothing to match on. Name the trigger.

The tools line is your guardrail. Leave it out and the subagent inherits every tool that subagents can use. A reviewer with only Read, Grep and Glob has no edit or shell tool, whatever its prompt says.

The last two lines of the prompt set the return format. The main session mostly works from what comes back, so ask for the shape you want. We also ask for the list of files read, so an empty result doesn't look the same as a skipped job.

How to run a subagent

You can let Claude delegate on its own, or ask by name: "Use the webhook-reviewer agent on the files I changed." To pick one explicitly, type @ and choose it from the typeahead.

@"webhook-reviewer (agent)" look at the payment handler

To run a whole session as that agent, start it with claude --agent webhook-reviewer. For a definition you don't want saved to disk, pass JSON with --agents, where the prompt key replaces the Markdown body.

claude --agents '{
  "webhook-reviewer": {
    "description": "Reviews webhook handlers after changes.",
    "prompt": "You review webhook handlers. You do not edit files.",
    "tools": ["Read", "Grep", "Glob"],
    "model": "sonnet"
  }
}'

Claude Code subagent settings, as of November 26, 2026

We checked these against Anthropic's subagents documentation on the date above. We didn't re-run each behavior ourselves.

Where the files go

When two subagents share a name, the higher location in this list wins:

  1. Managed settings, set across an organization
  2. The --agents flag, for the current session only
  3. .claude/agents/ in the project
  4. ~/.claude/agents/ for all your projects
  5. A plugin's agents/ directory

Both .claude/agents/ folders are scanned recursively, and identity comes from the name field, not the file path. On current versions, /agents prints a reminder to ask Claude or edit those folders. The docs say v2.1.197 and earlier opened a wizard, so older tutorials may show screens you won't see.

Frontmatter fields worth knowing

Only name and description are required. Claude Code ignores a field it doesn't recognize without reporting an error, so check your spelling and camelCase.

  • tools and disallowedTools: allow or remove tools. A scoped entry in disallowedTools, such as Bash(git push *), still removes the whole Bash tool.
  • model: sonnet, opus, haiku, fable, a full model ID or inherit.
  • maxTurns: caps how many agentic turns it can take.
  • skills: preloads the full content of the skills you list.
  • memory: user, project or local.
  • isolation: worktree: gives it a temporary git worktree, branched from the default branch unless you configure otherwise. Don't expect it to see the work on your current branch.
  • omitClaudeMd: starts it without your user, project and local CLAUDE.md files (v2.1.271 and later).
  • mcpServers, hooks and permissionMode: all three are ignored for subagents that come from a plugin.

Which model runs

The first of these that applies wins:

  1. The model Claude passes on that specific call
  2. The model field in the subagent file
  3. The CLAUDE_CODE_SUBAGENT_MODEL environment variable
  4. The main conversation's model, or the parent subagent's when nested

Permissions, background runs and naming

A subagent with no permissionMode inherits the main conversation's mode. If the main session is in bypassPermissions, acceptEdits or auto mode, the subagent runs in that mode and the field in its file is ignored. If the main session is in plan mode, the subagent stays in plan mode. A strict permissionMode line won't protect you from a loose parent, so restrict tools too.

Custom subagents spawned from the main conversation start in the background by default. The tool that launches them is called Agent. It was named Task before version 2.1.63, and the docs say existing Task(...) references still work as aliases. To stop all delegation, add Agent to permissions.deny.

Nesting and concurrency limits also apply. We couldn't confirm the current numbers word for word today, so check the docs page before you design around them.

What a subagent knows when it starts

A regular subagent gets its own system prompt and basic environment details such as the working directory. It doesn't get the full Claude Code system prompt or your conversation history. The built-in Explore and Plan agents also skip your CLAUDE.md files and the git status snapshot. Forks are the exception on history, since they carry the conversation over.

So brief it like someone who just walked in. Give it the goal, the exact paths, what you've already ruled out and what to return. If a rule lives only in something you said 40 messages ago, a regular subagent won't know it. If your delegation relies on Explore, repeat any CLAUDE.md rule that matters in the task message.

A working example: parallel subagents on a lead list

Our lead list personalization automation is a recorded run on a 40-row scraped CSV for an invented HVAC software company. The names are messy on purpose: legal suffixes, all-caps companies and trailing locations.

  1. A Python script splits the list into two files of 20 rows. Each line holds only a row number, first name and company name.
  2. Two subagents launch in the same message, one per file. Each returns JSON with a casual first name and a company name a person would say. The agent runner reported 12.5 and 15.2 seconds.
  3. A script merges the JSON back onto the rows and renders the opener. The merge fails loudly and lists any missing row numbers, so only that chunk's agent needs a rerun.
  4. The skill checks for rows that shouldn't send. The run ended with 36 send-ready rows and 4 held out.

Back to back, those two durations would add up to about 27.7 seconds. At this size the saved time hardly matters. On a real list of about 900 rows, the same recording notes seven agents and roughly three minutes.

The part we'd copy into any build is the split of duties. Subagents make the judgment calls, such as what people would call a company. Code handles chunking and merging, where a plausible guess is a bug. In that recorded run the Google Sheet staging step and the homepage scan weren't run, and the page says so.

Subagents vs agent teams

With subagents, the main agent manages the work and results flow back to it. In an agent team, teammates can message each other directly and coordinate through a shared task list. As of November 26, 2026, teams are experimental, off by default and enabled with CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1.

We'd start with subagents. Move to a team only when the workers need to challenge or build on each other's findings while the job is still running.

What subagents cost

Delegating can keep your main context smaller, but it isn't free. Every subagent sends its own requests on top of the main conversation's, and those draw on your usage. The cost documentation suggests model: haiku for simple subagent tasks, and /usage shows the share that subagents account for.

As of November 26, 2026, that page says agent teams use approximately 7x more tokens than standard sessions when teammates run in plan mode. It gives no equivalent multiplier for ordinary subagents, so we won't guess one. Run your job on a small sample, check /usage, then decide how wide to go.

Subagent mistakes we'd avoid

  • Splitting work that has an order. If step two needs step one's output, parallel the second agent has to guess it.
  • Letting two agents edit the same files. Give each its own files or use worktree isolation, and plan how the changes get merged.
  • Trusting a summary you can't check. Ask for file paths, line numbers or row counts, then spot-check them.
  • Writing five vague agents. One with a clear trigger and return format is easier to test, and Claude has less to confuse it with.

What we'd do first

Pick one task that keeps filling your context, such as log reading or code review. Write one project subagent with a specific description, read-only tools and a fixed return format. Run it on work where you already know the answer, and tighten the prompt wherever it misses.

Commit the file once it earns its place, so your team gets the same worker. If you're planning several agents plus skills, hooks and tool connections, our Claude Code consulting service covers that setup around your own jobs.

Frequently asked questions

What are Claude Code subagents?
Claude Code subagents are separate workers that the main session hands a task to, each with its own context window, system prompt and tool access. The subagent does the work and returns a result to the conversation that called it. A custom one is a Markdown file with YAML frontmatter, and Claude Code also ships built-in ones such as Explore, Plan and general-purpose.
How do I create a subagent in Claude Code?
Create a Markdown file in .claude/agents/ for one project or ~/.claude/agents/ for all of your projects. Only name and description are required in the frontmatter, and the text below it becomes the subagent system prompt. You can also ask Claude to write the file for you, or pass definitions for a single session with the --agents flag.
Which model does a Claude Code subagent use?
It depends on the first setting that applies: the model Claude passes on that particular call, then the model field in the subagent file, then the CLAUDE_CODE_SUBAGENT_MODEL environment variable, then the main conversation model. A model field in the file therefore beats the environment variable in a normal setup. The docs describe a separate force setting if you need one model on every subagent.
Do subagents see my conversation history?
A regular subagent does not start with your conversation history, so anything it needs has to be in the task message, its own instructions or files it can read. Custom subagents can still load your CLAUDE.md files, while the built-in Explore and Plan agents start without them. Forks are a separate variant that carries the conversation over.
Are subagents the same as agent teams?
No, they are different features. Subagents report back to the agent that called them, while teammates in an agent team are independent sessions that can message each other and share a task list. As of November 26, 2026 the docs describe agent teams as experimental and disabled by default.

Want this built for your business?

Book a free 15-minute call. Tell us what's eating your team's hours and we'll tell you what we'd automate first, how we'd build it and what it would cost.

Book a free automation audit