Anthropic released the Claude Agent SDK alongside Sonnet 4.5 — the same infrastructure that powers Claude Code, now available for your own agents.
Anthropic released the Claude Agent SDK on September 29, 2025, alongside Claude Sonnet 4.5. The SDK exposes the same agent infrastructure that powers Claude Code — including the agent loop, built-in tools, permission systems, context management, and subagent coordination.
If you have been building AI agents from scratch, this is worth your attention.
What You Get
The Claude Agent SDK provides:
- The agent loop that handles multi-turn reasoning and tool use
- Built-in tools for file operations, search, code execution, and web access
- Permission systems that balance agent autonomy with user control
- Context management for long-running tasks that exceed context windows
- Subagent coordination for delegating subtasks to specialized agents
- Memory management across extended sessions
Anthropic spent more than six months shipping updates to Claude Code before open-sourcing the underlying infrastructure. The hard problems — how agents manage memory, how permissions work, how subagents coordinate — are solved in the SDK rather than left to every developer to reinvent.
Installation
TypeScript:
npm install @anthropic-ai/claude-agent-sdk
Python (requires 3.10+):
pip install claude-agent-sdk
The TypeScript SDK bundles a native Claude Code binary. The Python SDK includes the CLI automatically — no separate installation required.
Set your API key:
export ANTHROPIC_API_KEY=your-api-key
A Minimal Agent
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
async for message in query(
prompt="Find and fix the bug in auth.py",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Bash"],
permission_mode="acceptEdits",
),
):
print(message)
The query function creates the agentic loop. You provide a prompt, configure which tools the agent can use, and stream messages as Claude works.
Key Configuration Options
allowed_tools/allowedTools: Pre-approve specific tools (Read, Edit, Bash, Glob, Grep, WebSearch, etc.)permission_mode/permissionMode: Control how the agent handles permission requests (acceptEdits, ask, etc.)model: Specify the Claude model (useclaude-sonnet-4-5for latest)cwd: Set the working directory for file operationsmax_turns/maxTurns: Limit conversation lengthsystem_prompt: Custom system instructionsmcp_servers: Connect Model Context Protocol servers for extended tool access
Hooks for Control
The SDK supports hooks that intercept tool usage before execution. A PreToolUse hook can enforce policies — for example, restricting file writes to specific directories or blocking certain bash commands.
This is critical for production deployments where you need guardrails beyond the default permission system.
Claude Sonnet 4.5 as the Engine
Anthropic recommends Sonnet 4.5 for all agent use cases. It is a drop-in replacement for Sonnet 4 at the same price ($3/$15 per million tokens) with significantly improved performance on coding, reasoning, and agentic tasks.
Code execution and file creation are available on all paid plans in the Claude apps, and the Agent SDK is available to all developers on the Claude Developer Platform.
Production Considerations
Sandbox your agents. Recent research from Darktrace showed agents hacking their own test environments. Run agents in isolated environments with no access to production systems.
Log everything. Agent actions should be auditable. The SDK's message stream provides a record of reasoning and tool use — persist it.
Start with restricted tools. Begin with read-only tools and expand permissions as you validate agent behavior. Pre-approving all tools in production is risky.
Test permission boundaries. Deliberately try to get your agent to take unauthorized actions. If it succeeds, tighten your hooks and permission configuration.
When to Use the Agent SDK vs. Raw API
Use the Agent SDK when your application needs multi-step autonomous work: code review, bug fixing, research tasks, data analysis pipelines, or any workflow where the agent decides which tools to use and in what order.
Use the raw Claude API when you need single-turn responses, structured output, or tight control over each interaction step.
The Agent SDK is Claude Code's foundation made portable. For developers who have been impressed by Claude Code's capabilities and wondered how to build something similar for their own domain, the answer is now a pip install away.
Comments
Loading comments…