Claude Agent SDK
The Claude Agent SDK (formerly the Claude Code SDK) is Anthropic's Python and TypeScript library that runs Claude Code's agent loop, tools, hooks, subagents and MCP support inside your own program; install it with pip install claude-agent-sdk or npm install @anthropic-ai/claude-agent-sdk.
The Claude Agent SDK is Anthropic's library for building agents on the same tools, agent loop and context management that run Claude Code, in Python (pip install claude-agent-sdk) and TypeScript (npm install @anthropic-ai/claude-agent-sdk); it was called the Claude Code SDK until Sep 29, 2025 (Agent SDK overview, Enabling Claude Code to work more autonomously, Sep 29, 2025). Unlike calling the Messages API, where your code must run every tool, the SDK reads files, runs commands and edits code itself, and you consume a stream of what it did.
Quick facts
| Languages | Python 3.10+, TypeScript (Node.js 18.14+) |
| Packages | claude-agent-sdk (PyPI), @anthropic-ai/claude-agent-sdk (npm) |
| Latest versions | Python v0.2.178, TypeScript v0.3.318 (both Nov 4, 2026) |
| Entry point | query(); Python also has ClaudeSDKClient |
| Authentication | Claude API key, or Amazon Bedrock, Claude Platform on AWS, Google Cloud's Agent Platform, Microsoft Foundry |
| Terms | Anthropic's Commercial Terms of Service |
| Repositories | anthropics/claude-agent-sdk-python, anthropics/claude-agent-sdk-typescript |
Sources for the table: Agent SDK quickstart, Agent SDK overview, Python releases and TypeScript releases, read Nov 6, 2026.
What does the SDK give you?
Everything Claude Code has, as options on a function call: the built-in tools (read, write and edit files, run commands, search the web), permissions and modes, hooks as callbacks in your own code, subagents, MCP servers, sessions you can resume or fork, skills, commands and CLAUDE.md memory loaded from .claude/ folders, and plugins loaded by path. Anthropic's pages also cover custom tools, structured outputs, cost tracking, file checkpointing and hosting (Agent SDK overview, read Nov 6, 2026). Under the hood it runs the Claude Code binary, which both packages bundle, so most installs need no separate Claude Code install.
A first agent
Anthropic's quickstart builds an agent that finds and fixes crash bugs in a file. In Python:
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage
async def main():
async for message in query(
prompt="Review utils.py for bugs that would cause crashes. Fix any issues you find.",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Glob"],
permission_mode="acceptEdits",
),
):
if isinstance(message, AssistantMessage):
for block in message.content:
if hasattr(block, "text"):
print(block.text)
elif isinstance(message, ResultMessage):
print(f"Done: {message.subtype}")
asyncio.run(main())
The TypeScript version is the same shape: for await (const message of query({ prompt, options: { allowedTools: ["Read", "Edit", "Glob"], permissionMode: "acceptEdits" } })). The steps:
- Install the package and set
ANTHROPIC_API_KEYin the shell (the SDK does not read.envfiles on its own). - Write the script above, choosing tools:
Read,Glob,Grepfor analysis only; addEditto change code; addBashfor full automation. - Run it (
python agent.py, ornpx tsx agent.ts); the loop ends withDone: success.
Source: Agent SDK quickstart, read Nov 6, 2026. Options such as system_prompt, mcp_servers and permission_mode shape the agent; an SDK session starts in default permission mode, not auto.
How is it different from the API, the CLI and Managed Agents?
Anthropic's overview draws the lines this way (Agent SDK overview, read Nov 6, 2026):
| You want to | Use |
|---|---|
| Embed Claude Code's agent in your own app, in a process you run | Agent SDK |
| Work interactively or run one-off tasks in a terminal | Claude Code CLI |
| Call the Claude API directly and run the tool loop yourself (or with the client SDK's beta tool runner) | Client SDK |
| Have Anthropic host the agent loop in a managed or self-hosted sandbox | Managed Agents |
In short: with the client SDK and tool use you write each tool and decide what runs; with the Agent SDK the tools come built in and run on your machine or server; with Managed Agents Anthropic runs the loop and the sandbox, priced at $0.08 per session-hour of active runtime on top of tokens (as of Nov 6, 2026). From other languages, Anthropic suggests calling the CLI with claude -p --output-format json (Claude Code Headless and CI).
Billing and the login rule
The SDK bills like the API: tokens on your Claude API key or cloud account at API rates. Anthropic's overview states that, unless previously approved, third-party developers may not offer claude.ai login or claude.ai rate limits in their products, agents built on the SDK included; builders should use API key authentication (Agent SDK overview, read Nov 6, 2026). Branding rules let a product say "Claude Agent" or "Powered by Claude" but not "Claude Code" or imitate its look.
The rename and breaking changes
On Sep 29, 2025, alongside Claude Code 2.0, Anthropic renamed the Claude Code SDK to the Claude Agent SDK. The TypeScript package moved from @anthropic-ai/claude-code to @anthropic-ai/claude-agent-sdk and Python from claude-code-sdk to claude-agent-sdk. Version 0.1.0 also changed behavior: Python's ClaudeCodeOptions became ClaudeAgentOptions, the system prompt no longer defaults to Claude Code's, and settings files are not loaded unless asked (Migrate to Claude Agent SDK, read Nov 6, 2026). Later, the TypeScript V2 session API was removed in 0.3.142 in favor of query(). The Claude Code GitHub Action and the GitLab integration are both built on the SDK.
Frequently asked questions
What is the Claude Agent SDK? It is Anthropic's Python and TypeScript library that runs Claude Code's agent loop and tools inside your own application, so Claude can read files, run commands, use MCP servers and call subagents without you writing a tool loop.
Is the Claude Code SDK the same as the Claude Agent SDK? Yes. Anthropic renamed the Claude Code SDK to the Claude Agent SDK on Sep 29, 2025, with new package names, claude-agent-sdk and @anthropic-ai/claude-agent-sdk.
Can I use my Claude Pro or Max subscription with the Agent SDK? Anthropic's documentation tells builders to authenticate with an API key or a cloud provider, and does not allow third-party products to offer claude.ai login or its rate limits unless approved.
How is the Claude Agent SDK different from Managed Agents? With the Agent SDK the agent runs in a process you operate; with Managed Agents, Anthropic hosts the loop and a sandbox and charges for session runtime as well as tokens.
Does the Claude Agent SDK need Claude Code installed? Usually not. Both packages bundle a native Claude Code binary; a few installs, such as a Python source distribution on ARM64 Windows, need Claude Code installed separately.
Sources
- Agent SDK overview, Anthropic, read Nov 6, 2026
- Agent SDK quickstart, Anthropic, read Nov 6, 2026
- Migrate to Claude Agent SDK, Anthropic, read Nov 6, 2026
- TypeScript SDK V2 session API (removed), Anthropic, read Nov 6, 2026
- Enabling Claude Code to work more autonomously, Anthropic, Sep 29, 2025
- claude-agent-sdk-python releases, GitHub, read Nov 6, 2026
- claude-agent-sdk-typescript releases, GitHub, read Nov 6, 2026
- Pricing, Anthropic, read Nov 6, 2026
- Ship your first Managed Agent, Claude, May 26, 2026 (video)
Moments
Ship your first Managed Agent
Claude
See also
-
Claude CodeClaude Code is Anthropic's agentic coding tool. It reads a codebase, edits files, runs commands and opens pull requests from the terminal, VS Code, JetBrains IDEs, the Claude desktop app, the browser and Slack, and it comes with every paid Claude plan or a pay-as-you-go Console account. -
Messages APIThe Messages API is the Claude API's main endpoint, POST /v1/messages: you send a model, max_tokens and a list of user and assistant messages, and Claude returns a message with content blocks, a stop_reason and token usage, whole or streamed.
-
Claude Code Permissions and ModesClaude Code has six permission modes (Manual, Accept edits, Plan, Auto, Don't ask and Bypass permissions), cycled with Shift+Tab; since v2.1.283 interactive sessions start in auto mode, and --dangerously-skip-permissions turns every check off and belongs only in a container or VM.
-
Claude Code HooksClaude Code hooks are shell commands (or HTTP calls, MCP tools or model checks) that Claude Code runs at fixed points such as before a tool call, after an edit or when Claude stops, configured under "hooks" in a settings.json file.
-
Claude Code SubagentsClaude Code subagents are helper agents that run in their own context window with their own instructions, tools and model; Claude Code ships built-in ones such as Explore and Plan, and you add your own as Markdown files in .claude/agents/.
-
Claude Code MCP ServersClaude Code connects to MCP servers with claude mcp add, for example claude mcp add --transport http notion https://mcp.notion.com/mcp, stored per user, per project in a shared .mcp.json file, or locally for one project.