Guide
Claude Code agents: creating and using subagents
Harrowtech.ai · last checked 13 October 2026
In Claude Code, the agents you create and call by name are subagents: helpers that Claude hands a side task to. Each one works in its own context window, with its own instructions and tool access, and sends back only a summary. Claude Code ships with some, and you can make your own as a Markdown file in .claude/agents/.
Harrowtech.ai is independent of Anthropic. The short version, following Anthropic's quickstart: describe the subagent you want to Claude and say where to save it, check the file Claude writes, then ask Claude to use it by name. The rest of this page explains each part, from Anthropic's subagents documentation read on 13 October 2026.
What a subagent is for
Anthropic's subagents page gives the main reason as context. A side task such as searching a codebase or reading logs can fill your conversation with output you will not look at again. A subagent does that work in its own context window and returns a summary, so your main conversation stays focused. Anthropic lists four other benefits:
- Limiting which tools a task can use.
- Reusing the same helper across projects.
- Giving a helper focused instructions for one kind of job.
- Cutting cost by sending simple tasks to a cheaper model such as Haiku.
Subagents make their own requests, and those count against the same usage limits as your main conversation.
The built-in subagents
| Explore | Fast and read-only (Write and Edit are denied). Claude uses it to search and understand a codebase without changing it, and asks for a thoroughness level: quick, medium or very thorough. |
|---|---|
| Plan | Read-only research used in plan mode, so the exploration stays out of your main context before Claude presents a plan. |
| General-purpose | Has every tool available to subagents. Used for tasks that need both exploring and changing things, or several dependent steps. |
| Others | claude (a catch-all), statusline-setup (used by /statusline) and claude-code-guide (answers questions about Claude Code). Claude normally calls these itself. |
Explore and Plan skip your CLAUDE.md files and the git status to stay quick and cheap. Every other subagent loads both. To stop Claude using a built-in, add it to the deny list in settings, for example "deny": ["Agent(Explore)"], or set CLAUDE_CODE_DISABLE_EXPLORE_PLAN_AGENTS=1 to remove Explore and Plan only.
Making your own
A subagent is a Markdown file. The header between the --- lines sets it up, and the text below becomes its system prompt. Anthropic notes that a subagent receives only that prompt plus basic details such as the working folder, not Claude Code's own system prompt, so the body needs to say everything the subagent should know.
There are two ways to create one:
- Ask Claude. Describe what you want and where to save it. Claude writes the file with a name, description, tool list, model and prompt.
- Write the file yourself in
.claude/agents/or~/.claude/agents/.
On current versions /agents only prints a reminder to do one of these. The interactive wizard it used to open was in v2.1.197 and earlier, so older tutorials that walk through it no longer match.
Claude Code notices new and changed files within a few seconds, with no restart. The main exception Anthropic gives: if the agents folder did not exist when the session started, restart once after creating it.
Anthropic's example
This read-only reviewer is copied from Anthropic's subagents page:
---
name: code-reviewer
description: Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing or modifying code.
tools: Read, Grep, Glob, Bash
model: inherit
---
You are a senior code reviewer ensuring high standards of code quality and security.
When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately
Review checklist:
- Code is clear and readable
- Functions and variables are well-named
- No duplicated code
- Proper error handling
- No exposed secrets or API keys
- Input validation implemented
- Good test coverage
- Performance considerations addressed
Provide feedback organized by priority:
- Critical issues (must fix)
- Warnings (should fix)
- Suggestions (consider improving)
Include specific examples of how to fix issues.
What each part does:
descriptionis what Claude reads when deciding whether to delegate. The words "Proactively" and "Use immediately after" push it to call the reviewer without being asked. Anthropic suggests phrases like "use proactively" for this.toolsleaves out Edit and Write, so the reviewer cannot change files. It keeps Bash so it can rungit diff.model: inheritruns it on whatever model the main conversation uses.- The body tells it where to start, what to check and how to lay out its answer, which is what comes back to the main conversation.
Where the files live, and which one wins
When two subagents share a name, the one from the higher-priority location is used:
| 1. Managed settings | Organisation-wide, deployed by admins. |
|---|---|
2. --agents flag | JSON passed when starting claude. Lasts for that session only and is not saved. |
3. .claude/agents/ | The current project. Anthropic suggests checking these into version control so the team shares them. |
4. ~/.claude/agents/ | All your projects on this machine. |
5. A plugin's agents/ folder | Wherever the plugin is enabled. |
- Project folders are found by walking up from the working folder to the repository root. If two nested folders define the same name, the closer one wins.
- Subfolders such as
agents/review/are fine. The subagent is identified by itsnamefield, not its path or filename. - If two files in the same
agentsfolder tree share a name, only one loads, picked by file system read order rather than a documented rule./doctorreports such duplicates. - Plugin subagents ignore the
hooks,mcpServersandpermissionModefields for security. Copy the file into.claude/agents/if you need them.
Every header field
Only name and description are required. Field names are case-sensitive camelCase, and Anthropic warns that a misspelt field is ignored without any error.
name | Required. A unique ID of up to 256 characters, such as code-reviewer. It cannot contain : or start with -. |
|---|---|
description | Required. When Claude should hand work to this subagent. |
tools | The tools it may use, as Read, Grep, Bash or a YAML list. Leave it out to inherit every tool available to subagents. |
disallowedTools | Tools to take away from the inherited or listed set. |
model | sonnet, opus, haiku, fable, a full model ID, or inherit. |
permissionMode | default (Manual), acceptEdits, auto, dontAsk, bypassPermissions or plan. |
maxTurns | How many turns it may take before stopping. Output at the limit is marked partial and Claude can resume it. |
skills | Skills loaded in full at start-up. The subagent can still call other skills unless you remove the Skill tool. |
mcpServers | MCP servers for this subagent only, by name or defined inline. An inline server keeps its tools out of your main conversation. |
hooks | Hooks that run only while this subagent is active. |
memory | A memory folder that lasts between conversations: user, project or local. See below. |
background | true keeps it in the background even when Claude asks for the foreground. |
omitClaudeMd | true starts it without your user, project and local CLAUDE.md files. |
effort | Effort level while it runs: low, medium, high, xhigh or max, depending on the model. |
isolation | worktree runs it in a temporary git worktree, a separate copy of the repository. The worktree is removed if it changes nothing. |
color | Display colour in the task list and transcript. |
initialPrompt | Sent automatically as the first message when the agent runs as the whole session with --agent. |
experimental | Experimental options. Its cacheTtl key sets the prompt cache lifetime to 5m or 1h. |
A file is skipped without a message if it has no name, has a name but no description, or has YAML that does not parse. Run Claude Code with --debug to see why, or check a folder before a session with claude plugin validate .claude/agents.
Limiting what a subagent can do
Tools
toolsis an allow list. Anthropic'ssafe-researcherexample setstools: Read, Grep, Glob, Bash, which leaves it unable to edit or write files or use MCP tools.disallowedToolsis a deny list. Anthropic'sno-writesexample setsdisallowedTools: Write, Editand keeps everything else.- With both set, the deny list is applied first. MCP tools can be named by server, as
mcp__github. disallowedTools: Bash(git push *)removes Bash entirely, not only that command. To block one command and keep Bash, addBash(git push *)topermissions.denyin settings instead, which applies to every subagent and the main conversation.- Subagents running in the background get a smaller set of built-in tools than foreground ones, so the same file can end up with different tools depending on how it runs.
Permission mode
Without permissionMode, a subagent uses the main conversation's mode. If the main conversation is in bypass, accept edits or auto mode, the subagent runs in that mode whatever its file says.
Finer rules with a hook
For "allow this tool, but not like that", Anthropic's example puts a PreToolUse hook in the subagent's header that runs a script before each Bash command and blocks SQL writes by exiting with code 2. How hooks work is covered in Claude Code hooks.
Choosing the model
Claude Code decides a subagent's model in this order:
- A model Claude passes for that particular call.
- The
modelfield in the file, whereinheritmeans the main conversation's model. - The
CLAUDE_CODE_SUBAGENT_MODELenvironment variable, if set. - The main conversation's model.
Because the variable is only a default, setting it alone does not change subagents that name a model. To force one model onto every subagent, set CLAUDE_CODE_SUBAGENT_MODEL_FORCE=1 as well. Run /tasks while a subagent is working to see which model it is on. Anthropic's example for lower-cost searching is to define your own subagent named Explore with model: haiku, which overrides the built-in one.
Using subagents
| Let Claude decide | Claude delegates when a task matches a subagent's description. |
|---|---|
| Ask by name | Anthropic's example: "Have the code-reviewer subagent look at my recent changes". Claude usually delegates, but still decides. |
| @-mention | Type @ and pick the subagent, or type @agent-code-reviewer. This guarantees that subagent runs for the task. |
| Whole session | claude --agent code-reviewer runs the main session with that subagent's prompt, tools and model. To make it the default in a project, set "agent": "code-reviewer" in .claude/settings.json. |
- In an interactive session, subagents Claude starts run in the background by default, so you can keep working. Their permission prompts appear in your main session with the subagent's name.
Ctrl+Bmoves a running task to the background, and/taskslists what is running. - Each call starts a new subagent. To carry on from where one stopped, ask Claude to continue that work; it resumes the subagent with its history. Explore and Plan cannot be resumed, so use general-purpose or your own subagent for work you may continue.
/subtaskstarts a fork: a subagent that begins with a copy of the whole conversation, so it needs no briefing. Anthropic says a fork costs less than a fresh subagent for tasks that need the same context, because it reuses the main session's prompt cache.
Patterns Anthropic suggests
- Keep noisy work out of the way: "Use a subagent to run the test suite and report only the failing tests with their error messages".
- Research in parallel: separate subagents for independent areas, then Claude combines the findings. Anthropic warns that many detailed reports coming back can still fill your context.
- Chain them: one subagent finds performance issues, the next fixes them.
Memory that lasts between sessions
The memory field gives a subagent its own folder of notes it reads and updates across conversations:
user | ~/.claude/agent-memory/<name>/, across all your projects. |
|---|---|
project | .claude/agent-memory/<name>/, shareable through version control. Anthropic recommends this as the default. |
local | .claude/agent-memory-local/<name>/, for this project but not checked in. |
The first 200 lines or 25KB of the folder's MEMORY.md load at start. Turning auto memory off also turns this off.
Limits worth knowing
- A subagent can start subagents of its own, up to three layers below the main conversation by default.
CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTHchanges this, and1turns nesting off. - By default no more than 20 can run at once in a session.
CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTSchanges that. - Every description is loaded into context. If your own subagents' descriptions add up to more than 15,000 tokens, Claude Code warns at start-up. Keep descriptions short and put detail in the body, which only loads when the subagent runs.
- Apart from a fork, a subagent does not see your conversation, the skills or files Claude has already loaded, your output style or your auto memory. If a rule must reach it, put it in the subagent's file or in your request.
Subagent, skill, or the main session?
| Main conversation | Lots of back-and-forth, phases that share a lot of context, quick targeted changes, or when speed matters (a fresh subagent takes time to gather context). |
|---|---|
| Subagent | The task produces a lot of output you do not need, it should run with restricted tools or permissions, or it is self-contained and can return a summary. |
| Skill | Reusable instructions or a workflow that should run inside the main conversation rather than in a separate context. See Claude Code skills. |
/btw | A quick question about something already in the conversation. It sees your context but has no tools, and the answer is not kept. |
Skills and subagents also combine. A subagent can preload skills with its skills field, and a skill can run in a subagent with context: fork.
Anthropic's own tips for good subagents: keep each one focused on one job, write descriptions specific enough that Claude picks the right one, grant only the tools it needs, and check project subagents into version control.
What this guide does not cover
It does not cover agent teams, background sessions in agent view, dynamic workflows, plugin packaging, or the SubagentStart and SubagentStop hook events. For Anthropic's wider agent products, such as the Agent SDK, see Anthropic AI agents. For the command list, see Claude Code commands and shortcuts.
Sources
- Anthropic: Create custom subagents, including the code-reviewer, safe-researcher and no-writes examples, read 13 October 2026.
- Anthropic: Extend Claude Code, for skills compared with subagents, read 13 October 2026.
- Anthropic: Commands, for what
/agentsdoes now, read 13 October 2026.
Related: All Harrowtech.ai guides · Claude Code best practices · Claude Code skills · Claude Code hooks