Claude Code subagents are specialized assistants that your main Claude session can delegate work to. Each subagent runs in its own context window, with its own system prompt, its own restricted set of tools, and optionally its own model. The main session hands off a task — “review this module for security issues” — the subagent works independently, and only its final summary comes back. Your main conversation stays clean, focused, and cheap.
Why Claude Code Subagents Exist: The Context Problem
Long sessions fill up with noise: pages of search results, test output, file contents from exploratory reading. Subagents solve this by isolating the noisy work. A subagent can burn through fifty files hunting for a pattern and return three sentences. They also let you encode expertise — a code reviewer that always checks the same checklist, a test runner that knows your suite’s quirks, a documentation writer with your house style — and reuse it in every session, for every teammate.
Claude Code ships with built-in subagent types, including a general-purpose agent for complex multi-step work, an Explore agent optimized for fast codebase search, and a Plan agent used for read-only research during planning. Custom Claude Code subagents sit alongside these and handle the jobs specific to your project.
Create Your First Subagent with /agents
The interactive route is the friendliest. Run:
/agents
This opens the subagent manager, where you can view built-in and custom agents and create new ones with guided questions: where to save it (project or personal), what it should do, which tools it may use, and which model it should run on. Let Claude generate the initial prompt, then edit it like you would any config file.
Define Claude Code Subagents as Files
Under the hood, a subagent is just a Markdown file with YAML frontmatter. Project subagents live in .claude/agents/ (shared with your team through Git); personal ones live in ~/.claude/agents/ and follow you everywhere. Here is a complete, realistic example:
---
name: code-reviewer
description: Expert code review specialist. Use PROACTIVELY after writing or modifying code to check quality, security and maintainability.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior code reviewer for this project.
When invoked:
1. Run `git diff` to see the recent changes.
2. Review only the modified files.
3. Check for security issues, missing error handling,
unclear naming and absent tests.
Report findings grouped by severity: critical, warning, suggestion.
Do not edit files — report only.
The frontmatter fields that matter most:
- name (required): lowercase letters and hyphens; this is how the agent is referenced.
- description (required): tells Claude when to delegate. Words like “use PROACTIVELY” encourage automatic invocation after matching work.
- tools (optional): an allowlist such as
Read, Grep, Glob. Omit it to inherit all tools. Least privilege is a feature — a reviewer that cannot edit cannot break anything. - model (optional):
haiku,sonnet,opusorinherit. Match cost to task depth: fast cheap models for searches, strong models for deep review.

How Invocation Works
Subagents get used three ways. Automatically: Claude reads the descriptions and delegates when a task matches — which is why precise descriptions matter more than clever names. Explicitly: ask in plain language (“use the code-reviewer subagent on the auth module”) or @-mention the agent. And directly: claude --agent code-reviewer starts a whole session running as that agent. Subagents typically run in the foreground and return their result; long jobs can be sent to the background and checked on later while you keep working.
Good Subagent Jobs (and Bad Ones)
- Great fits: code review with a fixed checklist, test running and failure triage, documentation drafting, log and error investigation, dependency audits, migration research.
- Poor fits: tiny tasks the main session can do in one step (delegation overhead exceeds the saving), and work where every intermediate detail matters to your next decision — that belongs in your main context.
One pattern worth copying: route noisy work down, keep judgment up. Let subagents gather and summarize; let your main session — with the strong model and full project picture — decide. This mirrors how we recommend structuring multi-agent systems in our broader guide to AI agents for server automation.
Tips for Reliable Subagents
- Write descriptions like routing rules: what the agent does and when to call it.
- Restrict tools aggressively; grant write access only when the job truly needs it.
- Give the system prompt a checklist and an output format — summaries come back far more useful.
- Start with one or two subagents (reviewer + test runner covers most teams) and add more only when a recurring job proves itself.
The official reference lives in Anthropic’s subagents documentation. Combine subagents with hooks for guardrails and a good CLAUDE.md, and you have the core of a serious Claude Code setup.