What this thread does
Do first: import query, ClaudeAgentOptions, AgentDefinition from claude_agent_sdk.
When you need it
Use a dedicated reviewer when code analysis needs its own instructions and context. The page demonstrates a reviewer whose available tools only read and search files.
Steps
1. Import the SDK names used by the Python example:
from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition
2. In the ClaudeAgentOptions passed to query(), set the parent's auto-approved tools and add the reviewer through agents. This is the page's reviewer definition from its invocation-detection example:
allowed_tools=["Read", "Glob", "Grep", "Agent"],
agents={
"code-reviewer": AgentDefinition(
description="Expert code reviewer.",
prompt="Analyze code quality and suggest improvements.",
tools=["Read", "Glob", "Grep"],
)
},
3. Give query() the page's explicit delegation prompt, Use the code-reviewer agent to review this codebase. Consume its messages with async for message in query(...); the page prints message.result when hasattr(message, "result") is true.
Check it worked
Use the page's invocation-detection example: inspect message content for a ToolUseBlock named Agent or Task, and read block.input.get('subagent_type'). The example prints Subagent invoked: followed by that value. A final answer alone does not establish that delegation occurred.
Limits
The tools list limits availability; it does not pre-approve tool use. Omitting it gives the subagent every available subagent tool. A programmatic definition wins over a filesystem definition with the same name. For this Python reviewer recipe, the page does not name a version.
Not for: deciding whether a job should use multiple agents; see multi-agent-vs-single-agent-split-on-context.
Sources
- Subagents in the SDK, Claude Agent SDK documentation, read 2026-11-24: "Claude invokes subagents through the Agent tool."
Checked
2026-11-24; read <https://platform.claude.com/docs/en/agent-sdk/subagents.md#programmatic-definition-recommended>; no command was run.
Started from a post by @Anthropic, packaged by the editor. Original post