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:

Subagents make their own requests, and those count against the same usage limits as your main conversation.

The built-in subagents

ExploreFast 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.
PlanRead-only research used in plan mode, so the exploration stays out of your main context before Claude presents a plan.
General-purposeHas every tool available to subagents. Used for tasks that need both exploring and changing things, or several dependent steps.
Othersclaude (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:

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:

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 settingsOrganisation-wide, deployed by admins.
2. --agents flagJSON 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/ folderWherever the plugin is enabled.

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.

nameRequired. A unique ID of up to 256 characters, such as code-reviewer. It cannot contain : or start with -.
descriptionRequired. When Claude should hand work to this subagent.
toolsThe tools it may use, as Read, Grep, Bash or a YAML list. Leave it out to inherit every tool available to subagents.
disallowedToolsTools to take away from the inherited or listed set.
modelsonnet, opus, haiku, fable, a full model ID, or inherit.
permissionModedefault (Manual), acceptEdits, auto, dontAsk, bypassPermissions or plan.
maxTurnsHow many turns it may take before stopping. Output at the limit is marked partial and Claude can resume it.
skillsSkills loaded in full at start-up. The subagent can still call other skills unless you remove the Skill tool.
mcpServersMCP servers for this subagent only, by name or defined inline. An inline server keeps its tools out of your main conversation.
hooksHooks that run only while this subagent is active.
memoryA memory folder that lasts between conversations: user, project or local. See below.
backgroundtrue keeps it in the background even when Claude asks for the foreground.
omitClaudeMdtrue starts it without your user, project and local CLAUDE.md files.
effortEffort level while it runs: low, medium, high, xhigh or max, depending on the model.
isolationworktree runs it in a temporary git worktree, a separate copy of the repository. The worktree is removed if it changes nothing.
colorDisplay colour in the task list and transcript.
initialPromptSent automatically as the first message when the agent runs as the whole session with --agent.
experimentalExperimental 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

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:

  1. A model Claude passes for that particular call.
  2. The model field in the file, where inherit means the main conversation's model.
  3. The CLAUDE_CODE_SUBAGENT_MODEL environment variable, if set.
  4. 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 decideClaude delegates when a task matches a subagent's description.
Ask by nameAnthropic's example: "Have the code-reviewer subagent look at my recent changes". Claude usually delegates, but still decides.
@-mentionType @ and pick the subagent, or type @agent-code-reviewer. This guarantees that subagent runs for the task.
Whole sessionclaude --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.

Patterns Anthropic suggests

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

Subagent, skill, or the main session?

Main conversationLots 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).
SubagentThe 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.
SkillReusable instructions or a workflow that should run inside the main conversation rather than in a separate context. See Claude Code skills.
/btwA 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

Related: All Harrowtech.ai guides · Claude Code best practices · Claude Code skills · Claude Code hooks