What Is a Sub-Agent? — Delegating Work to Team Members
A team lead doesn’t do everything alone, right? Simple tasks get delegated: “handle this and just give me the result.” Meanwhile, the lead works on other things.
Claude Code works the same way. The main Claude (team lead) creates sub-agents (team members) to handle tasks and receive results. That’s the Agent tool.
| Company | Claude Code |
|---|---|
| Team lead | Main Claude (the one you're chatting with) |
| Team member | Sub-agent (created via Agent tool) |
| "Organize this report for me" | "Analyze this file and summarize it" |
| Team member delivers results | Sub-agent returns results |
| Lead works on something else meanwhile | Main Claude continues other tasks |
Sub-agents are created automatically by the main Claude. You don’t need to create them yourself. If you say “analyze this folder,” Claude determines it’s complex enough and spins up sub-agents automatically.
How Sub-Agents Are Created
"Analyze the README and summarize it"
"This would be more efficient to handle separately"
A new Claude instance spins up to focus on that task
When the sub-agent finishes, results go back to the main Claude
Key Characteristics
🕵
Independent Execution
Sub-agents work in their own context without affecting the main conversation.
🚀
Parallel Processing
Multiple sub-agents can run simultaneously. Analyzing 5 files at once is possible.
📦
Results Only
What the sub-agent did in between doesn’t matter. Only the final result comes back to the main Claude.
💡
Auto-Created
You don’t need to create them. Claude decides when needed and creates them automatically.
Analyze all TypeScript files in the src folder
and summarize each file's role in one line.
# If there are many files, Claude automatically spawns
# sub-agents to analyze them in parallel.One-line summary
Sub-agent = Main Claude’s team member. Handles complex tasks in pieces and reports back. You just give instructions.
What Are Agent Teams? — Building a Project Team
If sub-agents are “delegating to one team member,” Agent Teams are “assembling an entire project team.” The lead distributes work and multiple members work simultaneously.
Think of a product launch: designer handles design, developer handles code, marketer handles promotion — all at once. Agent Teams work the same way.
| Project Team | Agent Team |
|---|---|
| Team assembly meeting | Lead creates team members (independent sessions) |
| Task distribution | Tasks distributed via shared task list |
| Communication between members | Members exchange direct messages |
| Each works on their part | Agents work in parallel simultaneously |
| Compile results | Lead consolidates results |
How Agent Teams Work
Request in natural language like "create a team of 3" and the lead creates member sessions.
Lead creates tasks, members pick them up and work on them.
Members exchange messages to share info and coordinate.
All members work simultaneously in independent sessions, lead collects results.
Create an agent team to refactor this project.
- 1 person for TypeScript conversion
- 1 person for Tailwind migration
- 1 person for test code
Work on everything simultaneously.
# You need to explicitly request "create an agent team."
# Claude may suggest a team, but you must approve it.When are Agent Teams available?
Agent Teams are currently an experimental feature. Disabled by default — you need to enable it in settings. When you request a team-sized task, Claude suggests a team composition and you approve it. It won’t create teams automatically.
Agent Team = Your Own Project Team
You (the lead) give instructions, and team members (agents) work simultaneously
When Do You Need a Team?
Not every task needs an Agent Team. Simple tasks need just one sub-agent; only large-scale work needs a team. The distinction is simple.
Sub-agent is enough when
Focused task needing results only
“Fix the bug in this function”
Independent task
“Analyze this file and summarize it”
Agent Team needed when
Discussion/collaboration required
“Review from security, performance, and testing perspectives simultaneously”
Exploring multiple hypotheses at once
“Investigate the bug cause from multiple angles simultaneously”
Real Scenarios Where Agent Teams Shine
🔍
Multi-Angle Research & Review
Security, performance, and test coverage reviewed simultaneously by different members who share findings.
🛠
New Module/Feature Development
Frontend, backend, and tests worked on independently and simultaneously by different members.
🐛
Competing Hypothesis Debugging
Test multiple hypotheses about a bug cause simultaneously; members verify each other’s hypotheses.
🌐
Cross-Layer Work
Changes spanning frontend, backend, and tests coordinated simultaneously by dedicated owners.
Sub-agents are automatic, teams require requests
Sub-agents are created automatically by Claude. But Agent Teams require you to request “create a team for this.” Claude may suggest a team, but it won’t form one without your approval.
Creating Custom Agents — Your Own Expert Team
So far, Claude created sub-agents automatically. But you can go further: pre-define your own experts.
Having a dedicated “code review specialist” on your team would be handy, right? In Claude Code, you can create custom agents that handle specific roles.
How to Create — Just One File
Create a .claude/agents/ folder in your project and add a markdown file (.md) inside. The filename becomes the agent name.
my-project/
├── .claude/
│ └── agents/
│ ├── code-reviewer.md ← Code review expert
│ ├── doc-writer.md ← Documentation expert
│ └── deploy-expert.md ← Deployment expert
├── src/
└── package.jsonWriting an Agent File
Add YAML frontmatter for settings, then describe the agent’s role and rules in the body. Required fields are name and description. The description is what Claude uses to decide “when to invoke this agent.” Optionally specify tools and model.
---
name: code-reviewer
description: Reviews code changes and finds bugs, security vulnerabilities, and improvement opportunities.
tools: Read, Grep, Glob, Bash
model: sonnet
---
# Code Reviewer
## Role
- Thoroughly review code changes
- Find potential bugs
- Check security vulnerabilities
- Suggest performance improvements
## Rules
- Always specify file names and line numbers
- Classify severity in 3 levels (High/Medium/Low)
- Provide code examples with fix suggestions
- Always mention positive aspects too---
name: doc-writer
description: Analyzes code and writes README, API docs, and usage guides.
tools: Read, Grep, Glob
model: haiku
---
# Documentation Writer
## Role
- Read code and write clear documentation
- Auto-generate and update README.md
- Document API endpoints
- Write installation/usage guides
## Rules
- Write in English (keep code terminology as-is)
- Accessible to non-developers
- Always include runnable code examples
- Markdown format with table of contents---
name: deploy-expert
description: Deploys projects to Vercel, GitHub Pages, etc. and sets up CI/CD.
---
# Deployment Expert
## Role
- Build and deploy projects
- Set up CI/CD pipelines
- Manage environment variables
- Post-deployment verification
## Rules
- Always run build tests before deploying
- Environment variables managed only in .env
- Verify the actual URL after deployment
- Include rollback instructionsDescription Is the Key to Invocation
The description line is the most important. Claude reads it to decide “should I invoke this agent?” Like reading a job description to assign the right person.
Good description
Reviews code changes and finds bugs, security vulnerabilities, and improvement opportunities. — Clear when to invoke.
Bad description
A useful helper. — Too vague for Claude to know when to invoke.
2 Ways to Use Custom Agents
1. Auto-invocation
When you request a task matching the description, Claude automatically invokes the agent.
Review this PR.
# Claude auto-invokes the code-reviewer agent.2. Named invocation
Mention the agent name directly in conversation.
Use the code-reviewer sub-agent to review this commit.
# code-reviewer agent is directly invoked.Practical custom agent ideas
Report Writer — Analyzes data and creates HTML reports.
Translator — Translates code comments and documentation.
Test Expert — Auto-generates tests matching the code.
Refactoring Expert — Cleans up and reorganizes code.
Sub-Agent vs Agent Team — Which to Use?
They look similar but serve different purposes. Here’s a quick comparison.
| Item | Sub-Agent | Agent Team |
|---|---|---|
| Analogy | Delegate to 1 team member | Assemble an entire project team |
| Structure | Runs within the main session | Each runs in an independent session |
| Communication | Reports results to main Claude only | Members exchange direct messages |
| Coordination | Managed by main Claude | Self-coordinated via shared task list |
| Activation | Claude creates automatically | User must request (experimental feature) |
| Token usage | Low (returns summary only) | High (each member is an independent instance) |
| Best for | Focused tasks needing results only | Complex tasks requiring discussion/collaboration |
Where Do Custom Agents Fit?
Custom agents are a type of sub-agent. Default sub-agents (Explore, Plan, etc.) are auto-created by Claude, while custom agents are pre-defined experts that Claude invokes. They’re separate from Agent Teams.
| Default Sub-Agent | Custom Sub-Agent | |
|---|---|---|
| Definition | Built into Claude (Explore, Plan, etc.) | Pre-defined by you in .md files |
| Specialization | General purpose (exploration, planning) | Specialized (role/rules/tools you specify) |
| Model choice | Automatic (Explore=Haiku, etc.) | You can specify (Haiku, Sonnet, Opus) |
| Reusability | Always available | Reusable at project or user level |
| Setup time | 0 seconds (built-in) | 5 minutes (one file, or /agents command) |
The bottom line is simple
Focused tasks = sub-agent (automatic). Tasks needing discussion/collaboration = Agent Team (request required). Frequently repeated expert tasks = custom sub-agent. Sub-agents are used automatically by Claude; just pre-create custom agents. Try Agent Teams for truly large tasks.
Focused = Sub-Agent • Collaborative = Team • Repeated = Custom
Sub-agents are automatic, Agent Teams require requests, custom agents are pre-built
Try It Yourself
Reading alone won’t click. Follow these exercises.
Exercise 1: Experience Sub-Agents (Easiest)
Run Claude Code in any project folder and enter this prompt. Watch Claude create sub-agents for parallel analysis.
Analyze all files in this project and
summarize what each file does in one line.
Organize as a table.If there are 5+ files, Claude auto-creates sub-agents. If you see “Agent” in the terminal, success!
Exercise 2: Create a Custom Agent
Build your own expert agent. Just tell Claude Code:
/agents
# → Select "Create new agent"
# → Choose User-level or Project-level
# → Describe the role and Claude auto-generates itCreate a report-writer.md file in .claude/agents/.
Role: Expert that analyzes data and creates beautiful HTML reports
Rules:
- Always include charts and tables
- Write in English
- Summarize key insights in 3 lines
- Clean design (gradient + card layout)/agents is the easiest method. Once the file exists, saying “analyze this CSV and create a report” auto-invokes this agent.
Exercise 3: Experience Agent Teams (Challenge, Experimental)
Agent Teams are experimental and must be enabled in settings first. Then try requesting a team.
Create an agent team to improve this project.
- One person for TypeScript conversion
- One person for documentation (README, CHANGELOG)
- One person for test code
Work simultaneously.To use Agent Teams, enable CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS in settings. Approve the team composition Claude suggests and observe how each member works.
Verification Checklist
If you didn’t see agents being created, the project may have too few files. Try with a project with 5+ files. Or create a mkdir test-project folder, ask Claude to generate 10 files first, then request analysis.
Tips + Sources
Practical tips for effective agent usage.
1. Be specific about scope
“Fix up this project” is too vague. “Convert all .js files in src to .ts and add types” produces much better results. Be specific when delegating to agents.
2. Build custom agents incrementally
No need to create 10 agents upfront. When you notice a repeated task, make an agent for it. Doing lots of code reviews? Create one code-reviewer.md.
3. Refine descriptions often
If a custom agent isn’t being invoked, or triggers at wrong times, edit the description. Claude judges by this single line, so clarity and specificity matter.
4. Watch token usage
Agent Teams run multiple Claudes simultaneously, consuming lots of tokens. If token limits are tight, break work into smaller tasks. Check usage with /cost.
5. Watch for file conflicts
Multiple agents editing the same file simultaneously can cause conflicts. Clearly separate work areas: “A handles frontend only, B handles backend only.”
6. Share custom agents with your team
Commit .claude/agents/ to Git and the whole team gets the same custom agents. Unify code review standards, documentation rules, etc.
| Mistake | Result | Solution |
|---|---|---|
| Vague description | Agent doesn't get invoked | Specific role + situation description |
| Too many agents | Claude gets confused | Keep to 5 or fewer core agents |
| Same file edited simultaneously | Code conflicts | Clearly separate work areas |
| Context limit exceeded | Sub-agent results get truncated | Consider switching to Agent Teams |
| Custom agents not in Git | Teammates can't use them | Commit .claude/agents/ folder |
AI Agent Team = Your Own Automation Department
Delegate simple work with sub-agents, handle large-scale work simultaneously with Agent Teams, and pre-deploy experts with custom agents.
Remember one thing
You are the “team lead.” Give instructions and Claude assembles the team, agents work simultaneously, and results come back to you. A lead delegates — they don’t do everything themselves. Practice delegating.
References
- Sub-Agents (Custom Subagents) — code.claude.com/docs/en/sub-agents
- Agent Teams (Experimental) — code.claude.com/docs/en/agent-teams
- Feature Comparison — code.claude.com/docs/en/features-overview