Repolode
anthropics

anthropics/claude-agent-sdk-python

Python SDK for building agents on Claude Code, with query(), an interactive client, in-process custom tools and hooks.

Stars
8,304
Forks
1,363
Open issues
571
Last commit
2 days ago

What is it?

The Claude Agent SDK for Python lets Python applications drive Claude Code programmatically. Install it with pip and call query() to send a prompt and iterate over the streamed response messages, or use ClaudeSDKClient for bidirectional, multi-turn conversations.

The package bundles the Claude Code CLI, so no separate installation is needed by default, though a system-wide install or a specific CLI path can be configured. By default Claude has access to the full Claude Code toolset such as Read, Write, Edit and Bash, and allowed_tools, disallowed_tools and permission_mode control approvals.

With ClaudeSDKClient you can define custom tools as Python functions that run as in-process MCP servers, and register hooks that run at points in the agent loop, such as blocking a Bash command before it executes. Typed options, message classes and error classes are provided for handling results.

Key features

  • 01Stream Claude Code responses from an async query() function.
  • 02Run multi-turn, interactive sessions with ClaudeSDKClient.
  • 03Define custom tools as in-process MCP servers using a Python decorator.
  • 04Register Python hooks that run at points in the agent loop.
  • 05Control tool permissions with allowed and disallowed tool lists and permission modes.

Use cases

  • Embedding a Claude coding agent inside a Python application or internal tool.
  • Adding domain-specific Python functions as tools that Claude can call.
  • Enforcing policies such as blocking certain shell commands with hooks.
  • Building automated workflows that run Claude Code against a project directory.

Quick start

  1. 1

    Install the SDK from PyPI

    pip install claude-agent-sdk
  2. 2

    Save the README quick start code as a Python file and run it with anyio

Things to know

  • Use is governed by Anthropic's Commercial Terms of Service, not the MIT license alone.
  • Requires Python 3.10 or later.
  • Querying Claude requires access to Anthropic's service and credentials.

Topics

FAQ

What is claude-agent-sdk-python?
Python SDK for building agents on Claude Code, with query(), an interactive client, in-process custom tools and hooks. The Claude Agent SDK for Python lets Python applications drive Claude Code programmatically. Install it with pip and call query() to send a prompt and iterate over the streamed response messages, or use ClaudeSDKClient for bidirectional, multi-turn conversations.
Is claude-agent-sdk-python free to use? What license does it have?
claude-agent-sdk-python is open source under the MIT license. Check the license terms before using it in commercial products.
Is claude-agent-sdk-python still maintained?
Actively maintained. The last commit to claude-agent-sdk-python was on Oct 19, 2026.
What can I use claude-agent-sdk-python for?
Embedding a Claude coding agent inside a Python application or internal tool. Adding domain-specific Python functions as tools that Claude can call. Enforcing policies such as blocking certain shell commands with hooks. Building automated workflows that run Claude Code against a project directory.
How do I install claude-agent-sdk-python?
Install the SDK from PyPI: pip install claude-agent-sdk Save the README quick start code as a Python file and run it with anyio
Where can I get claude-agent-sdk-python?
The source code and installation instructions are on GitHub: https://github.com/anthropics/claude-agent-sdk-python

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects