Skills with Subagents
A skill does not have to do everything itself. With the Task tool enabled in allowed-tools, your skill becomes an orchestrator — it spawns parallel child Claude instances, each handling one subtask, then collects and synthesises their output.
What is a subagent?
In Claude Code, a subagent is a separate Claude instance that your orchestrating skill spawns to handle one specific piece of work.
| Property | Behaviour |
|---|---|
| Runs independently | Does not share memory with the orchestrator or other subagents |
| Runs in parallel | Multiple subagents work at the same time, saving wall-clock time |
| Returns a result | Sends its output back to the orchestrator when done |
| Has a narrow focus | Given a single well-defined task, not the whole problem |
How it works
| Step | What happens |
|---|---|
| 1 | You invoke the skill (e.g. /research "React Server Components") |
| 2 | Orchestrator Claude reads SKILL.md and sees allowed-tools: [Task] |
| 3 | Orchestrator spawns subagents in parallel — e.g. docs, community, comparisons |
| 4 | All subagents complete; orchestrator receives their text output |
| 5 | Orchestrator synthesises findings into one structured report |
The key ingredient: allowed-tools
By default, skills do not have access to any tools. To enable subagents, add Task to the allowed-tools list in the frontmatter. Add any other tools your subagents will need too.
No subagent access
--- name: research description: Research a topic. --- ## Steps 1. Research the topic.
Subagents enabled
--- name: research description: Research a topic. allowed-tools: - Task - WebSearch --- ## Steps 1. Spawn subagents via the Task tool.
Example 1 — /research
A single command spawns three subagents in parallel — one per angle — then returns one synthesised report. Without subagents this would require three separate conversations.
--- name: research description: > Research a topic using three parallel subagents. Usage: /research <topic> Example: /research "React Server Components" Outputs a structured summary covering docs, community, and comparisons. allowed-tools: - Task - WebSearch --- ## Role You are a research coordinator. Delegate subtasks to subagents, then synthesise their results into one clear report. ## Steps 1. Read the topic the user provides after the command. 2. Spawn three subagents in parallel using the Task tool: - Subagent A: Search official documentation and specs. - Subagent B: Search community discussions, blog posts, and tutorials. - Subagent C: Find comparisons with alternative approaches. 3. Wait for all three subagents to return. 4. Synthesise the results into one report. ## Output format ### Overview One paragraph summary. ### Key findings - Bullet per important finding (source: A/B/C) ### Comparisons Short table if relevant. ### Recommended next step One sentence. ## Constraints - Do not add findings that subagents did not return. - Keep the total output under 600 words.
Example 2 — /audit
Review every TypeScript file in a directory by spawning one dedicated subagent per file. Each subagent reads only its file and reports findings independently. The output format ends with a Summary: line — that is part of the skill output, not this lesson.
---
name: audit
description: >
Audit every TypeScript file in a directory for issues.
Usage: /audit <directory>
Example: /audit src/api
Spawns one subagent per file; collects and ranks all findings.
allowed-tools:
- Task
- Read
- Bash
---
## Context
- Date: $CURRENT_DATE
- Files: $(find ${directory} -name "*.ts" | head -20)
## Steps
1. Read the file list from context.
2. For each file, spawn a subagent with the Task tool:
- Give the subagent the file path.
- Ask it to list Critical, Warning, and Suggestion findings.
3. Collect all subagent results.
4. De-duplicate overlapping findings.
5. Rank by severity: Critical first.
## Output format
## Audit — ${directory}
For each file with findings:
### filename.ts
- [Critical]: description
- [Warning]: description
- [Suggestion]: description
## Summary
X critical, Y warnings, Z suggestions across N files.Audit — src/api
auth.ts
[Critical] jwt.verify does not check expiry
[Warning] process.env.SECRET is not guarded at startup
middleware.ts
[Warning] rate-limiter applied after auth check
[Suggestion] extract token extraction into a shared helper
helpers.ts · tokens.ts
No critical or warning findings.
Summary: 1 critical, 2 warnings, 1 suggestion across 4 files
Best practices
- Give each subagent one job — narrow tasks return more accurate results than broad instructions.
- Do not nest subagents — keep the hierarchy to one level: orchestrator spawns subagents only.
- Only request tools subagents need — unnecessary tool access increases risk and slows the run.
- Collect, then synthesise — the final Step must combine subagent results into one report.
- Keep subagent count reasonable — 2–5 subagents is a sweet spot; more than 10 can hit rate limits.
When to use subagents vs a single skill
| Situation | Use subagents? | Why |
|---|---|---|
| Multiple independent search queries | Yes | Queries have no dependency; parallel is faster |
| Review N files independently | Yes | Each file is self-contained; one subagent per file is clean |
| Sequential steps (A depends on B) | No | Subagents cannot share state; orchestrate sequentially instead |
| One focused transformation task | No | A single Claude invocation is faster and simpler |
| Tasks needing shared memory | No | Subagents are isolated — use a single skill with context instead |
| Gathering data from multiple sources | Yes | Each source is independent; parallelism cuts total time |
Before you continue
- Add
Tasktoallowed-toolsto enable subagent spawning in Claude Code. - Orchestrator skills delegate parallel work, then synthesise results into one report.
- Use subagents for independent parallel tasks — not sequential or shared-memory work.
- Keep subagent count to 2–5 and give each one a narrow, specific job.
- Next lesson: Share and Distribute Skills.
What's Next
Sub-agents extend what a single skill can do. Next: packaging and sharing skills with your team.