Claude Agent SDK (Python): build your own agent on Claude Code's engine
TL;DR
pip install claude-agent-sdk (Python 3.10+, Claude Code CLI bundled). Use query() for one-way tasks and ClaudeSDKClient for two-way conversations, custom tools and hooks. Custom tools run in-process via create_sdk_mcp_server — no separate MCP process.
Minimal
import anyio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
opts = ClaudeAgentOptions(
system_prompt="You are a read-only code reviewer",
allowed_tools=["Read", "Grep", "Glob"],
cwd="./my-repo", max_turns=5)
async for msg in query(prompt="Find error handling without logging", options=opts):
print(msg)
anyio.run(main)A custom tool in Python
from claude_agent_sdk import tool, create_sdk_mcp_server, ClaudeAgentOptions
@tool("get_sprint", "Get the current sprint", {"team": str})
async def get_sprint(args):
data = await jira_client.current_sprint(args["team"]) # your code
return {"content": [{"type": "text", "text": str(data)}]}
server = create_sdk_mcp_server(name="pm", version="1.0.0", tools=[get_sprint])
opts = ClaudeAgentOptions(mcp_servers={"pm": server},
allowed_tools=["mcp__pm__get_sprint"])Key options
| Option | Meaning |
|---|---|
allowed_tools | Auto-approved tools (not the list of available tools) |
disallowed_tools | Block tools entirely |
permission_mode | e.g. acceptEdits to auto-accept file edits |
hooks | Python functions on PreToolUse… that can deny actions |
Docs: anthropics/claude-agent-sdk-python · Agent SDK — Python reference