Claude Agent SDK
The Claude Agent SDK (available in Python and TypeScript) embeds the same autonomous agent loop that powers Claude Code into custom applications. It is the primary building block for creating production-quality, tool-using Claude agents.
What it provides
query()entry point — starts the agent loop with a prompt and options- Tool permission controls — define which tools run automatically, require approval, or are blocked
- PreToolUse / PostToolUse hooks — intercept tool calls for logging, policy, or human approval
- Streaming messages — observe the agent’s reasoning and tool calls in real time
- Session management — preserve conversation identity across interrupted or long-running work
- Result metadata — status, token usage, cost, and session ID on every completed run
Official repositories
anthropics/claude-agent-sdk-pythonanthropics/claude-agent-sdk-typescriptanthropics/claude-agent-sdk-demos— learning examples coveringhello-world, chat streaming, user approval, email agent (MCP tools), and research agent (subagents)anthropics/claude-quickstarts— deployable application examples
Demo learning ladder
The SDK demo project teaches one production concern at a time:
| Demo | Teaches |
|---|---|
hello-world | Minimal agent loop and messages |
| Chat app | Streaming UI and message display |
AskUserQuestion | Human-in-the-loop approval flow |
| Email agent | Custom MCP tool integration |
| Research agent | Subagent orchestration and audit hooks |
Key design principle
The SDK is a runtime, not a prompt wrapper. The real engineering work is deciding which tools to allow, when to insert hooks, how to manage sessions, and how to validate outputs — not just which model to use.
Governance use
- Use hooks for audit trails and policy enforcement
- Use minimal tool allowlists per workflow
- Store session IDs and results for recovery and audit
- Validate outputs against acceptance criteria before trusting results
Related
- AgentLoop — the loop this SDK implements
- BoundedAgent — the pattern for constraining SDK agents
- MCP — protocol for connecting external tools to the SDK
- ClaudeCowork — the Cowork product is built on the same underlying loop
- ClaudeSDKEcosystem — synthesis across the full Claude agent ecosystem