Canonical: https://code.claude.com/docs/en/sub-agents.md. This file is a distillation – for anything version-sensitive or where exact behaviour matters, fetch the live page instead.
| Priority | Location | Scope |
|---|---|---|
| 1 | Managed settings .claude/agents/ |
organisation |
| 2 | --agents CLI flag (JSON) |
current session |
| 3 | .claude/agents/ |
project |
| 4 | ~/.claude/agents/ |
all projects |
| 5 | Plugin agents/ |
where enabled |
- Identity comes from the
namefrontmatter field, not the filename. Lowercase and hyphens, no colons - Directories scan recursively – subfolders organise but don't affect identity, except in plugins where they become scoped ids (
my-plugin:review:security) - Duplicate names: across nested project dirs, closest to the working directory wins. Within one directory tree, load order is undefined –
/doctorreports these - Edits to existing files apply live within seconds. The first file in a brand-new
agents/directory needs a restart
name and description required, everything else optional.
| Field | Purpose |
|---|---|
description |
When Claude should delegate to this agent – the trigger. "Use proactively" encourages auto-delegation |
tools |
Allowlist. Omitted = inherits every tool available to subagents. Use skills to preload skills, not Skill here |
disallowedTools |
Denylist, applied before tools resolves. Accepts MCP server patterns: mcp__<server>, mcp__* |
model |
sonnet, opus, haiku, fable, full id, or inherit (default) |
effort |
Overrides session effort while the agent runs |
permissionMode |
default, acceptEdits, auto, dontAsk, bypassPermissions, plan. Parent bypassPermissions/acceptEdits/auto overrides it |
maxTurns |
Turn cap before the agent stops |
skills |
Skills preloaded in full at startup – on subagent spawns only. A main-session --agent boot gets just the listing, so if a skill is needed from turn one, instruct loading it in the body. Can't preload disable-model-invocation skills |
mcpServers |
Named refs share the session's connection; inline definitions are scoped to the agent – keeps their tool descriptions out of main context |
hooks |
Lifecycle hooks active only while the agent runs. Stop converts to SubagentStop |
memory |
Persistent memory scope: user (cross-project), project (recommended – shareable via git) or local (project-scoped, untracked). Omitted = no persistent memory. Inert when auto memory is disabled. Enables Read/Write/Edit, injects generic save instructions and the first 200 lines (or 25KB) of MEMORY.md – see memory note below |
background |
true = always run in the background |
isolation |
worktree = run in a temporary git worktree, auto-cleaned if unchanged |
initialPrompt |
Auto-submitted first user turn when run as the main session agent |
color |
Display colour in task list and transcript |
Plugin agents ignore hooks, mcpServers and permissionMode.
Memory injection includes save mechanics plus a user/feedback/project/reference taxonomy. It suits agents whose durable learnings map onto those types. An agent whose per-task output resembles a memory type (account-scan findings look like 'project' memories) saves that output, and it goes stale. Add a body instruction scoping what to record.
Two filters apply on top of the tools/disallowedTools fields:
- Always removed:
AskUserQuestion,EndConversation,EnterPlanMode,ExitPlanMode(unlesspermissionMode: plan),ScheduleWakeup,TaskOutput,WaitForMcpServers,Workflow– andAgentat the depth limit - Background runs (the default) keep every MCP tool but only these built-ins: Read, Grep, Glob, Bash, PowerShell, Edit, Write, NotebookEdit, WebFetch, WebSearch, TodoWrite, Skill, ToolSearch, EnterWorktree, ExitWorktree, Monitor, TaskStop, SendMessage, Artifact
Forks skip both filters.
- Its own body as system prompt plus environment details – not the full Claude Code system prompt
- The delegation message the main conversation writes
- The full CLAUDE.md hierarchy and parent git status (built-in Explore and Plan skip both)
- Full content of preloaded
skills - Not: conversation history, invoked skills, output style, main-session auto memory. Context window is sized by the agent's own model
- Auto-delegation matches the description. An @-mention guarantees the agent runs; natural language leaves the choice to Claude
claude --agent <name>runs the definition as the main session: the body replaces the entire default system prompt, CLAUDE.md still loads. Theagentkey in.claude/settings.jsonsets a project default- Deny with
Agent(<name>)inpermissions.deny tools: Agent(worker, researcher)allowlists which subagent types a main-session agent can spawn. Inside a subagent definition the type list is ignored – bareAgentenables nesting, omitting it prevents spawning
- Nesting: 3 layers below main by default (
CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH). Session total 200, concurrent 20 - Background results arrive as a completion notification in a later turn
- Resume with
SendMessageby name or id – full history retained. Explore and Plan are one-shot and can't resume - Transcripts:
~/.claude/projects/{project}/{sessionId}/subagents/agent-{agentId}.jsonl
A fork inherits the whole conversation, system prompt, tools and model, and shares the parent's prompt cache – cheaper than a fresh spawn when the task needs the session's context. A named agent starts fresh from its definition. Start one manually with /subtask.