The Claude Agent SDK enables building autonomous AI agents that can:
- Execute multi-turn conversations with tool use
- Read, write, and edit files in a working directory
- Run shell commands
- Integrate with external services via MCP
- Spawn specialized subagents
1. Streaming is Primary
The SDK operates as a streaming API. You iterate over messages as they're generated:
// TypeScript
for await (const message of query({ prompt: "...", options })) {
// Handle each message type
}
# Python
async for message in query(prompt="...", options=options):
# Handle each message type
2. System Prompt is Empty by Default
The SDK uses an empty system prompt by default. To get Claude Code's full capabilities:
systemPrompt: { type: "preset", preset: "claude_code" }
3. Settings Sources Must Be Explicit
CLAUDE.md, skills, and slash commands are NOT loaded by default. You must specify:
settingSources: ["user", "project"] // TypeScript
setting_sources=["user", "project"] # Python
4. Permission Modes Control Tool Access
Choose permission mode based on your use case:
default - Interactive approval
acceptEdits - Auto-approve file changes
bypassPermissions - Skip all permission checks (use with care)
5. MCP Tools Require Streaming Input
Custom MCP tools require streaming input mode (async generator), not simple strings.
Install:
npm install @anthropic-ai/claude-agent-sdk # TypeScript
pip install claude-agent-sdk # Python
Basic agent:
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const msg of query({
prompt: "Read package.json and summarize the dependencies",
options: {
systemPrompt: { type: "preset", preset: "claude_code" },
allowedTools: ["Read", "Grep", "Glob"],
maxTurns: 5
}
})) {
if (msg.type === "result") console.log(msg.result);
}
For detailed guidance, select a workflow below.
- Build a new agent from scratch
- Add custom tools (MCP servers)
- Implement hooks for behavior modification
- Configure permissions and security
- Deploy an agent to production
- Debug an agent issue
- Something else
Then read the matching workflow from workflows/ and follow it.
After reading the workflow, follow it exactly.
# TypeScript
npx tsc --noEmit # Type check
npm test # Run tests
# Python
python -m mypy . # Type check
pytest # Run tests
Test the agent interactively:
npx tsx my-agent.ts # TypeScript
python my_agent.py # Python
Report to the user:
- "Type check: OK/X errors"
- "Tests: X pass, Y fail"
- "Agent runs and responds correctly"
All in references/:
Core:
- sdk-overview.md - Architecture, installation, message types, API comparison
- built-in-tools.md - Read, Write, Edit, Bash, Glob, Grep, MCP tools
Features:
- hooks.md - Lifecycle hooks, callbacks, patterns
- subagents.md - Creating and spawning subagents
- mcp-and-custom-tools.md - MCP servers, custom tool definition
- permissions.md - Permission modes, tool restrictions, canUseTool
- sessions.md - Resuming, forking, context management
Advanced:
- patterns-and-features.md - Streaming modes, structured outputs, checkpointing
- filesystem-features.md - Skills, slash commands, CLAUDE.md, plugins
- hosting-and-deployment.md - Docker, sandboxing, production patterns
- debugging.md - Common issues and solutions
All in workflows/:
| File |
Purpose |
| build-new-agent.md |
Create new agent from scratch |
| add-custom-tools.md |
Add MCP tools to extend capabilities |
| implement-hooks.md |
Add lifecycle hooks |
| configure-permissions.md |
Set up security and permissions |
| deploy-agent.md |
Deploy to production |
|
|
1---2name: developing-claude-agent-sdk-agents3description: Build AI agents with the Claude Agent SDK (TypeScript/Python). Covers creating agents, custom tools, hooks, subagents, MCP integration, permissions, sessions, and deployment. Use when building, reviewing, debugging, or deploying SDK-based agents. Invoke PROACTIVELY when user mentions Agent SDK, claude-agent-sdk, ClaudeSDKClient, query(), or building autonomous agents.4---56<objective>7Build production-ready AI agents using the Claude Agent SDK. This skill provides comprehensive guidance for the full agent development lifecycle: creating agents, adding custom tools, implementing hooks, configuring permissions, managing sessions, and deploying to production.8</objective>910<essential_principles>11**Core SDK Concepts**1213The Claude Agent SDK enables building autonomous AI agents that can:14- Execute multi-turn conversations with tool use15- Read, write, and edit files in a working directory16- Run shell commands17- Integrate with external services via MCP18- Spawn specialized subagents1920**1. Streaming is Primary**2122The SDK operates as a **streaming API**. You iterate over messages as they're generated:2324```typescript25// TypeScript26for await (const message of query({ prompt: "...", options })) {27 // Handle each message type28}29```3031```python32# Python33async for message in query(prompt="...", options=options):34 # Handle each message type35```3637**2. System Prompt is Empty by Default**3839The SDK uses an **empty system prompt** by default. To get Claude Code's full capabilities:4041```typescript42systemPrompt: { type: "preset", preset: "claude_code" }43```4445**3. Settings Sources Must Be Explicit**4647CLAUDE.md, skills, and slash commands are NOT loaded by default. You must specify:4849```typescript50settingSources: ["user", "project"] // TypeScript51setting_sources=["user", "project"] # Python52```5354**4. Permission Modes Control Tool Access**5556Choose permission mode based on your use case:57- `default` - Interactive approval58- `acceptEdits` - Auto-approve file changes59- `bypassPermissions` - Skip all permission checks (use with care)6061**5. MCP Tools Require Streaming Input**6263Custom MCP tools require streaming input mode (async generator), not simple strings.6465</essential_principles>6667<quick_start>68**Get Started in 60 Seconds**6970**Install:**71```bash72npm install @anthropic-ai/claude-agent-sdk # TypeScript73pip install claude-agent-sdk # Python74```7576**Basic agent:**77```typescript78import { query } from "@anthropic-ai/claude-agent-sdk";7980for await (const msg of query({81 prompt: "Read package.json and summarize the dependencies",82 options: {83 systemPrompt: { type: "preset", preset: "claude_code" },84 allowedTools: ["Read", "Grep", "Glob"],85 maxTurns: 586 }87})) {88 if (msg.type === "result") console.log(msg.result);89}90```9192**For detailed guidance, select a workflow below.**93</quick_start>9495<intake>96**What would you like to do?**97981. Build a new agent from scratch992. Add custom tools (MCP servers)1003. Implement hooks for behavior modification1014. Configure permissions and security1025. Deploy an agent to production1036. Debug an agent issue1047. Something else105106**Then read the matching workflow from `workflows/` and follow it.**107</intake>108109<routing>110| Response | Workflow |111|----------|----------|112| 1, "new", "create", "build", "start" | `workflows/build-new-agent.md` |113| 2, "tool", "tools", "mcp", "custom" | `workflows/add-custom-tools.md` |114| 3, "hook", "hooks", "lifecycle", "callback" | `workflows/implement-hooks.md` |115| 4, "permission", "security", "sandbox" | `workflows/configure-permissions.md` |116| 5, "deploy", "host", "production", "ship" | `workflows/deploy-agent.md` |117| 6, "debug", "fix", "error", "broken" | Read `references/debugging.md`, then diagnose |118| 7, other | Clarify, then select workflow or references |119120**After reading the workflow, follow it exactly.**121</routing>122123<verification_loop>124**After Every Change**125126```bash127# TypeScript128npx tsc --noEmit # Type check129npm test # Run tests130131# Python132python -m mypy . # Type check133pytest # Run tests134```135136Test the agent interactively:137```bash138npx tsx my-agent.ts # TypeScript139python my_agent.py # Python140```141142Report to the user:143- "Type check: OK/X errors"144- "Tests: X pass, Y fail"145- "Agent runs and responds correctly"146</verification_loop>147148<reference_index>149**Domain Knowledge**150151All in `references/`:152153**Core:**154- sdk-overview.md - Architecture, installation, message types, API comparison155- built-in-tools.md - Read, Write, Edit, Bash, Glob, Grep, MCP tools156157**Features:**158- hooks.md - Lifecycle hooks, callbacks, patterns159- subagents.md - Creating and spawning subagents160- mcp-and-custom-tools.md - MCP servers, custom tool definition161- permissions.md - Permission modes, tool restrictions, canUseTool162- sessions.md - Resuming, forking, context management163164**Advanced:**165- patterns-and-features.md - Streaming modes, structured outputs, checkpointing166- filesystem-features.md - Skills, slash commands, CLAUDE.md, plugins167- hosting-and-deployment.md - Docker, sandboxing, production patterns168- debugging.md - Common issues and solutions169</reference_index>170171<workflows_index>172**Workflows**173174All in `workflows/`:175176| File | Purpose |177|------|---------|178| build-new-agent.md | Create new agent from scratch |179| add-custom-tools.md | Add MCP tools to extend capabilities |180| implement-hooks.md | Add lifecycle hooks |181| configure-permissions.md | Set up security and permissions |182| deploy-agent.md | Deploy to production |183</workflows_index>184185<success_criteria>186A well-built SDK agent:187- Uses streaming API correctly188- Handles all message types appropriately189- Has proper error handling190- Uses appropriate permission mode191- Includes timeout and maxTurns limits192- Has been tested with real queries193- Is type-safe (TypeScript) or type-hinted (Python)194</success_criteria>