Build AI agents with the Claude Agent SDK (TypeScript/Python). Covers creating agents, custom tools, hooks, subagents, MCP integration, permissions, sessions, and deployment...
The Claude Agent SDK enables building autonomous AI agents that can:
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 approvalacceptEdits - Auto-approve file changesbypassPermissions - 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.
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:
All in references/:
Core:
Features:
Advanced:
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 |