HomeClaude Code › Subagents
OverviewInstallCLI referencePricing & limitsAgent SDKSkills & pluginsGitHubWeb, desktop & IDEModelsErrorsOpen source?TutorialFor studentsQA automationvs Cursorvs Codex & OpenCodeSubagentsHooksMCPEcosystem中文指南
Last updated: September 22, 2026

Claude Code subagents: how they work, how to define them, and agent teams

A subagent is a separate Claude Code worker with its own system prompt, its own tool permissions and — the important part — its own context window. The main session delegates a task to it, gets a summary back, and its context stays clean. Used well, subagents are the difference between a session that degrades after an hour and one that runs all day.

TLDR

  • Define one as a Markdown file in .claude/agents/ (project) or ~/.claude/agents/ (user): frontmatter for name, description, tools, model; body is the system prompt.
  • Claude delegates automatically when the description matches the task, or explicitly when you name the agent.
  • Each subagent carries its own context and bills its own tokens; results come back summarised.
  • /agents creates and manages them; agent teams extend the idea to coordinating sessions.

Defining a subagent

# .claude/agents/code-reviewer.md
---
name: code-reviewer
description: Reviews a diff for correctness, security and test coverage. Use after any non-trivial change.
tools: Read, Grep, Glob, Bash(git diff *)
model: sonnet
---
You are a senior reviewer. Read the staged diff, list concrete defects with file:line,
flag untested paths, and stop. Do not edit files.

name is how you call it; description is how Claude decides to call it on its own, so write it as a routing rule ("use after any non-trivial change") rather than a job title. tools restricts what it may do — a reviewer that cannot edit is a safer reviewer. model pins a tier: haiku for scouting and classification, sonnet for most work, opus for the hard step, or inherit to follow the parent session.

Project vs user agents

Files in .claude/agents/ belong to the repository and travel with it — commit them, and every teammate gets the same reviewer, test-writer and migration agent. Files in ~/.claude/agents/ are yours across every project. Project agents win on a name clash. /agents inside a session lists, creates and edits both kinds without touching files by hand.

When Claude delegates

Two ways. Implicit: the main agent reads every subagent's description and delegates when a task matches — "run the code-reviewer subagent on this" is not required if the description already says when to use it. Explicit: name it in the prompt. In both cases the subagent runs in its own context, sees only what it is given plus what it reads, and returns a result the main session summarises into its own history. Subagents do not spawn subagents; the hierarchy is one level deep.

Why they keep sessions cheap

Every turn in Claude Code resends the whole conversation. A subagent that reads forty files does so in its own window; the parent receives a paragraph. Without subagents those forty files would sit in the main context for the rest of the session, resent on every turn. So the pattern for large codebases is: scout with a Haiku subagent, review with a Sonnet subagent, keep the parent's context for decisions. Each subagent bills its own tokens — it is not free, it is contained.

Parallelism and rate limits

Several subagents can run at once, and each is a parallel streaming request. That is the quickest way to hit the concurrent-request limit on any endpoint, so on a new gateway account start with two or three in parallel and ask for higher concurrency once the workload is real. The errors guide covers the 429 you get otherwise.

Agent teams

Newer Claude Code builds add agent teams: instead of one parent delegating to short-lived subagents, several sessions coordinate as named teammates with a shared task list and messages between them, so a lead can hand out work, ask for status and stop a teammate. It is an experimental capability that ships behind a setting and changes between releases — check claude --help and the changelog for the current flag rather than a blog post. The mental model is the same as subagents with persistence and communication added; the cost model is the same too, multiplied by teammates.

On the gateway

Subagents and teams use the same endpoint and key as the parent session, so ANTHROPIC_BASE_URL=https://aiprimetech.io covers all of them. On a flat-rate unlimited plan the parallelism question becomes a fair-use question rather than a billing one, which is why heavy multi-agent users tend to end up there.

PlanDurationPrice
Unlimited 1 Hour1 hour$1
Unlimited 24 Hours24 hours$10
Unlimited 1 Week1 week$49
Unlimited 15 Days15 days$89

All unlimited plans →

Frequently asked questions

What is a subagent in Claude Code?

A separate agent with its own system prompt, tool permissions, model choice and context window, defined as a Markdown file in .claude/agents/, that the main session delegates tasks to.

Where is the Claude Code subagents documentation?

The official reference is in Anthropic's Claude Code docs under Sub-agents; this page is the practical version — the file format, when delegation happens and what it costs.

Do subagents cost extra?

They bill their own tokens like any request. They save money on long sessions by keeping large reads out of the parent context, and they cost more if you run many in parallel on Opus.

What are agent teams?

An experimental extension where several Claude Code sessions coordinate as named teammates with messaging and a shared task list, rather than one parent and short-lived helpers.

Run Claude Code on the gateway

Same models, two environment variables, credits at 7.69× face value — or a flat-rate unlimited plan.

Get an API key See unlimited plans

AI Prime Tech is an independent API gateway and is not affiliated with, endorsed by, or sponsored by Anthropic. “Claude” and “Claude Code” are trademarks of Anthropic. Claude Code features described here follow Anthropic’s public documentation at the time of writing and change frequently; prices and model lists on this page are read from this gateway’s live settings.

More Claude Code guides

Claude Code: the complete guideHow to install Claude CodeClaude Code CLI documentation: commands and flagsClaude Code pricing and limits, explainedThe Claude Code SDK, now the Claude Agent SDKClaude Code skills and pluginsClaude Code in GitHub: the App, the Action and @claudeDoes Claude Code have a web interface? Web, desktop and IDE explainedWhich model Claude Code uses, and how to change itClaude Code errors and how to fix themIs Claude Code open source?Claude Code tutorial: your first real sessionClaude Code for studentsHow to use Claude Code for QA automationClaude Code vs Cursor: which one, when — and how to run bothClaude Code vs Codex vs OpenCode: the terminal agents comparedClaude Code hooks: deterministic control over what the agent doesClaude Code MCP: connecting servers, scopes, remote MCP and real examplesThe Claude Code ecosystem: routers, frameworks, plugins and the lists that track themClaude Code 怎么用:从安装到日常使用