Claude Agent SDK - The Definitive Guide
Claude Agent SDK is the toolkit that brings the same autonomous-agent capabilities that power Claude Code to your own applications. It is a fully-featured, open-source library written in Python and TypeScript, exposing a high-level agent loop, built-in tools, and the Model Context Protocol (MCP) for connecting to external services. Whether you're a solo developer, a data-science team, or a cloud-ops house, the SDK lets you ship agents that can read files, run shell commands, query the web, edit code, and more - all with minimal boilerplate.
Below is the exhaustive, up-to-date walkthrough of everything you need to know: what the SDK is, its latest capabilities, installation on every major OS, sample code, best-practice use cases, alternatives, and community feedback. All statements are grounded in the official documentation at <https://docs.claude.ai> and the public release notes; if anything is unclear, consult the docs directly.
---
1. What it is & why it matters
1.1 The Core Idea
Claude Agent SDK is an agent-development framework that lets you build autonomous agents that:
| Feature | Description |
|---|---|
| Agent loop | A reusable, event-driven cycle that manages prompt, tool execution, and response streaming. |
| Built-in tools | File read/write, Bash execution, code editing, web search, and more, ready to use out of the box. |
| MCP support | The open Model Context Protocol allows you to plug in any external tool or data source without changing the core agent logic. |
| Session persistence | Save and restore agent context to/from external storage, enabling long-running workflows. |
| Observability | Built-in OpenTelemetry hooks and permission controls for auditability and testing. |
1.2 Why it matters
- Rapid prototyping - You can spin up an intelligent bot that reads a repo, finds a bug, and patches it in minutes.
- Productivity - By abstracting the heavy lifting (prompt engineering, tool orchestration), you focus on business logic.
- Scalability - The SDK is designed to run in cloud environments, and its tool-search feature scales to thousands of tools.
- Open-source control - Unlike black-box solutions, you own the code, can audit it, and can extend it with your own MCP adapters.
---
2. What's new / key features (detailed breakdown)
| Feature | What's new in the latest release | Practical impact |
|---|---|---|
| MCP (Model Context Protocol) | First public version of MCP is now baked into the SDK as a modular interface. | Agents can now plug in any third-party API (e.g., a company's internal CRM) without hard-coding logic. |
| Tool search | Agents can discover relevant tools at runtime from a registry, instead of a static whitelist. | Reduces configuration overhead and allows dynamic workflows. |
| Subagents | Ability to spawn child agents that run in parallel or nested contexts. | Enables complex, multi-stage pipelines (e.g., a data-prep agent that feeds a modeling agent). |
| Observability & OpenTelemetry | Integrated tracing and metrics. | Easier debugging, cost monitoring, and compliance. |
| Permission model | Fine-grained control over which tools an agent can use per user or per session. | Strengthens security for multi-tenant deployments. |
| Streaming approvals | Agents can request user approval mid-loop, and the UI can stream the approval decision. | Improves safety in high-risk actions (e.g., modifying production code). |
| Checkpointing | Ability to snapshot agent state and rewind to a previous checkpoint. | Very useful for debugging or for "undo" functionality. |
| Cross-platform CLI | The SDK now ships a claude-agent CLI that works on Windows, macOS, and Linux. | Simplifies deployment and experimentation. |
> Note: Some of these items are still marked "in progress" in the changelog. Verify the exact availability by checking the official release notes.
---
3. Installation - every OS
The SDK is available as a single pip package for Python and as an npm package for TypeScript. The following sections walk through the minimal steps for Windows, macOS, and Linux.
> Prerequisite: You must have a recent version of the Claude API key. Set it as an environment variable CLAUDE_API_KEY before running any code.
3.1 Windows
- Open PowerShell as Administrator.
- Create a virtual environment (recommended):
python -m venv claude-env
.\claude-env\Scripts\activate
- Upgrade pip and install the SDK:
python -m pip install --upgrade pip
pip install claude-agent-sdk
- Verify installation:
python -c "import claude_agent_sdk; print(claude_agent_sdk.__version__)"
- Optional - Install the CLI:
pip install claude-agent-sdk[cli]
claude-agent --help
3.2 macOS
- Open Terminal.
- Create a virtual environment:
python3 -m venv claude-env
source claude-env/bin/activate
- Upgrade pip and install the SDK:
pip install --upgrade pip
pip install claude-agent-sdk
- Check the version:
python -c "import claude_agent_sdk; print(claude_agent_sdk.__version__)"
- CLI (optional):
pip install claude-agent-sdk[cli]
claude-agent --help
3.3 Linux
The steps mirror macOS but use python3 as
HowiPrompt