Skip to main content

claude-runner

PyPI version License: MIT Python

The easiest way to build AI agents with Claude in Python. 5 lines to start.

The official SDK is an engine 🔧 — claude-runner is the car 🚗.

A thin, clean wrapper around the Anthropic SDK. Zero required dependencies.

claude-runner-py demo

from claude_runner import Runner

runner = Runner(api_key="sk-ant-...")
result = await runner.run("Analyze this codebase and suggest improvements")
print(result.text)

Also available as a TypeScript/npm package.

Install

# API Mode — no CLI needed, deploys anywhere
pip install claude-runner-py[api]

# Agent Mode — full Claude Code power (needs CLI)
pip install claude-runner-py[agent]

# Everything
pip install claude-runner-py[all]

Quick Start

Simple await

import asyncio
from claude_runner import Runner

async def main():
    runner = Runner(api_key="sk-ant-...")
    result = await runner.run("Fix the failing tests in this project")

    print(result.text)
    print(f"Cost: ${result.cost:.4f}")
    print(f"Turns: {result.turns}")

asyncio.run(main())

Streaming

claude-runner-py streaming demo

async for event in runner.stream("Refactor the auth module"):
    match event.type:
        case "text":
            print(event.text, end="", flush=True)
        case "tool_start":
            print(f"  → {event.tool}")
        case "tool_end":
            print(f"  ← {event.tool} ({event.duration:.0f}ms)")
        case "done":
            print(f"\nCost: ${event.result.cost:.4f}")

Custom Tools

from claude_runner import Runner, define_tool, ToolResult

async def get_weather(city: str) -> ToolResult:
    return ToolResult(content=[{"type": "text", "text": f"72°F and sunny in {city}"}])

weather = define_tool(
    "get_weather",
    "Get current weather for a city",
    {"city": {"type": "string"}},
    get_weather,
)

runner = Runner(api_key="sk-ant-...", tools=[weather])
result = await runner.run("What's the weather in San Francisco?")

CLI

# With API key
ANTHROPIC_API_KEY=sk-xxx claude-runner "Analyze this codebase"
claude-runner --api-key sk-xxx "Fix the tests"

# Choose model
claude-runner -m opus "Refactor the auth module"

# JSON output
claude-runner --json "What files are in this project?"

API Mode vs Agent Mode

API Mode Agent Mode
Requires API key only Claude CLI
Built-in tools Bring your own Read, Write, Bash, Edit
Custom tools define_tool() define_tool()
Deploys to Anywhere Machines with CLI
Cost model Pay-per-token Claude subscription

Models

Runner(model="opus")       # claude-opus-4-6
Runner(model="sonnet")     # claude-sonnet-4-6
Runner(model="haiku")      # claude-haiku-4-5
Runner(model="opus-4.5")   # claude-opus-4-5-20250918
Runner(model="sonnet-4.5") # claude-sonnet-4-5-20250514

Real-World Use Cases

FastAPI endpoint

@app.post("/chat")
async def chat(message: str):
    runner = Runner(api_key=os.environ["ANTHROPIC_API_KEY"])
    result = await runner.run(message)
    return {"reply": result.text, "cost": result.cost}

Data analysis

runner = Runner(api_key=key, model="haiku")
result = await runner.run(f"Analyze this CSV:\n{csv_data}")

Slack bot

@app.event("message")
async def handle(event):
    runner = Runner(api_key=key, tools=[search_docs, query_db])
    result = await runner.run(event["text"])
    await say(result.text)

Examples

Example Description Run
Code Reviewer Reviews codebase for bugs python examples/code_reviewer.py
Chatbot Chat with custom tools python examples/chatbot.py
FastAPI Agent REST API endpoint uvicorn examples.fastapi_agent:app

API Reference

Runner

class Runner:
    def __init__(self, **kwargs) -> None
    async def run(self, prompt: str) -> RunResult
    async def stream(self, prompt: str) -> AsyncIterator[RunEvent]
    @property
    def last_session_id(self) -> str | None

RunResult

@dataclass
class RunResult:
    text: str
    session_id: str
    cost: float          # USD
    duration: float      # ms
    usage: dict          # {"input": N, "output": N}
    turns: int
    tool_calls: list[ToolCallSummary]
    error: str | None

RunEvent types

Type Fields When
text text Each streamed chunk
tool_start tool, id, input Tool begins
tool_end tool, id, duration Tool ends
session_init session_id, model, tools Session started
error message, code Error occurred
done result Run complete

RunnerOptions

Option Type Default Description
api_key str — Anthropic API key (enables API Mode)
model str sonnet Model shorthand or full ID
system_prompt str — System prompt
tools list — Custom tools via define_tool()
mcp dict — MCP servers (shorthand strings supported)
permissions str deny-unknown auto, prompt, deny-unknown
max_turns int 50 Max agentic turns
max_budget float — Max cost in USD

Links

License

MIT

Metadata

Release files for claude-runner-py 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for claude-runner-py 0.1.1
File Size Uploaded Provenance
claude_runner_py-0.1.1.tar.gz 785.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for claude-runner-py 0.1.1
File Interpreter ABI Platform
claude_runner_py-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 800.9 kB

Release files / claude_runner_py-0.1.1.tar.gz

Download URL claude_runner_py-0.1.1.tar.gz
Size 785.5 kB
Tags Source
SHA-256 checksum
How to use checksums
952332f5701502cf01eae849975d2fd55f7c82b2bb3afe276c41c7af010a31d2
BLAKE2b-256 checksum
How to use checksums
1a31bf0d5b640cd3b7f516b4b97fbb56b2dc1163b75ec98c0b780bebb81a386e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Release files / claude_runner_py-0.1.1-py3-none-any.whl

Download URL claude_runner_py-0.1.1-py3-none-any.whl
Size 15.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7482cce723977d7eddf7379de7cb5e6da7ff73160aabaf84a708cfc81f42ded2
BLAKE2b-256 checksum
How to use checksums
0325a4017349a42351b7d8a002acc69fefa985b7088939365c234fa535cefd29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.4

Security for claude-runner-py 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page