← Claude Docs

Subagents in the SDK - Claude Code Docs

Claude Docs · April 21, 2026
Subagents are separate agent instances that main agents can spawn to handle specialized subtasks with isolated context, parallel execution, and tool restrictions. Defined programmatically through an agents parameter or as markdown files, subagents are automatically invoked by Claude based on their descriptions or explicitly called by name. Subagents can be resumed to continue previous work, with their transcripts persisting independently from the main conversation while retaining their conversation history across sessions.

Detailed Analysis

Anthropic's Claude Agent SDK introduces a subagent architecture that allows a primary agent to spawn isolated, specialized agent instances for handling discrete subtasks within complex workflows. The SDK supports three methods of subagent creation: programmatic definition via the `agents` parameter in TypeScript or Python, filesystem-based definition using Markdown files stored in `.claude/agents/` directories, and a built-in general-purpose subagent invocable at any time through the Agent tool. The programmatic approach is recommended for SDK applications and exposes a rich `AgentDefinition` configuration schema that allows developers to specify system prompts, permitted tools, model overrides, reasoning effort levels, memory sources, MCP server access, and execution modes — including a `background` boolean for non-blocking task delegation. Each subagent runs in a fully isolated context window, receiving only its own system prompt, project-level CLAUDE.md content, and the specific prompt string passed by the parent agent, with no access to the parent's conversation history or tool results.

The architecture's core value proposition rests on three capabilities that are difficult to achieve in single-agent designs: context isolation, parallelization, and specialized instruction sets. Context isolation ensures that token-intensive operations — such as crawling dozens of files during a research task — do not pollute the main agent's context window, since only the subagent's final output is returned to the parent. Parallelization enables multiple subagents to execute concurrently, which the documentation illustrates with a code review scenario where style-checking, security scanning, and test coverage analysis can run simultaneously rather than sequentially. Tool restriction provides a security and scope-bounding mechanism: a documentation reviewer, for instance, can be configured with access only to `Read` and `Grep` tools, eliminating any risk of inadvertent file modification. Together, these features allow developers to architect workflows that more closely resemble professional team structures — such as a product specification agent handing off to an architect agent, which in turn delegates to an implementer — rather than monolithic prompt engineering exercises.

The SDK's subagent system reflects a broader industry shift toward hierarchical and orchestrated AI agent patterns, a trend that has accelerated significantly across the AI development ecosystem entering 2026. The renaming of the tool from "Claude Code SDK" to "Claude Agent SDK" in September 2025 signaled Anthropic's explicit intent to position the framework for general agentic use well beyond its original code-editing context. The `effort` parameter — ranging from `low` to `max` or a numeric value — and the `model` override field reveal a cost-optimization strategy baked into the architecture: computationally expensive reasoning can be reserved for complex parent-agent decisions, while simpler subagents run on lighter, cheaper models. This layered resource allocation mirrors practices common in distributed computing systems and suggests Anthropic is designing for production-scale deployments where inference costs are a meaningful operational concern.

The explicit prohibition on nested subagent spawning — subagents cannot themselves invoke the Agent tool — represents a deliberate architectural constraint rather than a technical limitation. By preventing recursive delegation, Anthropic limits the surface area for runaway agent trees, unintended tool chaining, and difficult-to-audit execution graphs. This constraint aligns with the company's broader emphasis on predictability and safety in agentic systems, and it positions the current subagent model as a two-tier hierarchy: one orchestrating parent and one layer of specialized workers. The guidance to serialize high-risk tasks while parallelizing safe ones further reinforces this safety-conscious design philosophy, encouraging developers to treat task orchestration not as a purely performance optimization problem but as a risk management exercise. As agentic frameworks from competing organizations such as OpenAI, Google DeepMind, and open-source communities continue to mature, Anthropic's structured, permission-scoped approach to multi-agent coordination represents a distinctive — if deliberately constrained — design stance in the rapidly evolving landscape of production AI systems.

Read original article →