Claude Code subagents: how to create and use them

What Claude Code subagents are, how to write one in .claude/agents, what the tools and model fields do, and when separate parallel agents are the better choice.

Solviera Teknoloji 9 min read

Claude Code subagents are helpers that the main Claude Code session hands a single task to. Each one runs in its own context window, with its own system prompt, tool list and model, and only its final answer comes back to the main conversation. You define a subagent as a Markdown file in .claude/agents/, and Claude uses it automatically when the task matches its description, or when you ask for it by name.

This post covers how subagents work, the file format, the tools and model fields, how to call them, and the line between a subagent and a separate agent running next to the first one. Facts come from the official subagents docs. For the one-paragraph version, see the subagent glossary entry.

How subagents work

When Claude decides to delegate, it calls the Agent tool (called Task before version 2.1.63) with a short brief. The subagent starts with a fresh context. It gets its own system prompt, the delegation message, your CLAUDE.md, the git status and any skills you preloaded for it. It does not see the main conversation history.

It then works through the task with its allowed tools and returns one result. Everything it read along the way, such as dozens of files, long grep output or test logs, stays in its own context. That is the main reason to use subagents: the main conversation gets a summary, not the noise.

A few limits worth knowing:

  • Subagents can start their own subagents, up to three layers deep by default.
  • Up to 20 can run at once by default.
  • Their requests count toward the same usage limits as the main session.
  • A subagent can run in the foreground, where the main agent waits, or in the background while the main agent keeps going.

Built-in subagents

Claude Code ships a few subagents you can use without writing anything:

SubagentToolsTypical use
ExploreRead onlySearching and reading across the codebase, at quick, medium or very thorough depth
PlanRead onlyResearch while in plan mode
General-purposeAll toolsMulti-step tasks that need both research and changes

Explore is the one you will see most. When Claude needs to find where something is defined or how a feature works across files, it often hands that to Explore so the file dumps don’t land in your main context.

Where subagent files live

Subagents are Markdown files with YAML frontmatter. Claude Code loads them from several places, and when two have the same name, the higher one in this list wins:

LocationScope
Managed settingsOrganization-wide, set by admins
--agents flag (JSON)One session
.claude/agents/One project, shared through git
~/.claude/agents/All your projects
A plugin’s agents/ folderWherever the plugin is installed

Project subagents in .claude/agents/ are the ones to commit, so the whole team shares the same reviewer or test runner.

The subagent file format

Only name and description are required. The body after the frontmatter is the subagent’s system prompt.

---
name: code-reviewer
description: Reviews code changes for bugs, security issues and readability. Use after writing or changing code.
tools: Read, Grep, Glob, Bash
model: sonnet
---

You are a senior code reviewer. When called:

1. Run git diff to see the recent changes.
2. Read the changed files and the code around them.
3. Report problems by priority: bugs, security, then readability.
4. For each problem, give the file, the line and a concrete fix.

Do not edit files. Report only.

The description matters more than it looks. It is what Claude reads when deciding whether to delegate, so say what the subagent does and when to use it. Phrases like “use after writing code” help Claude pick it up on its own.

The tools field

tools is an allowlist. With tools: Read, Grep, Glob, Bash, the reviewer above can read and run commands but cannot edit files. If you leave tools out, the subagent inherits every tool the main session has, including MCP tools. There is also disallowedTools when it is easier to say what to remove than what to keep.

Keep the list as short as the job allows. A reviewer does not need Edit. A researcher does not need Bash. Fewer tools means fewer surprises and a clearer job.

The model field

model accepts an alias (sonnet, opus, haiku), a full model ID, or inherit to use the main session’s model. When the subagent is called, Claude Code picks the model in this order: a model passed with that call, then the file’s model field, then the CLAUDE_CODE_SUBAGENT_MODEL environment variable, then the main session’s model.

This is where subagents can save real money. Broad file searches and log reading rarely need the strongest model. Put them on Haiku and keep the main session on the bigger model for the decisions. The Claude Code token usage post covers more ways to cut spend.

Other useful fields

FieldWhat it does
permissionModePermission mode for the subagent, for example plan or acceptEdits
skillsSkills to load into the subagent’s context at start
mcpServersMCP servers the subagent can use
hooksHooks that apply while this subagent runs
memoryPersistent memory at user, project or local scope
maxTurnsUpper limit on the subagent’s turns
backgroundRun in the background by default
isolation: worktreeRun in a temporary git worktree
effortReasoning effort for the subagent

How to call a subagent

There are three ways:

  1. Let Claude decide. If the request matches a subagent’s description, Claude delegates on its own.
  2. Ask by name. “Use the code-reviewer subagent to check my last commit.” You can also @-mention it from the menu.
  3. Run a whole session as one. claude --agent code-reviewer starts a session that uses that subagent’s prompt, tools and model.

For a one-off session you can pass subagents as JSON without creating files:

claude --agents '{
  "code-reviewer": {
    "description": "Reviews code changes. Use after edits.",
    "prompt": "You are a senior code reviewer. Report bugs and fixes, do not edit.",
    "tools": ["Read", "Grep", "Glob", "Bash"],
    "model": "sonnet"
  }
}'

To stop Claude from using a particular subagent, add it to the deny list in your permissions, for example Agent(Explore).

Subagents vs separate parallel agents

Subagents and parallel agents both split work, but they solve different problems.

SubagentsSeparate parallel agents
Who starts themThe main Claude sessionYou
What you seeThe final result, inside the main chatEach agent’s full session
ContextFresh per task, discarded afterLong-lived, one per agent
FilesSame working folder unless isolation: worktreeUsually one git worktree each
Your input mid-taskNone, the main agent talks to itYou can steer each one
Good forSearch, review, research, short focused jobsFeatures, refactors, long tasks that end in a branch

Use a subagent when the main agent needs an answer to keep going: “find every caller of this function”, “review this diff”, “summarize these logs”. The work is short, its result is what matters, and you don’t need to watch it.

Use separate agents when each piece is real work on its own: a feature, a migration, a test suite. You want to see what each one is doing, answer its questions, and review its changes as a branch. That is the setup described in parallel coding agents and running multiple Claude Code agents, with each agent in its own git worktree.

The two mix well. A separate agent can still use subagents for its own searches and reviews. A good default is separate agents for the work you would assign to a person, and subagents for the errands those agents run. For larger teams, the AI agent team post covers roles and hand-offs, and the multi-agent orchestration entry covers the general idea.

Claude Code also has a separate feature called agent teams, where several Claude sessions work together. That is not the same as subagents and is outside this post.

Tips for subagents that work

  • One job per subagent. “Reviewer” and “test runner” work better than “helper”.
  • Write the description for Claude. Say when to use it, not just what it is.
  • Limit tools. Read-only subagents for research and review, edit tools only where needed.
  • Pick the model on purpose. Haiku for search and summaries, a stronger model for design and tricky fixes.
  • Ask for a short report. The result goes into the main context, so tell the subagent to return findings, not file dumps.
  • Check in your project subagents. .claude/agents/ in git means everyone gets the same helpers.

How AgentVera shows subagents

AgentVera is a desktop app for running many coding agents, Claude Code, Codex and others, side by side. It handles subagents in two ways.

You can see them. In a Claude Code agent’s pane, the “Subagents” button opens a live view of the subagents that agent started and what they are doing now. Each one shows its status (Running, Done, Error, Stopped), whether it runs “in background”, the “Assigned task” it got and its “Report”. While some are working, a “{count} subagents running — show” line appears so you don’t miss them. The project tour and code map also has a subagents timeline with type, status, tool count and duration. Both read local transcripts and are for Claude Code agents for now.

A cheaper Explore. Under Settings → “Token saving”, the “Explorer subagent” option gives Claude agents a read-only explorer for broad searches. File scanning runs on a cheaper model, Haiku by default, and only the result returns to the main conversation. If you already have your own Explore subagent file, AgentVera leaves yours in place. It sits next to the smart tools in the same section.

Separate agents when the work is bigger. The team view shows up to 24 agents at once. Parallel team (Pro and Team plans) splits a goal into parts, runs each in its own worktree and merges them into one PR. Agent messaging lets agents ask each other questions, even across CLIs, and agent coordination warns when two agents touch the same file. That gives you the separate-agent side of the table above, with subagents still available inside each Claude agent.

Wrapping up

Subagents are the right tool when the main agent needs an answer and you don’t need to watch the work: search, review, research. Write one Markdown file with a clear description, a short tool list and a deliberate model. When the work is big enough to deserve its own branch and your attention, run a separate agent instead.

Read more:

To try AgentVera, start at the home page.

Questions

What is a subagent in Claude Code?

A subagent is a helper that the main Claude Code session starts for one task. It runs in its own context window with its own system prompt, tools and model, and only its final result comes back to the main conversation.

How do I create a Claude Code subagent?

Add a Markdown file to .claude/agents/ in your project, or to ~/.claude/agents/ for all projects. The YAML frontmatter needs a name and a description; the body is the system prompt. Optional fields include tools, model, permissionMode and isolation.

Which model does a subagent use?

The model field accepts an alias such as sonnet, opus or haiku, a full model ID, or inherit. If it is not set, the subagent uses the main session’s model, unless the CLAUDE_CODE_SUBAGENT_MODEL environment variable says otherwise.

Do subagents save tokens?

They keep the main context clean, because file reads and search output stay in the subagent. They do not make work free: subagent requests count toward the same usage limits, so routing broad searches to a cheaper model like Haiku is what saves the most.

When should I use separate agents instead of subagents?

When tasks are long, edit many files, need your review along the way, or should end up as separate branches. Separate agents in their own git worktrees give you that; subagents suit short, focused jobs whose result the main agent needs.

Bring your agents to one desk.

Download AgentVera for free; your installed CLIs are ready to go.

More posts