Claude Agent SDK Python

Active
GitHub Python MIT

Description

Official Python SDK from Anthropic for building Claude-powered AI agents with tool use, multi-turn conversations, and agent orchestration.

Key Features

  • Bundled Claude Code CLI — no separate installation required; SDK uses the bundled CLI by default
  • In-Process MCP Tools — define custom tools as Python functions running as in-process MCP servers, eliminating subprocess overhead
  • Hooks System — intercept and control agent behavior at specific loop points with deterministic processing and automated feedback
  • Permission Control — allowed_tools, disallowed_tools, and permission_mode for fine-grained tool access management
  • Bidirectional Conversations — ClaudeSDKClient supports interactive multi-turn conversations with tool use and streaming
  • Error Hierarchy — structured error types for CLI not found, connection issues, process failures, and JSON decode errors

Use Cases

💡 Build Claude-powered AI agents with custom tool use in Python
💡 Create in-process MCP tool servers for high-performance tool execution
💡 Implement agent behavior guards and automated feedback with hooks
💡 Develop multi-turn conversational agents with streaming responses
💡 Automate file editing, bash commands, and project tasks via Claude Code

Quick Start

Install with pip install claude-agent-sdk (Python 3.10+). Quick start: import anyio and query from claude_agent_sdk, then run async for message in query(prompt='What is 2 + 2?'): print(message). The CLI is bundled — no separate install needed.

Related Projects