Delegates work to subagents using the Claude Agent SDK. Defines subagents with agents option, restricts tools, passes context, detects subagent messages, and caps depth/concurrency/spend.
Ships in agent-sdk. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A subagent is a separate agent instance the main agent spawns through the Agent tool. It starts with its own context, does focused work, and returns only its final report. Use it to isolate context, run independent work in parallel, specialize instructions, and restrict tools.
agents optionimport { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Review the authentication module for security issues",
options: {
allowedTools: ["Read", "Grep", "Glob", "Agent"],
agents: {
"code-reviewer": {
description: "Expert code review specialist. Use for quality, security, and maintainability reviews.",
prompt: "You are a code review specialist. Identify vulnerabilities and suggest specific fixes. Be concise.",
tools: ["Read", "Grep", "Glob"], // read-only
},
"test-runner": {
description: "Runs and analyzes test suites. Use for test execution and coverage analysis.",
prompt: "Run tests and explain failures clearly.",
tools: ["Bash", "Read", "Grep"],
},
},
},
})) {
if ("result" in message) console.log(message.result);
}
Python uses ClaudeAgentOptions(agents={"code-reviewer": AgentDefinition(description=..., prompt=..., tools=[...])}). Subagents can also be defined as Markdown files in .claude/agents/; programmatic definitions win on name conflicts. Claude can always use the built-in general-purpose subagent.
Key AgentDefinition fields (per docs): description and prompt (required), tools, disallowedTools, model (an alias such as "sonnet", "inherit", or a full ID), maxTurns, skills, mcpServers, background, effort, permissionMode. Some fields are TypeScript-only; check the reference for your SDK.
Claude chooses a subagent by matching the task to each description. Say when to use it, not just what it is. To force delegation, name the agent in the prompt: "Use the code-reviewer agent to check the auth module."
A non-fork subagent does not see the parent's conversation, tool results, or system prompt. It receives its own prompt, the Agent tool's prompt string, project CLAUDE.md (unless omitted), and its tool definitions. Put file paths, error messages, and decisions it needs into the delegation prompt. A fork (subagent_type: "fork") instead copies the conversation so far; deny it with disallowedTools: ["Agent(fork)"] if you do not want that.
Omit tools to inherit the tools available to subagents, or list only what the job needs. A tool left out is simply absent, with no prompt or error.
| Use case | Tools |
|---|---|
| Read-only analysis | Read, Grep, Glob |
| Test execution | Bash, Read, Grep |
| Code modification | Read, Edit, Write, Grep, Glob |
Permission modes interact with inheritance (for example, a plan-mode parent keeps subagents in plan mode); see the permissions page before relying on a subagent's own permissionMode.
Subagents are invoked through a tool_use block named "Agent"; older versions used "Task" (and the system init tools list still shows Task), so match both. Messages produced inside a subagent carry parent_tool_use_id. In TypeScript, assistant content is at message.message.content.
for (const block of (message as any).message?.content ?? []) {
if (block.type === "tool_use" && (block.name === "Agent" || block.name === "Task")) {
console.log("delegated to", block.input.subagent_type);
}
}
if ((message as any).parent_tool_use_id) console.log(" (inside subagent)");
Token-level stream events are not forwarded from subagents (see agent-sdk-streaming).
By default a spawned subagent can run in the background (the Agent tool result reports status: "async_launched") and its report arrives in a later turn; Claude waits when its next step needs the report. To resume a subagent, capture the session ID and the agentId from the Agent tool result, then resume the same session with the same agents definitions and reference the agent ID in the prompt.
Each subagent makes its own API requests, which count toward the query's cost, and subagents can spawn their own. Bound the tree:
| Limit | Setting |
|---|---|
| Nesting depth | CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH via the env option |
| Concurrent subagents | CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS via the env option |
| Total spend | maxBudgetUsd / max_budget_usd |
In TypeScript the env option replaces the subprocess environment, so spread process.env into it; Python merges it. These limits depend on recent SDK versions; check the subagents page for the minimums and defaults.
Agent and Task when detecting delegationWhat SKILL.md sets; muted values are Claude Code's defaults
5 skills in this plugin
/agent-sdk-quickstartBuild a first agent with the Claude Agent SDK (TypeScript or Python): install, run query(), read result messages, restrict tools and permissions, add custom tools through an in-process MCP server, and guard tool calls with hooks. Also explains when to pick the Agent SDK, the Client SDK, or Managed Agents.
Use this skill when starting a new agent project, migrating from a hand-written messages.create tool loop, or choosing between the Agent SDK, the Client SDK, and Managed Agents.
Activate when: Claude Agent SDK, @anthropic-ai/claude-agent-sdk, claude-agent-sdk, query(), ClaudeAgentOptions, createSdkMcpServer, build agent, agent SDK quickstart.
/agent-sdk-streamingStream Claude Agent SDK output to a UI: the default message flow, enabling partial messages with includePartialMessages / include_partial_messages, handling stream_event deltas for text and tool input, attributing subagent output, and handling cut-off streams.
Use this skill when building a chat or progress UI on top of the Agent SDK, showing tool activity live, or debugging missing or out-of-order streamed output.
Activate when: agent SDK streaming, includePartialMessages, include_partial_messages, stream_event, StreamEvent, SDKPartialAssistantMessage, text_delta, input_json_delta, real-time agent output.
Other plugins' skills for the same job
/agent-sdk:sub-agent-delegationfrom agent-sdk
npx claudepluginhub latestaiagents/agent-skills --plugin agent-sdk2 plugins in one repository ship this exact skill · first indexed Nov 5, 2026