Workbranch › Guides

Guide

How to use subagents in Claude Code

Long searches and noisy test output fill up your Claude Code conversation fast. Subagents take that work into a separate context and hand back a summary. This guide explains what they are, how to make your own, and when they are worth it.

Updated 30 October 2026

Quick answer: a subagent is a specialized helper that Claude Code hands a task to. It works in its own context window with its own instructions and tool access, then returns only a result. To create one, save a Markdown file with a name and description in its frontmatter to .claude/agents/ (one project) or ~/.claude/agents/ (all projects), then ask Claude to use it by name or pick it with @.

Details below come from Anthropic's Claude Code documentation as of October 2026. Claude Code changes often, so run claude update if something described here is missing.

What subagents are

When Claude meets a task that matches a subagent's description, it can delegate it. The subagent starts fresh: it does not see your conversation, only the instructions Claude passes along. It does its work, such as reading dozens of files or running a test suite, and sends back a summary. Your main conversation stays short.

Claude Code ships with built-in subagents, including:

You don't have to set these up; Claude uses them when they fit.

Create your own subagent

  1. Decide the scope. For a subagent the whole team can use in one repository, create the folder .claude/agents/ in the project. For one that follows you across projects, use ~/.claude/agents/.
  2. Create a Markdown file in that folder, for example code-reviewer.md.
  3. Start the file with frontmatter between two --- lines. The first line of the file must be ---.
  4. Add the two required fields: name (a unique identifier, for example code-reviewer, without a colon) and description (when Claude should use it, for example Reviews code for quality and best practices. Use after code changes.).
  5. Optionally add tools to limit what it can use, for example Read, Glob, Grep for a read-only reviewer, and model (a model alias such as sonnet or haiku, a full model ID, or inherit).
  6. Below the closing ---, write the subagent's instructions in plain language: its role, what to check, and what to return.
  7. Save the file. Claude Code picks up changes in an existing agents folder within seconds; if you created the folder during the session, restart Claude Code.

You can also just ask Claude in a session to create a subagent for you. In current versions, the /agents command points you to exactly that, or to editing the folders directly.

Use a subagent

When subagents help, and when they don't

Anthropic's guidance boils down to this:

Use a subagent whenStay in the main conversation when
The task produces lots of output you don't need to keep, like logs or search resultsYou need frequent back-and-forth
You want to restrict which tools can be usedSeveral steps share a lot of context
The work is self-contained and can end in a summaryIt's a quick, targeted change
You want independent research to run in parallel

Good to know

If it doesn't work

Keep the results, not just the summary

A subagent's report ends up in your session, which is gone from view once the session closes. With the Workbranch plugin for Claude Code, saying "save this to Workbranch" files the tasks, decisions and open questions from the session into a project, and the next session in that folder starts with what is still open. See Workbranch for Claude. If a session ran out of room, resuming a Claude Code session covers how to get back in.

Sources

Frequently asked questions

Do subagents use extra usage?

Subagent requests count toward the same usage limits as your main conversation. Routing simple work to a cheaper model such as Haiku through the model field can keep costs down.

Can a subagent start its own subagents?

Yes, by default up to three levels below the main conversation. To stop one particular subagent from doing so, leave Agent out of its tools list.

Can I run a whole session as a subagent?

Yes. Start Claude Code with claude --agent followed by the subagent's name, and the session uses that subagent's prompt, tools and model.