Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

How to Define Claude Code Subagents

A Claude Code subagent definition needs only two keys: name and description. Where the files go, how to restrict tools, and how the model gets chosen.

TL;DR

  • A subagent runs in its own context and returns only a summary, keeping bulky search results and logs out of the main conversation.
  • Built-ins are Explore and Plan (read-only) and general-purpose; Explore and Plan start without your CLAUDE.md files.
  • Definitions are Markdown files with YAML frontmatter in .claude/agents/ or ~/.claude/agents/; on a name clash the higher-priority location wins, and the frontmatter name identifies the subagent.

A subagent is a specialist helper that runs in its own context, separate from your main conversation. It works through bulky output you won’t read again, such as search results or logs, and hands back only a summary, so your main conversation stays clean. This guide covers the built-in subagents, where definition files go, the file format, how subagents get invoked, model and tool settings, and cost. For what went wrong when we ran many in parallel, see Subagent Failures in Parallel Runs. In our test environment (macOS, Claude Code 2.1.306, on 2026-10-22), we put a definition file into a dummy todo app and validated its format. We did not run a session that actually invokes the subagent (not run).

Built-in subagents

NameRoleTools
ExploreFast search and analysis of a codebaseRead-only; Write and Edit are denied
PlanGathers context in plan mode before Claude presents a planRead-only; Write and Edit are denied
general-purposeMulti-step work that needs both exploring and changing thingsEvery tool available to subagents

Explore and Plan start without your CLAUDE.md files.

Source: https://code.claude.com/docs/en/sub-agents (checked 2026-10-22)

Where definitions live

A subagent is a Markdown file with YAML frontmatter. Either ask Claude to write one (“create a read-only reviewer in ~/.claude/agents/”) or write the file yourself. In current versions, /agents doesn’t open an editor; it prints a reminder to ask Claude or edit the agents directories directly. Up to v2.1.197 it opened a wizard.

PriorityLocationScope
1 (highest)Managed settingsOrganization-wide
2JSON passed to --agents at launchThat session only
3.claude/agents/This project
4~/.claude/agents/All your projects
5A plugin’s agents/ directoryWherever the plugin is enabled

When two subagents share a name, the higher-priority one wins. Subagents are identified by the frontmatter name, not the filename. Added or edited files are picked up within a few seconds, but if you create an agents directory that didn’t exist when the session started, restart to load it.

Source: https://code.claude.com/docs/en/sub-agents (checked 2026-10-22)

The definition file

Here is a read-only code reviewer for a dummy todo app, saved as .claude/agents/readonly-reviewer.md:

---
name: readonly-reviewer
description: Read-only code reviewer for the todo app. Use proactively after code changes, or when the user asks for a review of a diff. Do not use for writing fixes or running migrations.
tools: Read, Grep, Glob
model: sonnet
maxTurns: 20
---

You review changes in the todo app. You never edit files.

1. Read the list of changed files passed to you by the caller.
2. Read those files and their tests.
3. Report findings as a list: file:line, severity (high / medium / low), and one sentence on why.
4. If you find nothing, say "No findings" and list what you checked.

The body becomes the subagent’s system prompt. It does not receive Claude Code’s own system prompt.

The main frontmatter keys are below. Only name and description are required. Multi-word keys use camelCase, as in maxTurns.

KeyWhat it does
nameIdentifier, up to 256 characters. Can’t contain :
descriptionWhen Claude should delegate to this subagent
toolsAllowed tools. If omitted, the subagent inherits every tool available to subagents
disallowedToolsTools to deny
modelsonnet, opus, haiku, a full model ID, or inherit
permissionModedefault, acceptEdits, auto, dontAsk, bypassPermissions or plan
maxTurnsMaximum number of turns
mcpServersMCP servers available only to this subagent
isolationworktree runs it in a temporary git worktree

Source: https://code.claude.com/docs/en/sub-agents (checked 2026-10-22)

Validate the format

claude plugin validate .claude/agents checks definitions without starting a session. We ran it on 2026-10-22 with 2.1.306. The example above returned Validation passed. A file with an unclosed quote returned:

✘ Found 1 error:

  ❯ frontmatter: YAML frontmatter failed to parse: YAML Parse error: Unexpected character. At runtime this agent does not load at all — with no frontmatter name it is treated as a co-located reference document and skipped.

A subagent with broken YAML doesn’t load at all. Files with tool instead of tools, modle instead of model, or a name containing : all passed the validator. The docs say Claude Code skips, at runtime, any file whose name starts with -, contains :, or is longer than 256 characters, and writes an error to the debug log. It passes the check but never loads. The docs also say unknown keys are ignored without an error, and that a misspelled key shows up in the claude --debug log as does not recognize or apply (not run).

Descriptions and invocation

Claude picks a subagent from your request, each subagent’s description, and the current context. To encourage proactive delegation, the docs suggest phrases like “use proactively” in the description. If your subagents’ descriptions add up to more than 15,000 tokens, you get a warning at startup. Keep descriptions short and put details in the body.

There are three ways to invoke one explicitly:

Source: https://code.claude.com/docs/en/sub-agents (checked 2026-10-22)

Choosing the model

The model is resolved in this order:

  1. The model Claude passes for that invocation
  2. The definition’s model (inherit means the main conversation’s model)
  3. The CLAUDE_CODE_SUBAGENT_MODEL environment variable
  4. The main conversation’s model

If you leave model out, the subagent usually runs on the main conversation’s model, so a simple search runs on a top-tier model if that’s what you’re chatting with. Set the model explicitly in the definition. /tasks shows which model a subagent is running on (v2.1.242 or later).

Source: https://code.claude.com/docs/en/sub-agents (checked 2026-10-22)

Tools and permissions

Since v2.1.283, interactive sessions start in auto mode by default, and in auto mode a subagent’s permissionMode is ignored. So enforce read-only access with tools, not permissionMode. That’s why the example limits tools to Read, Grep, Glob and leaves Bash out. For permission rules, see Claude Code settings.json Permissions: A Cheat Sheet.

Sources: https://code.claude.com/docs/en/sub-agents and https://code.claude.com/docs/en/permission-modes (checked 2026-10-22)

Cost

Each subagent keeps its own context and sends its own requests, and those requests count toward the same usage limits as your main conversation. Run many at once and usage grows with them. A skill can also run as a subagent; see How to Create Claude Code Skills (SKILL.md).

Summary