Skip to content

Cheatsheet: Subagents and Claude Managed Agents

Verbatim: Subagents are separate agent instances that your main agent can spawn to handle focused subtasks. Use subagents to isolate context for focused subtasks, run multiple analyses in parallel, and apply specialized instructions without bloating the main agent’s prompt.

Four benefits: context isolation (only the final message returns to the parent), parallelization, specialized instructions, tool restrictions.

PathWhere definedWhen to use
Programmaticagents parameter on SDK query() callRecommended for SDK applications
Filesystem-basedMarkdown files in .claude/agents/Claude Code projects; team-shared via Git
Built-in general-purposeNone (always available)Quick delegation without defining a subagent

Parent must include Agent in allowedTools to auto-approve subagent invocations.

FieldRequiredDescription
descriptionYesRouting signal Claude reads to decide whether to delegate
promptYesSubagent’s system prompt
toolsNoAllowed tool names; if omitted, inherits all parent tools
disallowedToolsNoTool names to remove from the inherited set
modelNoAlias (sonnet, opus, haiku, inherit) or full ID; cost lever per L3
skillsNoL10 Agent Skills to preload
memoryNoMemory source (user / project / local)
mcpServersNoL6 MCP servers
maxTurnsNoPer-subagent iteration cap (L8 discipline)
backgroundNoNon-blocking background task
effortNoL3’s effort dial per subagent
permissionModeNoTool-execution permission policy

Constraint: subagents cannot spawn their own subagents. Do NOT include Agent in a subagent’s tools array.

from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition
async for message in query(
prompt="Review the authentication module for security issues",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Grep", "Glob", "Agent"],
agents={
"code-reviewer": AgentDefinition(
description="Expert code review specialist.",
prompt="You are a code review specialist...",
tools=["Read", "Grep", "Glob"], # read-only
model="sonnet", # smaller model for cost
),
},
),
):
if hasattr(message, "result"):
print(message.result)
ReceivesDoes NOT receive
Own system prompt + Agent tool’s prompt string from parentParent’s conversation history or tool results
Project CLAUDE.md (via settingSources)Preloaded Skill content (unless listed in AgentDefinition.skills)
Tool definitions (inherited or subset in tools)Parent’s system prompt

Only channel from parent: the Agent tool’s prompt string. Include any file paths, error messages, or decisions the subagent needs in that prompt.

L9 patternHow Subagents realize it
L9.3 Parallelization (sectioning)Concurrent subagents on independent slices
L9.4 Orchestrator-workersParent loop = orchestrator; subagents = workers
L9.6 Autonomous agentParent loop spawns many subagents over a long run

Beyond dozens to hundreds of subagents: use the Workflow tool (moves orchestration out of the per-turn context).

Verbatim: Pre-built, configurable agent harness that runs in managed infrastructure. Best for long-running tasks and asynchronous work.

vs Messages API:

Messages API (L4-L10)Claude Managed Agents
What it isDirect model prompting accessPre-built configurable agent harness in managed infrastructure
Best forCustom agent loops and fine-grained controlLong-running tasks and asynchronous work
ConceptDescription
AgentModel + system prompt + tools + MCP servers + Skills
EnvironmentWhere sessions run (Anthropic-managed cloud sandbox or self-hosted)
SessionRunning agent instance within an environment, performing a specific task
EventsMessages exchanged (user turns, tool results, status updates)
  1. Create an agent (POST /v1/agents). Define model + system + tools + MCP + Skills.
  2. Create an environment (POST /v1/environments). Cloud sandbox or self-hosted.
  3. Start a session (POST /v1/sessions). References agent + environment.
  4. Send events + stream SSE responses. Anthropic runs the loop; you POST user events and receive agent events.
  5. Steer or interrupt. Send additional user events mid-run.

Beta header: managed-agents-2026-04-01 (SDK auto-sets).

from anthropic import Anthropic
client = Anthropic()
agent = client.beta.agents.create(
name="Coding Assistant",
model="claude-opus-4-8",
system="You are a helpful coding assistant.",
tools=[{"type": "agent_toolset_20260401"}], # full built-in tool set
)
environment = client.beta.environments.create(
name="quickstart-env",
config={"type": "cloud", "networking": {"type": "unrestricted"}},
)
session = client.beta.sessions.create(
agent=agent.id, environment_id=environment.id, title="Quickstart",
)
with client.beta.sessions.events.stream(session.id) as stream:
client.beta.sessions.events.send(session.id, events=[
{"type": "user.message",
"content": [{"type": "text", "text": "..."}]},
])
for event in stream:
if event.type == "session.status_idle":
break
ToolPurpose
BashRun shell commands in the sandbox
File operationsRead, write, edit, glob, grep files in the sandbox
Web search and fetchSearch the web and retrieve URL content
MCP serversConnect to external tool providers (L6)

All enabled via agent_toolset_20260401 tool type.

SignalNotes
Long-running executionTasks running minutes or hours with many tool calls
Cloud infrastructureSecure sandbox with pre-installed packages + network access
Self-hosted executionSandbox on your infrastructure (compliance / data residency)
Minimal infrastructureNo need to build agent loop, sandbox, tool execution
Stateful sessionsPersistent filesystem + conversation history across interactions
PropertyManaged AgentsMessages API (L4-L10)
ZDR eligibleNO (stateful by design)Per-feature (most yes)
HIPAA BAA eligibleNOPer-feature
Data controlDelete sessions + uploaded files via APIPer-feature

Bottom line: ZDR-required workloads must stay on the Messages API path (self-built loop or Subagents).

PickWhen
Self-built L8 loopFull harness control; ZDR required; short tasks; latency dominated by tool side
Subagents inside the loopOrchestrator-workers (L9.4); parallelization (L9.3); per-subagent tool restriction; per-subagent smaller model (cost)
Claude Managed AgentsLong-running async; stateful sessions useful; no harness to build; ZDR NOT a constraint

The three compose. Most production stacks mix them.

FailureRecognize byFix
Subagent never spawnsParent does the work directlyInclude Agent in allowedTools; write a clearer description; explicit invoke (“Use the X agent”)
Subagent tries to spawn subagentRecursion error or unexpected behaviorSubagents cannot spawn subagents. Do NOT include Agent in subagent’s tools
Subagent missing contextSubagent asks for info parent already hasThe ONLY channel is the Agent tool prompt string. Include file paths, errors, decisions in that prompt
Managed Agents on ZDR workloadCompliance gapUse the Messages API path (self-built loop or Subagents)
Long-running self-built loopSandbox + state management complexity > the agent logicManaged Agents would have saved weeks. Reach for it when runtime > a few minutes
Cost spike on subagent fan-outAll subagents running on Opus when smaller models would sufficeUse per-subagent model alias (sonnet / haiku) per L3’s mix-and-match
Hundreds of subagents per turnSubagents fan-out hits context limitsUse the Workflow tool for dozens-to-hundreds of agents (moves orchestration outside the per-turn context)

What this lesson does NOT cover (and where to find it)

Section titled “What this lesson does NOT cover (and where to find it)”
TopicLands at
Shipping a Claude application end to endLesson 12
Cost monitoring (usage + usage.iterations + Cost API)Lesson 12
Eval-set discipline for agentsLesson 12 + Track 21 L7
Self-hosted sandboxes for Managed Agentsplatform.claude.com docs
MCP tunnels (Managed Agents)platform.claude.com docs (research preview)
Dynamic workflows (dozens to hundreds of agents)code.claude.com/docs/en/workflows
  • Anthropic Subagents in the SDK at https://code.claude.com/docs/en/agent-sdk/subagents.
  • Anthropic Claude Managed Agents overview at https://platform.claude.com/docs/en/managed-agents/overview.
  • Anthropic Managed Agents quickstart at https://platform.claude.com/docs/en/managed-agents/quickstart.
  • See references for the full anchor list.