Claude Code Sub-agents Reference

Defining and using Claude Code sub-agents: built-in Explore, Plan and general-purpose agents, file locations and priority, every frontmatter field, model resolution order, tool restriction, foreground and background runs, forks, nesting and concurrency limits, memory, worktree isolation, example agents, and when not to use one.

On this page

Simple definition#

A sub-agent is a separate Claude worker that the main conversation hands a task to. It has its own context window, its own system prompt, and optionally its own tools, model and permission mode. It does the work and returns a summary, so long searches, test logs or file dumps never enter your main conversation. Claude delegates on its own when a sub-agent’s description fits; you can also ask for one by name.

Built-in sub-agents#

Agent Tools Model Used for
Explore Read-only (no Write/Edit) Main conversation’s model Fast codebase search; Claude picks quick, medium or very thorough
Plan Read-only Inherits Research during plan mode
general-purpose All sub-agent tools CLAUDE_CODE_SUBAGENT_MODEL if set, else inherits Multi-step tasks that explore and modify
claude, statusline-setup, claude-code-guide Varies Varies Catch-all, /statusline, Claude Code questions

Explore and Plan start without CLAUDE.md and git status to stay cheap. Define your own Explore with model: haiku to make exploration cheaper; deny Agent(Explore) to disable it; CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS=1 removes both.

Where definitions live#

Location Scope Priority
Managed settings Organisation 1 (highest)
--agents '<json>' This session 2
.claude/agents/ This project (commit it) 3
~/.claude/agents/ All your projects 4
Plugin agents/ Where the plugin is enabled (plugin:name) 5

Same name in two places → the higher priority wins. Folders are scanned recursively, so agents/review/security.md is fine. Ask Claude to create one, or write the file.

Definition format#

---
name: reviewer
description: Reviews changed files against the spec. Use after implementing a feature, before the PR.
tools: Read, Grep, Glob
model: sonnet
effort: high
maxTurns: 30
color: purple
---
You are reviewing code you didn't write. Compare the changed files with the spec you are given.
Check every requirement is implemented and edge cases have tests.
Report only gaps that affect correctness, as a numbered list with file:line. Skip style.

The body is the sub-agent’s system prompt. The delegating Claude writes the task prompt from your request.

Frontmatter#

Field Required Does
name Yes Identifier (no :); hooks see it as agent_type
description Yes When Claude should delegate — add “use proactively” to encourage it
tools No Allowlist, e.g. Read, Grep, Bash. Omit to inherit all sub-agent tools
disallowedTools No Remove tools (a specifier like Bash(git push *) removes the whole tool)
model No sonnet, opus, haiku, fable, a full ID, or inherit
effort No low … max
permissionMode No default, acceptEdits, auto, dontAsk, bypassPermissions, plan (ignored for plugin agents)
maxTurns No Turn cap; output is returned marked partial
skills No Skills preloaded in full at start
mcpServers No Server names, or inline server configs, for this agent only
hooks No Hooks active while this agent runs
memory No user, project or local — persistent learning across sessions
background No true keeps it in the background even when Claude asks to wait
isolation No worktree — temporary git worktree, removed if unchanged
omitClaudeMd No Start without user/project/local CLAUDE.md
autoCompactWindow No Lower this agent’s auto-compact threshold
color No Display colour
initialPrompt No First turn when run as the main agent (--agent)

Which model runs it#

  1. The model Claude passes on that call (an alias).
  2. The definition’s model (inherit = main model).
  3. CLAUDE_CODE_SUBAGENT_MODEL.
  4. The main conversation’s model.

A family alias that matches the main model’s family resolves to the exact main model (including a 1M-context variant). Organisation availableModels still applies — a blocked model is substituted with a warning.

Invoking#

How Guarantee
Automatic Claude matches the task to a description
“Use the reviewer subagent to…” Claude usually delegates
@"reviewer (agent)" check the auth changes That sub-agent runs for this task
claude --agent reviewer, or "agent" setting The whole session is that agent
/subtask <task> A forked sub-agent that inherits your full conversation

Foreground, background and forks#

  • Sub-agents Claude spawns from your main conversation start in the background by default (fork mode on); permission prompts surface in your session, naming the agent.
  • Ctrl+B backgrounds a running one; /tasks lists them; Ctrl+X Ctrl+K stops all.
  • To let Claude wait for results, set CLAUDE_CODE_FORK_SUBAGENT=0. In -p and SDK runs, Claude can wait on its own judgment.
  • A fork inherits the conversation instead of starting fresh — no re-gathering context, but it carries everything.

Limits#

Limit Default Change with
Nesting depth below main 3 layers CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH (1 = no nesting)
Concurrent sub-agents 20 CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS
Combined descriptions Warning above 15,000 tokens Shorter descriptions

Keep a reviewer from spawning more agents by omitting Agent from its tools.

Controlling sub-agents#

{
  "permissions": { "deny": ["Agent(Explore)", "Agent(general-purpose)"] },
  "env": { "CLAUDE_CODE_SUBAGENT_MODEL": "haiku" }
}
  • Deny Agent entirely to stop all delegation.
  • Settings, managed and plugin hooks fire inside sub-agents too; SubagentStart / SubagentStop hooks see them start and finish.
  • --append-subagent-system-prompt adds text to every sub-agent’s prompt (useful in CI).

Example agents#

The first four follow Anthropic’s published examples; the last two are common additions.

Agent Tools Prompt essentials
code-reviewer Read, Grep, Glob, Bash Review recent changes; report by severity; skip style
debugger Read, Edit, Bash, Grep, Glob Reproduce, isolate, fix root cause, verify, report evidence
data-scientist Bash, Read, Write; model: sonnet SQL and data analysis with summarised findings
db-reader Bash, with a PreToolUse hook that allows only SELECT Read-only database queries
test-runner Bash, Read Run the suite; return only failures with file:line and first error lines
docs-checker Read, Grep, WebFetch; model: haiku Find broken links and stale examples

When to use one — and when not#

Use a sub-agent when Stay in the main conversation when
Output is verbose and you only need the result You iterate back and forth
You want enforced tool limits (read-only reviewer) Phases share lots of context
Work is self-contained and can return a summary It’s a quick targeted change
You need an independent reviewer that didn’t see the reasoning Latency matters — a fresh agent must re-gather context

For a quick question about the current conversation, /btw is cheaper than any sub-agent. For a reusable prompt that should run in the main context, write a skill. For many coordinated workers, see agent teams and dynamic workflows.

Common mistakes#

Review questions#

Which model does a sub-agent with model: opus use when the main session runs Opus 5.5 with 1M context? The main session’s exact model, including the 1M variant, because the alias matches the main model’s family.

How do you guarantee a specific sub-agent runs for one task? @-mention it: @"reviewer (agent)" ….

What’s the difference between a sub-agent and a fork? A sub-agent starts with only its system prompt and task; a fork inherits the whole conversation.

References#