What Are Subagents?
Subagents are custom AI agents with their own configuration, including:- Name and color for visual distinction
- Tool allowlist to control what they can access
- Model selection (haiku, sonnet, opus, or inherit)
- Permission mode for auto-approving actions
- Preloaded skills for domain knowledge
- MCP servers for external integrations
- Lifecycle hooks for events
Subagents are defined in
.claude/agents/<name>.md with YAML frontmatter and invoked via the Task tool.Why Subagents Matter
Subagents enable specialization and orchestration:- Specialized expertise: Create agents for specific domains (frontend, backend, DevOps)
- Tool isolation: Limit what each agent can do for safety
- Parallel execution: Multiple agents can work on different parts of a codebase
- Persistent memory: Agents remember context across sessions
- Progressive disclosure: Preload skills for focused context
Key Concepts
Built-in vs Custom Agents
Built-in agents (available out-of-the-box):| Agent | Model | Tools | Use Case |
|---|---|---|---|
general-purpose | inherit | All | Complex multi-step tasks, the default |
Explore | haiku | Read-only | Fast codebase search and exploration |
Plan | inherit | Read-only | Pre-planning research before coding |
claude-code-guide | inherit | Read, WebFetch, WebSearch | Answers Claude Code feature questions |
Invocation via Task Tool
Always invoke subagents using the Task tool:claude agent-name — this won’t work.
Frontmatter Fields
Unique identifier using lowercase letters and hyphens. Used in
Task(subagent_type="name").When to invoke this agent. Use
"PROACTIVELY" for auto-invocation by Claude.Example: "Use this agent PROACTIVELY for deployment pipelines"Comma-separated allowlist of tools. Inherits all tools if omitted.Examples:
Read, Write, Edit, BashTask(agent_type)— Restrict which subagents this agent can spawn["Read", "Grep", "Glob"]
Tools to deny, removed from inherited or specified list.Example:
NotebookEdit, WebSearchModel alias:
haiku, sonnet, opus, or inherit (uses parent’s model).Permission mode for this agent:
default— Standard permission checkingacceptEdits— Auto-accept file editsdontAsk— Bypass most promptsbypassPermissions— Skip all permission checks (dangerous)plan— Read-only planning mode
Maximum number of agentic turns before the subagent stops.Example:
25Skill names to preload into agent context at startup. Full skill content is injected, not just made available.Example:
MCP servers for this subagent — server name strings or inline configs.Example:
Lifecycle hooks scoped to this subagent.Supported events:
PreToolUse, PostToolUse, PermissionRequest, PostToolUseFailure, Stop (converted to SubagentStop at runtime), SubagentStopPersistent memory scope:
user— Stored in~/.claude/agent-memory/<name>/, not sharedproject— Stored in.claude/agent-memory/<name>/, committed to gitlocal— Stored in.claude/agent-memory-local/<name>/, not committed
Set to
true to always run as a background task.Set to
"worktree" to run in a temporary git worktree (auto-cleaned if no changes).CLI output color for visual distinction.Examples:
green, magenta, blue, tealReal Examples
How to Use Subagents
Agent Skills (Preloaded Knowledge)
Preload skills into agents for focused domain knowledge:weather-fetcher skill is injected into the agent’s context at startup. The agent sees the full skill content without needing to invoke it separately.
Agent Memory
Agents can persist memory across sessions:| Scope | Location | Shared | Version Control |
|---|---|---|---|
user | ~/.claude/agent-memory/<name>/ | No | No |
project | .claude/agent-memory/<name>/ | Yes | Yes |
local | .claude/agent-memory-local/<name>/ | No | No |
Agent Memory Report
Deep dive into persistent memory scopes and how agents learn across sessions
Best Practices
Create feature-specific agents
Create feature-specific agents
Instead of general “backend-engineer” or “frontend-engineer” agents, create agents for specific features or domains:Good:
deploy-manager, api-tester, database-migratorBad: general-engineer, code-helperUse agents with preloaded skills
Use agents with preloaded skills
Combine agents with skills for progressive disclosure:
Restrict tools appropriately
Restrict tools appropriately
Only give agents the tools they need:
Set appropriate models
Set appropriate models
haikufor simple, fast operationssonnetfor most tasksopusfor complex reasoninginheritto use parent’s model
Use PROACTIVELY for auto-invocation
Use PROACTIVELY for auto-invocation
Add “PROACTIVELY” to the description so Claude knows to invoke the agent automatically:
Scope and Priority
When multiple agents share the same name:Orchestration Patterns
Command → Agent → Skill
The recommended pattern for complex workflows:- Command provides the entry point and user interaction
- Agent executes tasks with preloaded skills
- Skill creates outputs independently
Orchestration Workflow
See the complete Command → Agent → Skill pattern with diagrams
Cross-Links
Commands
Learn how commands orchestrate agents
Skills
Preload skills into agents for domain knowledge
Hooks
Add lifecycle hooks to agents
Subagents Best Practice
Complete frontmatter reference and built-in agents
