What’s a subagent?

A specialized Claude instance with its own context window, custom system prompt, and specific tool access — useful for tasks like code review, testing, or research that would otherwise clutter your main conversation.

Steps to create one

Option A — Ask Claude to write it for you (recommended)

  1. In a Claude Code session, describe the subagent you want, e.g.:
    “Create a personal code-improver subagent in ~/.claude/agents/ that scans files and suggests improvements for readability, performance, and best practices. Make it read-only and have it use Sonnet.”
  2. Claude will generate the Markdown file with the right frontmatter (name, description, tools, model) and system prompt.
  3. Open the file it created and tweak anything you’d like.

Note: as of Claude Code v2.1.198+, the old /agents interactive wizard was removed. Running /agents now just reminds you to ask Claude directly or edit the files yourself — but the file format and locations are unchanged.

Option B — Write the file manually

  1. Create a Markdown file in one of these locations:
    • .claude/agents/your-agent-name.md → project-level (shared with your team via the repo)
    • ~/.claude/agents/your-agent-name.md → personal, available across all your projects
  2. Add YAML frontmatter + a system prompt body. Example:

markdown

---
name: code-reviewer
description: Expert code review specialist. Use PROACTIVELY after code changes to check security, style, and maintainability.
tools: Read, Grep, Glob, Bash
model: sonnet
---
You are a senior code reviewer. When invoked:
1. Run `git diff` to identify modified files.
2. Focus review on changed code paths.
3. List security issues, likely false positives, and suggested fixes.
4. Provide a short, prioritized action list.
  1. Restart your Claude Code session — subagent files are loaded only at startup, so edits on disk won’t take effect until you restart. (Agents created via asking Claude in a live session take effect immediately.)

Key frontmatter fields

FieldPurpose
nameUnique identifier
descriptionThis is what triggers delegation — Claude matches tasks against it, so write it as a clear condition for use (e.g. “Use PROACTIVELY after writing code”)
toolsRestrict which tools the subagent can access (e.g. Read, Grep, Glob for a read-only reviewer)
modelsonnet, opus, haiku, or inherit (uses parent’s model)

Using it

  • Let Claude auto-delegate based on the description matching your request, or
  • Invoke explicitly: claude -p "Use the code-reviewer subagent to review payment.py"

Claude Code also ships with built-in subagents (Explore, Plan, general-purpose) that it uses automatically without you needing to configure anything.

Conclusion

Subagents are one of the most practical upgrades you can make to your Claude Code workflow. By delegating token-heavy, repetitive, or specialized tasks — like code review, testing, or codebase exploration — to a dedicated subagent, you keep your main conversation focused and your context window clean.

Getting started is simple: describe what you want to Claude and let it generate the subagent for you, or hand-write a Markdown file with the right YAML frontmatter in .claude/agents/ or ~/.claude/agents/. From there, it’s just a matter of refining the description field so Claude knows exactly when to delegate, and restricting tools and model choices to match the task at hand.

Start small — one or two subagents for your most repetitive tasks — and expand as you find more workflows worth isolating. Once you experience how much cleaner and faster your sessions become, it’s hard to go back to a single generalist agent handling everything.

Fediverse reactions

Leave a Reply

Discover more from Srinimf

Subscribe now to keep reading and get access to the full archive.

Continue reading