Claude Code Subagents

A long session fills Claude Code's memory with search results, file contents, and side discussions. Subagents protect that memory. A subagent is a specialist helper that takes a task, works in its own separate space, and returns only a short summary. The main conversation stays clean and focused.

The Research Assistant Idea

A manager asks an assistant to study twenty reports and report back. The assistant reads everything and delivers a one-page summary. The manager never wades through the twenty reports. Subagents give Claude Code the same help.

MAIN CONVERSATION
      │  "Find every place that handles payments"
      ↓
 ┌─────────────────────────┐
 │ SUBAGENT (own workspace)│
 │ reads 40 files          │
 │ searches the code       │
 └───────────┬─────────────┘
             ↓
   Short summary returns to the main chat

Why Use Subagents

  • Clean context: bulky exploration stays outside your main conversation.
  • Focus: each helper carries instructions for one job.
  • Safety: a helper can receive only the tools it needs, such as read-only access.
  • Consistency: a saved helper behaves the same way every time.

Built-In and Custom Helpers

Claude Code ships with built-in helpers for jobs such as exploring a codebase. Custom subagents add your own specialists. Run /agents to view, create, and edit them through a guided menu.

Anatomy of a Subagent File

A subagent is a Markdown file stored in .claude/agents/ for a project or ~/.claude/agents/ for every project. A short header describes the helper. The body holds its instructions.

---
name: code-reviewer
description: Reviews code changes for bugs and unclear names.
  Use after any significant edit.
tools: Read, Grep, Glob
---
You are a careful code reviewer.
Check the changed files for bugs, unclear names, and missing tests.
Report findings as a list, ordered from most to least serious.

Understanding the Header

FieldPurpose
nameShort identifier for the helper
descriptionTells Claude Code when to call the helper
toolsLimits which tools the helper may use
modelOptional; picks a faster or stronger model for the job

The description matters most. Claude Code reads it to decide when delegation makes sense. A clear description such as "Use after any significant edit" triggers the helper at the right moment.

Calling a Subagent

Automatic delegation happens when a task matches a description. Direct requests work too. Type "Use the code-reviewer subagent to check my latest changes" and Claude Code hands the work over.

Good Subagent Ideas

  • A reviewer that checks style and bugs.
  • A test writer that creates tests for new functions.
  • A security checker with read-only tools.
  • A documentation writer that updates README files.
  • A debugger that traces error messages to their source.

Habits for Better Results

Narrow the Job

A helper with one clear purpose outperforms a helper asked to do everything.

Limit the Tools

Give reviewers read-only tools. Fewer powers mean fewer accidents.

Share Through Git

Commit project subagents so teammates inherit the same specialists.

A Delegation Scenario

A developer asks, "Where does our app send emails, and which templates does it use?" Claude Code hands the question to an exploring helper. The helper opens many files, follows the trail, and returns a short answer with file names. The developer sees a clean summary and keeps the main conversation free for the real work. The same task without a helper would flood the chat with search output.

Key Points

  • A subagent works in a separate space and returns a summary.
  • Subagents keep the main conversation clean.
  • Markdown files in .claude/agents/ define custom helpers.
  • The description field controls when Claude Code delegates.
  • Tool limits make helpers safer.