~/academy $ claude learn subagents
Subagents: hand off side tasks cleanly
The built-in Claude Code subagents, how to write your own in .claude/agents with frontmatter for tools and model, and when delegating beats doing it in the main session. 8 min
$ Read
What a subagent is
A subagent is a separate Claude worker with its own fresh context window, its own instructions and its own tool limits. Claude hands it a task, it does the work, and only a summary comes back to your main conversation.
That last part is the point. Searching a big codebase, reading logs or running a noisy test suite can fill your context with output you will never look at again. In a subagent, that noise stays in its window, not yours.
The catch: a subagent starts with no memory of your conversation. It does not see what you discussed or which files Claude already read. Claude writes it a briefing, and it works from that.
Lesson notes: Subagents: hand off side tasks cleanly
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You write a read-only reviewer subagent, run it, and know when a task should be delegated.
Step 1 of 7 · Read
What a subagent is
A subagent is a separate Claude worker with its own fresh context window, its own instructions and its own tool limits. Claude hands it a task, it does the work, and only a summary comes back to your main conversation.
That last part is the point. Searching a big codebase, reading logs or running a noisy test suite can fill your context with output you will never look at again. In a subagent, that noise stays in its window, not yours.
The catch: a subagent starts with no memory of your conversation. It does not see what you discussed or which files Claude already read. Claude writes it a briefing, and it works from that.
Step 2 of 7 · Read
The ones that come built in
Explore is a fast, read-only agent for searching and understanding code. Plan is a read-only researcher used while Claude prepares a plan. general-purpose has the full tool set for multi-step jobs that need to both look and act. There are also small helpers such as claude-code-guide, which answers questions about Claude Code itself (checked 18 November 2026).
Claude picks these on its own when a task suits them. You can also ask directly:
use a subagent to find every place we call the payments API and list the files.Step 3 of 7 · Read
Write your own
A custom subagent is a Markdown file with YAML frontmatter. Save it in
.claude/agents/to share it with the project, or~/.claude/agents/to have it in every project. Onlynameanddescriptionare required. Write the description as when to use it, because that is what Claude reads when deciding to delegate.toolsis an allowlist: leave it out and the subagent inherits every tool.disallowedToolsremoves tools instead.modeltakessonnet,opus,haiku,fable, a full model ID orinherit. Other useful fields:maxTurns,permissionMode,background: true, andisolation: worktreeto give it its own git checkout.The
/agentscommand now just points you to those two folders (checked 18 November 2026), so create the file yourself or ask Claude to write it..claude/agents/code-reviewer.md --- name: code-reviewer description: Reviews recent code changes for bugs, security and readability. Use after any non-trivial change. tools: Read, Glob, Grep model: sonnet --- You are a careful code reviewer. Read the changed files, then report: 1. Bugs or risky logic, with file and line 2. Security concerns 3. Readability fixes worth making Be specific. Do not rewrite the code yourself.
Step 4 of 7 · Read
Three ways to call it
Ask in plain words:
use the code-reviewer subagent on the auth changes. Mention it: type@and pick it from the list, or type@agent-code-reviewer. Run a whole session as it: start Claude Code withclaude --agent code-reviewer.Subagents can start their own subagents, up to three levels below your main conversation by default. To stop a subagent delegating further, leave
Agentout of itstoolslist.Step 5 of 7 · Quiz
Check your understanding
You want a reviewer subagent that can read code but can never change it. What actually enforces that?
- Writing "never edit files" in its description
- Setting model: haiku
- Setting tools: Read, Glob, Grep in its frontmatter
- Setting permissionMode: bypassPermissions
Show the answer
Setting tools: Read, Glob, Grep in its frontmatter With an allowlist that has no Edit, Write or Bash, the subagent has no way to change files.
Step 6 of 7 · Sort
Delegate or keep it in the main session?
Pick where each job belongs.
- Search 400 files for every use of a deprecated function
- Tweak a button colour, look, tweak again
- Run the full test suite and summarise only the failures
- Plan, build and test one feature that shares a lot of context
- Review a change with a reviewer that must not edit anything
- Rename one variable in the file you are both looking at
Show the answers
- Search 400 files for every use of a deprecated function: Subagent. Lots of output you will not reread. Let a subagent search and return the list.
- Tweak a button colour, look, tweak again: Main conversation. Quick back and forth works best where the context already is. A fresh subagent would start cold each time.
- Run the full test suite and summarise only the failures: Subagent. Test output is verbose. The summary is all you need back.
- Plan, build and test one feature that shares a lot of context: Main conversation. Each phase builds on the last. Splitting it means re-explaining everything.
- Review a change with a reviewer that must not edit anything: Subagent. A subagent can carry its own tool restrictions. Your main session keeps its usual tools.
- Rename one variable in the file you are both looking at: Main conversation. Small and targeted. Delegating adds start-up time for no gain.
Step 7 of 7 · Try it in the terminal
Start a session as your reviewer
You saved code-reviewer.md in .claude/agents. Start Claude Code so the whole session runs as that subagent, with its prompt and tool limits.
Hint: claude, then the flag that names an agent, then its name.
Show the command
$ claude --agent code-reviewer Claude Code Agent: code-reviewer · tools: Read, Glob, Grep · model: sonnet >