Dev & Engineering ✓ Anthropic · Official python-sdkmcpcustom-toolshooksasync-api

Claude Agent SDK for Python

Call Claude Code from Python to build asynchronous and interactive agent workflows with extensible tools.

Stars
★ 8.3k
Last updated
today
License
MIT
Primary language
Python

At a glance

How it runs
Library / SDK
Works with
Platform-specificClaude CodeClaude API (Partial support)
Setup effort
Low · running in minutes
You'll need
Python 3.10+Claude Code CLIShell / CLINetwork accessLocal filesystemMCP Server
Typical use
Python application developers adding Claude Code queries to an existing application.
Not a fit if
  • Teams needing a provider-agnostic SDK
  • Teams that cannot run the Claude Code CLI

What does this agent do, and when should you use it?

This SDK provides an async Python interface for calling Claude Code and requires Python 3.10 or later. query() returns an asynchronous iterator of response messages for one-off requests, while ClaudeSDKClient supports bidirectional conversations and Python-defined custom tools and hooks. The package bundles the Claude Code CLI by default, with options to use a system installation or set a custom path. Claude can use the Claude Code toolset, and applications process the resulting messages and content blocks. The SDK is tied to the Claude Code ecosystem; the README does not state model usage prices or credential requirements.

After installing claude-agent-sdk, a Python program can send a prompt to Claude Code with query(prompt=...) and asynchronously read response messages. ClaudeAgentOptions configures the working directory, system prompt, turn limit, tool approvals, and permission mode. For interactive sessions, ClaudeSDKClient sends queries and receives responses; @tool and create_sdk_mcp_server register in-process Python tools, while hooks run deterministic logic at specific points in the agent loop. Applications can inspect types such as AssistantMessage and TextBlock, and catch CLI connection, process, result, or JSON decoding errors.

  1. Python application developers adding Claude Code queries to an existing application.
  2. Teams processing response messages in interactive Claude Code sessions.
  3. Teams exposing existing Python functions as in-process MCP tools for Claude to call.
  4. Engineering teams applying deterministic checks or blocking logic before tools such as Bash run.

How do you install or deploy this agent?

Requires Python 3.10+. The package bundles the Claude Code CLI automatically. If you prefer a system installation or a specific version, install the CLI separately or set its path with ClaudeAgentOptions(cli_path=...).

How do you use this agent?

Minimal async invocation:

pip install claude-agent-sdk
import anyio
from claude_agent_sdk import query

async def main():
    async for message in query(prompt="What is 2 + 2?"):
        print(message)

anyio.run(main)

What are this agent's strengths and limitations?

Pros
  • query() provides a straightforward async message stream for embedding in Python programs.
  • ClaudeSDKClient supports bidirectional conversations, Python-defined custom tools, and hooks.
  • The Claude Code CLI is bundled by default, and a custom CLI path can be configured.
Limitations
  • Core calls depend on the Claude Code CLI and ecosystem, limiting provider portability.
  • Requires Python 3.10 or later.
  • The README does not specify model usage costs, credentials, or offline operation, so adopters need to verify those conditions.

How does this agent compare with similar options?

Key facts side by side with the most closely related agents.

Agent Source review Form / cost Stars Updated Language Full support on
Claude Agent SDK for Python This agent 57 · Major gaps Library / SDK ★ 8.3k today Python Claude Code
Agno Agent Platform 41 · Major gaps FrameworkFree + model costs ★ 43k today Python —
OpenAI Agents SDK 64 · Some gaps Library / SDKFree + model costs ★ 30k today Python OpenAI API
Agently AI Application Runtime 63 · Some gaps Library / SDKFree + model costs ★ 1.7k 7d ago Python OpenAI API · Claude API

How does FollowAgents rate this agent?

FollowAgents source review · FARS-2.1
Major gaps
57/ 100 5-point scale 2.9 / 5
Trust 12/29
Reliability 9/14
Adaptability 12/18
Convention 12/18
Effectiveness 7/13
Verifiability 5/8
Why each dimension lost points
Trust12 / 29 · 2.1/5

The README explains that allowed_tools auto-approves listed tools, while permission_mode and can_use_tool decide the rest; it also describes disallowed_tools and hooks. However, the full Claude Code toolset is available by default, and examples pre-approve Bash and accept edits, with no general per-action confirmation guarantee shown. Least privilege and confirmation are therefore only partially addressed. Data flows through the Python SDK, Claude Code CLI, Claude service, and optionally external MCP subprocesses. The README outlines some architecture, but the supplied files do not describe sensitive-data retention, redaction, or access controls, so transparency and sensitive-data handling are thin. Release workflows hash-pin build dependencies, use PyPI trusted publishing, and isolate the changelog job from publishing credentials, supporting a score of 2 for dependency security. Tools can write files, run Bash, and access MCP services, while no general undo or recovery mechanism is shown; external effects and rollback are only partially addressed. README, package metadata, license, and release workflow identify the Anthropic project and update path, providing solid attribution evidence.

Reliability9 / 14 · 3.2/5

README, pyproject, and test configuration are broadly consistent on package identity, Python versions, async interfaces, and dependency ranges. Test files show checks for build, release tooling, and changelog structure, but static review cannot establish that tests ran, so self-consistency scores 2. Core dependencies have version bounds, the CLI is bundled in wheels, and a custom CLI path is supported; network services, platform builds, and external MCP servers remain dependencies, so availability is not fully assured. The README lists structured exception types and handling examples; failure reporting is reasonably covered, though not every runtime failure path is shown.

Adaptability12 / 18 · 3.3/5

The SDK targets Python developers. The README covers simple queries, interactive clients, tools, hooks, working directories, prompt configuration, and internal or external MCP scenarios. It supports Python 3.10–3.13 and offers CLI path configuration, a tool allowlist, and hooks, making common scenarios and capability boundaries clear. Environment guidance is useful, but CLI compatibility requirements are specified only for some features, so these criteria earn adequate rather than full marks.

Convention12 / 18 · 3.3/5

The README is organized around installation, quick start, features, types, error handling, and development and release. Prerequisites and examples for major usage patterns are clear, though FAQ and limitations coverage is sparse, especially for data governance and risk boundaries. Package names, metadata, and API concepts are consistent. The complete MIT license text merits full marks. SDK and bundled CLI versions have a clear, separate release process, and a changelog and automated release path are present. Anthropic authorship, repository identity, and publishing workflows identify maintenance responsibility, but there is no more detailed maintenance commitment, so this does not receive full marks.

Effectiveness7 / 13 · 2.7/5

The SDK provides async message streams, interactive sessions, custom tools, and hooks, with output that callers can consume. Its documented integrations offer practical value compared with invoking the CLI directly. Examples and exception types aid use. The files support the claimed added value, but do not quantify cost-benefit or sufficiently detail CLI size, network/API usage, or deployment costs, so cost-benefit scores 1.

Verifiability5 / 8 · 3.1/5

The README links key API descriptions to source files, and configuration, dependencies, license, and release processes can be cross-checked across supplied files. Test source contains inspectable assertions for build and version constraints, but this review does not infer that they ran or passed. Documentation generally separates interface facts from examples; performance and deployment benefits remain claims without independent corroboration, so these criteria score 2 rather than full marks.

Risks and how to mitigate them
  • The default toolset includes file writes and Bash. Callers should configure tool permissions and approval policy explicitly and review access granted to custom tools and MCP servers.
  • The supplied files do not explain retention, redaction, or access controls for sensitive prompts or code. Assess these against applicable Anthropic service terms and your own data requirements before use.
  • This static review did not execute code or tests and did not verify release artifacts, runtime behavior, or external service availability.
Evidence confidence: Low Reviewed Oct 21, 2026 Reviewed revision beffc5007a5a
See the full review method →

FAQ

Do I need to install the Claude Code CLI separately?
No. The package bundles it by default. You can also install a system version or set a path with ClaudeAgentOptions(cli_path=...).
How do query() and ClaudeSDKClient differ?
query() returns an async iterator of response messages. ClaudeSDKClient supports bidirectional conversations and adds custom tools and hooks.
How can I control which tools Claude uses?
allowed_tools auto-approves listed tools; it does not remove other tools from the toolset. Unlisted tools are handled by permission_mode and can_use_tool. Use disallowed_tools to block specific tools.
Which errors can the SDK report?
It provides error types including CLINotFoundError, CLIConnectionError, ProcessError, ResultError, and CLIJSONDecodeError.
View on GitHub ↗ Install ↓

Compare agents like this one

The same FARS review applied across the shortlist this agent qualifies for.

Related agents