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-python
  • anthropics/claude-agent-sdk-typescript
  • anthropics/claude-agent-sdk-demos — learning examples covering hello-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:

DemoTeaches
hello-worldMinimal agent loop and messages
Chat appStreaming UI and message display
AskUserQuestionHuman-in-the-loop approval flow
Email agentCustom MCP tool integration
Research agentSubagent 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
  • 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