Answer: You define subagents programmatically by passing an `agents` parameter in your options, where each subagent is an `AgentDefinition` with a description, prompt, and optional tools and model. Claude invokes subagents through the `Agent` tool. Status: Confirmed Entry: tool/claude-code/agents-and-automation/create-subagent-programmatically Revision: 4 Digest: sha256:98a8a1414a03bbb4 (changes whenever the content changes) Timeline: Created: 2026-11-13T03:03:03Z Last changed: 2026-11-19T12:13:12Z (definition class: — → AgentDefinition) Last verified: 2026-11-20T12:17:27Z Next check: 2026-11-21T12:17:27Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of method | agents | [1] | 2026-11-20 invocation tool | Agent | [1] | 2026-11-20 definition class | AgentDefinition | [1] | 2026-11-20 example subagent 1 | code-reviewer | [1] | 2026-11-20 example subagent 2 | test-runner | [1] | 2026-11-20 model override | sonnet | [1] | 2026-11-20 Sources: [1] Anthropic. "Subagents in the SDK". https://code.claude.com/docs/en/agent-sdk/subagents.md Role: primary. Accessed: 2026-11-20T12:17:27Z Quote: "Define subagents directly in your code using the `agents` parameter." (Supports: method) Quote: "Claude invokes subagents through the `Agent` tool." (Supports: invocation tool) Quote: "from claude_agent_sdk import query, ClaudeAgentOptions, AgentDefinition" (Supports: definition class) Quote: ""code-reviewer": AgentDefinition(" (Supports: example subagent 1) Quote: ""test-runner": AgentDefinition(" (Supports: example subagent 2) Quote: "model="sonnet"," (Supports: model override) Published: 2026-11-20T10:36:10Z Snapshot SHA-256: 39e8862dc192aa0a70a5153f84efe78010ae959a3f6f12a1f7b2c5982f0aaaed (captured 2026-11-20T12:17:27Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. Cross-check: not-available at 2026-11-20T12:17:27Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:17:27Z Last attempt: 2026-11-20T12:17:27Z Notes and limitations: Extracted automatically from a single official source (section "Programmatic definition (recommended)"). Related: https://latestn.com/tool/claude-code/agents-and-automation/custom-sessionstore-adapter How do I implement a custom SessionStore adapter for Claude Code Agent SDK session storage? https://latestn.com/tool/claude-code/agents-and-automation/disable-filesystem-settings-setting-sources How do I disable filesystem settings like CLAUDE.md and skills in a Claude Code SDK agent? https://latestn.com/tool/claude-code/agents-and-automation/disable-subagents How do I disable specific subagents in Claude Code? https://latestn.com/tool/claude-code/agents-and-automation/create-scheduled-task How do I create a scheduled task in Claude Code Desktop? https://latestn.com/tool/claude-code/agents-and-automation/create-scheduled-task-cli How do I create a scheduled task in Claude Code from the CLI? https://latestn.com/tool/claude-code/agents-and-automation/create-skill How do I create a skill for Claude Agent SDK sessions? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-19T12:13:12Z | changed | definition class: — → AgentDefinition | [1] 2026-11-19T12:13:12Z | changed | Python class: AgentDefinition → — | [1] 2026-11-17T12:21:44Z | changed | model override: — → sonnet | [1] 2026-11-17T12:21:44Z | changed | model override example: sonnet → — | [1] 2026-11-17T12:21:44Z | changed | method: Define subagents directly in your code using the `agents` parameter → agents | [1] 2026-11-14T12:13:08Z | changed | model override example: — → sonnet | [1] 2026-11-14T12:13:08Z | changed | Python class: — → AgentDefinition | [1] 2026-11-14T12:13:08Z | changed | model override: sonnet → — | [1] 2026-11-14T12:13:08Z | changed | definition class: AgentDefinition → — | [1] 2026-11-14T12:13:08Z | changed | method: agents → Define subagents directly in your code using the `agents` parameter | [1] 2026-11-13T03:03:03Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/agents-and-automation/create-subagent-programmatically/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/agents-and-automation/create-subagent-programmatically POST: https://latestn.com/dispute/tool/claude-code/agents-and-automation/create-subagent-programmatically with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/agents-and-automation/create-subagent-programmatically?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I create a subagent programmatically in the Claude Agent SDK? Revision 4, last verified 2026-11-20T12:17:27Z. https://latestn.com/tool/claude-code/agents-and-automation/create-subagent-programmatically (accessed 2026-11-21T09:54:22Z). @misc{LatestN_tool_claude_code_agents_and_automation_create_subagent_programmatically_r4, title = {How do I create a subagent programmatically in the Claude Agent SDK?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/agents-and-automation/create-subagent-programmatically}}, note = {Revision 4; digest sha256:98a8a1414a03bbb4; last verified 2026-11-20T12:17:27Z; accessed 2026-11-21T09:54:22Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/agents-and-automation/create-subagent-programmatically