Learning resourcesReviewed · Anthropic

Create custom subagents in Claude Code

This Claude Code guide teaches developers to create specialized AI helpers, but each helper consumes shared usage and needs carefully configured tool access. It covers separate context windows, reusable agent definitions, model selection, permissions, hooks, memory and repository worktrees.

Researched 12 Nov 2026

In short.

This Claude Code guide helps developers create specialized AI helpers, but delegation consumes shared usage and requires careful control of tools and permissions. It progresses from a code-review assistant to detailed configuration, including model precedence, background execution, persistent memory, hooks, worktree isolation and conversation forks. Its strongest use is learning how to delegate self-contained tasks that produce large amounts of output. Several behaviors depend on Claude Code version and session settings. Nothing was executed, so effectiveness, reliability and cost savings are not assessed.

Researched and written by an AI model and checked by a second AI model. How it works

Covers the complete supplied guide at [https://code.claude.com/docs/en/sub-agents.md], including its examples, embedded notices, configuration exceptions and version requirements. Linked pages and other folders are excluded. No explicit licence or redistribution notice appears in the supplied text. No code, commands, agents or configurations were executed; runtime behavior, performance and costs remain unassessed.

The overview

Resource identity

Create custom subagents is a Claude Code documentation guide at [https://code.claude.com/docs/en/sub-agents.md]. It explains built-in assistants and how to define custom assistants for tasks such as code review, debugging, research and data analysis.

The resource is a tutorial and configuration reference. Its example agent definitions are starting points to adapt rather than a separately packaged agent library.

Practical assessment

The guide is useful when repeated research or implementation tasks overwhelm the main conversation with file contents, logs or search results. It connects that problem to a concrete mechanism: delegate the task into a separate context and return a summary.

The quickstart gives beginners a manageable entry point, while the configuration reference explains precedence rules and operational exceptions experienced developers need. The page provides no measured evidence that delegation improves accuracy, reduces total tokens or finishes work faster.

Who it suits

The guide suits Claude Code users who repeatedly ask for the same kind of assistance, such as reviewing changes, investigating failures or exploring a codebase. Project definitions can be shared through version control; personal definitions can be reused across projects.

Beginners can follow the code-improver walkthrough. Developers configuring automation, plugins or organization-wide agents will benefit from the advanced sections, but must account for differences between interactive sessions, non-interactive use and the Agent SDK.

What it covers

The guide covers automatic delegation, explicit invocation, tool allowlists and denylists, model and effort selection, permission modes, lifecycle hooks, persistent memory, MCP server access and worktree isolation. It also explains background execution, nested delegation, concurrency limits, resuming agents and automatic context compaction.

Definitions can come from managed settings, command-line JSON, project files, personal files or plugins. These forms have different precedence and capabilities: plugin definitions, for example, ignore the hooks, mcpServers and permissionMode frontmatter fields.

Using it

Requirements and compatibility

The walkthrough assumes access to Claude Code and the ability to create agent files. File definitions use YAML frontmatter followed by the agent’s system prompt. Only name and description are required; tool and model configuration are optional.

Advanced features have individual version requirements. The page states that forcing a model across subagents requires v2.1.257 or later, while autoCompactWindow requires v2.1.296 or later. There is no single minimum version stated for every feature covered.

Available models, tools and MCP servers remain subject to the session and organization’s configuration. The page does not establish account eligibility or complete installation requirements.

How subagents work

A regular subagent starts with a separate context window: the information its model can see while working. It receives its own system prompt, environment details and a task message composed by the main assistant, rather than the full conversation history. Its tool activity stays outside the main conversation, which receives its result.

Custom subagents normally load applicable CLAUDE.md files and a git status snapshot. Built-in Explore and Plan skip those startup inputs. A conversation fork is different: it inherits the parent’s conversation, system prompt, tools and model.

Permissions remain tied to the main session’s constraints. An agent definition cannot always impose its requested permission mode; the guide describes cases where the parent mode overrides it.

Configuration path

For a personal assistant, the guide places a Markdown definition in ~/.claude/agents/. For a project assistant, it uses .claude/agents/. Add name and description to the YAML frontmatter, choose the tools and model when needed, and put the task instructions in the file body.

Use a specific, brief description because Claude uses it to decide when to delegate. Omitting tools grants the available inherited tool pool, so an explicit allowlist is the clearer starting point for narrowly scoped work.

Existing agent directories are watched for changes. Creating a scope’s first agents directory requires a restart, and definitions in directories added through --add-dir are not watched. Duplicate names within the same directory tree can resolve by filesystem read order.

Concrete example

The introductory example creates ~/.claude/agents/code-improver.md with the name code-improver, a description about reviewing readability and performance, the tools Read, Grep and Glob, and model sonnet. Its prompt asks for an explanation of each issue, the existing code and an improved version.

The user then asks Claude to use code-improver to suggest improvements in the project. The documented result is a delegated review that returns suggestions to the main conversation. This configuration and its review quality were not run or assessed.

Assessment & evidence

Limits and pitfalls

Regular subagents do not automatically know the main conversation’s history, so delegation can omit relevant context. Their summaries can also lose detail. Forks retain the history but give up that separation of input context. The guide recommends the main conversation when frequent interaction, shared context or low latency matters.

A read-only label is not sufficient to establish read-only behavior. Several examples include Bash, and the guide explicitly notes that denying Write and Edit leaves Bash and MCP tools available. As a practical implication, remaining tools must also be considered when deciding what an agent can change.

The database hook examples inspect command text with regular expressions. They do not establish database-enforced read-only access or comprehensive prevention of writes. Output scanning likewise identifies certain instruction-shaped text without determining whether it is malicious.

Worktree safeguards also differ by shell: the page describes working-directory and command-content checks for Bash, while PowerShell receives only the working-directory check.

Why the design may fit

The strongest fit is a self-contained task with verbose intermediate output and a compact useful result. Code searches, log investigations and test reports match that pattern because the parent conversation may need findings rather than every intermediate detail.

A reusable definition can make repeated delegation more consistent by fixing the task instructions and available tools. That is an inference from the documented configuration mechanism, not a demonstrated improvement in output quality. Any advantage must be weighed against extra requests, startup context and coordination.

Related approaches

The guide recommends staying in the main conversation for quick changes, frequent refinement or work whose phases share substantial context. It points to Skills for reusable instructions that operate in the main conversation rather than a separate subagent context.

Within Claude Code, a fork suits tasks needing the full existing conversation. The page distinguishes subagents from independent background sessions, cross-session messaging and coordinated agent teams. Those linked resources were not assessed, and the evidence does not support comparisons with other vendors’ tools.

Evidence and confidence

The evidence is the supplied documentation text from [https://code.claude.com/docs/en/sub-agents.md]. It provides configuration syntax, precedence rules, version conditions, troubleshooting notes and examples. These support an explanation of documented behavior.

Nothing was executed. Agent invocation, permission enforcement, hooks, model routing, background operation, worktree isolation and recovery behavior were not independently verified. The page contains no benchmark results establishing accuracy, speed or cost improvements.

Access & freshness

Usage and costs

Each subagent sends its own model requests, which count toward the same usage limits as the main conversation. Parallel or nested agents therefore consume usage individually, even when their work keeps the main conversation shorter.

The guide suggests routing suitable work to lower-cost models such as Haiku and explains prompt-cache reuse for forks. It supplies no prices, representative task costs or measured savings. Actual monetary cost and whether delegation saves money for a particular workload remain unknown.

Licence and reuse

The supplied page text contains no explicit licence or redistribution grant for its prose, example agent definitions or scripts. Reuse and redistribution rights are therefore unknown from this evidence.

The page recommends sharing project agent definitions through version control, but that recommendation does not establish a licence for reproducing the documentation itself.

Version sensitivity

The supplied documentation was captured on 12 November 2026. A page publication or last-update date is not established by the evidence.

Behavior is version-sensitive. For example, the page says /agents opened an interactive wizard through v2.1.197, while newer behavior prints an editing reminder. It also documents changes to model precedence, background tools and fork defaults. Match instructions to the installed version rather than assuming every example behaves identically across releases.

How to approach it

Start with one recurring, bounded task such as suggesting code improvements. Choose personal or project scope, write a clear description and explicitly list the necessary tools. Use the introductory example before adding memory, hooks, external servers or nested delegation.

Before relying on the assistant, confirm that its definition loads, its actual model matches expectations and its available tools fit the intended access. For version-sensitive features, use the documented requirements and diagnostics. Compare usefulness and usage on representative work; the guide supplies no measured threshold for when delegation pays off.

Evidence for this report

selected-page.txtselected · checked 2026-11-12