Skip to content

Agent SDK Reference

The Claude Agent SDK provides a Python framework for building autonomous AI agents with the same capabilities as Claude Code.

Terminal window
uv add claude-agent-sdk # Requires Python 3.10+
from claude_agent_sdk import query
import anyio
async def main():
async for msg in query("Analyze this codebase"):
print(msg)
anyio.run(main())

For multi-turn conversations:

from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
import anyio
async def main():
options = ClaudeAgentOptions(
model="claude-opus-4-5",
allowed_tools=["Read", "Write", "Edit", "Bash"],
permission_mode="ask"
)
async with ClaudeSDKClient(options) as client:
await client.query("Read the config file")
async for msg in client.receive_response():
print(msg)
await client.query("Explain what you found")
async for msg in client.receive_response():
print(msg)
anyio.run(main())
OptionTypeDescription
modelstringModel ID (e.g., claude-opus-4-5)
system_promptstringCustom system prompt
setting_sourcesarray["local", "project", "user"] - loads .claude/settings.json
permission_modestring"allow", "deny", "ask", "bypass"
allowed_toolsarrayTools to enable (e.g., ["Read", "Write"])
mcp_serversobjectMCP server configurations
max_tokensnumberMaximum response tokens
from claude_agent_sdk import tool, create_sdk_mcp_server
@tool("multiply", "Multiply two numbers", {"a": float, "b": float})
async def multiply_tool(args: dict) -> dict:
return {
"content": [{"type": "text", "text": f"Result: {args['a'] * args['b']}"}]
}
calculator = create_sdk_mcp_server(
name="calculator",
version="1.0.0",
tools=[multiply_tool]
)
options = ClaudeAgentOptions(
mcp_servers={"calc": calculator},
allowed_tools=["mcp__calc__multiply"]
)

Tool return format: { "content": [{"type": "text", "text": "result"}], "is_error": false }

Terminal window
# Anthropic API (default)
export ANTHROPIC_API_KEY="your-key"
# AWS Bedrock
export CLAUDE_CODE_USE_BEDROCK=1
# Google Vertex AI
export CLAUDE_CODE_USE_VERTEX=1