gitwtfhub

wtf is claude-agent-sdk-python?

anthropics/claude-agent-sdk-python — explained in plain English

Analysis updated 2026-06-24

6,844PythonAudience · developerComplexity · 3/5Setup · easy

TL;DR

A Python library that lets your code talk to Claude Code programmatically, send prompts, stream responses, define custom tools, and add hooks that control what the AI is allowed to do.

Mindmap

mindmap
  root((Claude Agent SDK))
    Core API
      query function
      Async streaming
      ClaudeSDKClient
    Tools
      Built-in file tools
      Custom Python tools
    Hooks
      Pre-tool intercept
      Block or modify actions
    Setup
      pip install
      Python 3.10 plus

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Build a Python script that uses Claude to automatically review or refactor code files in a repository

REASON 2

Define a custom tool so Claude can query your own database or call your API during a session

REASON 3

Add a hook that blocks Claude from running certain shell commands in automated pipelines

REASON 4

Run multi-turn conversations with Claude from a script without opening a browser

What's in the stack?

Pythonasyncio

How it stacks up

anthropics/claude-agent-sdk-pythonautoscrape-labs/pydollgoogle-research/arxiv-latex-cleaner
Stars6,8446,8416,838
LanguagePythonPythonPython
Setup difficultyeasyeasyeasy
Complexity3/52/52/5
Audiencedeveloperdeveloperresearcher

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 30min

Requires an active Claude Code installation, bundled in the package so no separate install needed.

Wtf does this do

The Claude Agent SDK for Python is a library that lets developers write Python programs that talk to Claude Code, the AI coding tool from Anthropic. Instead of interacting with Claude through a web interface, this SDK allows a Python script to send prompts and receive responses automatically, making it possible to build tools that use Claude as a component. The simplest use is the query function, which sends a prompt and returns an asynchronous stream of response messages. You can set a system prompt, limit how many turns the conversation runs, and specify which of Claude's built-in tools (such as reading files, writing files, or running shell commands) are automatically approved versus which require confirmation. For longer interactive sessions, there is a client class called ClaudeSDKClient. The client supports custom tools, which are Python functions you define and offer to Claude. When Claude decides it needs to use one, it calls your function directly within the same running program rather than starting a separate process. This avoids the overhead and complexity of managing external tool servers. Hooks are another feature of the client. A hook is a Python function that runs at specific points in the agent loop, such as just before Claude uses a tool. Hooks can inspect what Claude is about to do, block certain actions, or inject feedback. The example in the README shows a hook that blocks any shell command containing a particular pattern. The SDK bundles the Claude Code command-line tool, so no separate installation is needed. The package requires Python 3.10 or newer and is installed through pip, the standard Python package manager. The full README is longer than what was shown.

Yoink these prompts

Prompt 1
Using the Claude Agent SDK for Python, write a script that sends a coding task to Claude, auto-approves file read and write tools, and streams the output to the console.
Prompt 2
Show me how to define a custom Python tool for the Claude Agent SDK that queries a SQLite database and returns rows to Claude.
Prompt 3
Write a hook for the Claude Agent SDK that intercepts any bash tool call containing 'rm -rf' and blocks it with an error message.
Prompt 4
Using ClaudeSDKClient, create a Python script that runs a multi-turn session where Claude refactors a Python file step by step and asks for approval before each change.

Frequently asked questions

wtf is claude-agent-sdk-python?

A Python library that lets your code talk to Claude Code programmatically, send prompts, stream responses, define custom tools, and add hooks that control what the AI is allowed to do.

What language is claude-agent-sdk-python written in?

Mainly Python. The stack also includes Python, asyncio.

How hard is claude-agent-sdk-python to set up?

Setup difficulty is rated easy, with roughly 30min to a first successful run.

Who is claude-agent-sdk-python for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.