sub-agent-delegation
Delegate work to sub-agents via the Task/Agent tool — parallel research, isolated context windows, specialized expertise. Covers when sub-agents help vs hurt, prompt shape, and result handling. Use this skill when building agents that need to research in parallel, process independent work items, or isolate context-heavy sub-tasks. Activate when: sub-agents, Task tool, Agent tool, parallel agents, agent delegation, spawn agent, multi-agent.
What this skill does
# Sub-Agent Delegation
**Sub-agents are isolated agent invocations spawned from a parent. They run in a fresh context, do focused work, and return a single result. Use them to parallelize, specialize, and protect context.**
## When to Use
- Parallel research (5 topics × 1 agent each, run concurrently)
- Context-heavy sub-tasks that would bloat the parent's window
- Specialist work (a "code reviewer" sub-agent, a "security auditor" sub-agent)
- Independent work items where errors shouldn't compound
## When NOT to Use
- Trivial single-step tasks — sub-agent overhead isn't worth it
- Tasks that need to see the parent's full context — you'll have to pass it, defeating the isolation
- Highly interactive work — sub-agents don't ask clarifying questions back
## The Model
Parent agent sees a `Task` (or `Agent`) tool. When invoked, it spawns a sub-agent with:
- A fresh conversation (no parent history)
- Its own tool set (may be a subset of parent's)
- A single prompt describing the work
- A requirement to return ONE final response
The sub-agent's intermediate tool calls are NOT visible to the parent — only the final result.
## SDK Usage
```ts
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const msg of query({
prompt: "Research and compare the top 3 vector databases. Summarize pros/cons.",
options: {
model: "claude-sonnet-4-6",
allowedTools: ["Task", "WebFetch", "Read"],
},
})) { /* ... */ }
```
The parent agent decides to invoke `Task` with a prompt like "Research Pinecone's pros and cons. Use WebFetch. Report in under 200 words." Three parallel Task calls, three independent contexts, three summaries returned.
## Parallel Spawning
The parent can issue multiple tool calls in one step:
```
Parent: Let me research all three in parallel.
[tool_use: Task] Research Pinecone...
[tool_use: Task] Research Weaviate...
[tool_use: Task] Research Qdrant...
```
Three sub-agents run concurrently. Parent waits for all three results, then synthesizes.
## Prompt Shape for Sub-Agents
Sub-agents start with nothing. Prompt them like a smart colleague who just walked in:
1. State the goal
2. Give enough context to make judgment calls
3. Specify output format and length
4. List what's in scope vs out of scope
**Bad prompt:** "Find info about Pinecone"
**Good prompt:** "Research Pinecone as a vector DB for a 10M-vector production workload. Find pricing, latency at 10M scale, clustering support, filtering support. Report as a 200-word summary with bullet points for each metric. Do not cover marketing fluff."
## Handling Sub-Agent Results
```ts
hooks: {
PostToolUse: async ({ toolName, output }) => {
if (toolName === "Task") {
await db.logDelegation({ prompt: output.prompt, result: output.result });
}
},
}
```
Log every delegation. Sub-agents can fail, loop, or hallucinate like any agent — audit them.
## Context Economics
Sub-agents cost extra — they run a full model inference. But they save parent tokens:
- Without sub-agent: parent processes full raw research → 50K tokens in context
- With sub-agent: parent sees 500-word summary → 500 tokens in context
Net: you pay more compute, save context window for reasoning. Worth it when parent is doing long reasoning on top of research.
## Specialization Pattern
Create multiple agent "personas" — each a sub-agent type with specialized prompts and tools:
```ts
// Parent system prompt:
"You orchestrate work across:
- 'researcher' sub-agents (WebFetch, Read) for gathering info
- 'reviewer' sub-agents (Read, Grep) for code review
- 'writer' sub-agents (Read, Write) for drafting
Delegate to the right one based on the task."
```
The parent plans; specialists execute.
## Sub-Agent Error Handling
A sub-agent can return errors:
- "I couldn't find relevant info" — retry with refined prompt or move on
- "The tool I need isn't available" — parent decides alternative
- Silent bad output — parent should verify critical results before using
Always have the parent sanity-check sub-agent output before passing to user.
## Limits
- No nested delegation by default — sub-agents don't spawn sub-sub-agents (prevents runaway chains)
- Sub-agent budget tokens come from parent's budget
- Too many parallel sub-agents can rate-limit you
- Sub-agents can't communicate with each other — only through the parent
## Anti-Patterns
1. **Delegating trivial work** — sub-agent spin-up costs more than the task
2. **Needing the parent's context** — passing full history to sub-agent defeats purpose
3. **Sub-agent that returns "the full details"** — parent gets a firehose; should return a summary
4. **No log of delegations** — can't debug when something went wrong
5. **Unbounded parallel spawn** — 50 sub-agents = 50× rate limit consumption
## Best Practices
1. Use sub-agents for research, context isolation, specialist work
2. Prompt them self-contained — they have no prior context
3. Require summarized output (word limit)
4. Parallelize independent work; sequentialize when dependencies exist
5. Log every delegation with prompt and result
6. Cap parallel spawn count (e.g., max 5 concurrent)
7. Have parent verify critical sub-agent output before acting on it
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.