Agent SDK

The Claude Agent SDK exposes Claude Code’s full agentic engine as a programmable library. Available in Python (claude-agent-sdk) and TypeScript (@anthropic-ai/claude-agent-sdk).

What It Is

The same infrastructure that powers Claude Code, but programmable. Instead of interacting through a terminal, you build applications that use Claude’s agent loop: reading files, running commands, editing code, searching the web - all orchestrated by the model.

Two Levels

There’s an important distinction between the Client SDK and the Agent SDK:

Client SDK (anthropic)Agent SDK (claude-agent-sdk)
You manageThe tool loop, tool execution, message historyJust the prompt and configuration
Claude managesNothing - you call the APIThe full agent loop with built-in tools
Best forCustom tool implementations, fine-grained controlApplications that need Claude Code’s capabilities

The Agent Loop

Same loop as Claude Code:

prompt → Claude thinks → tool call → execute → observe → repeat → final response

The SDK handles all of this. You provide a prompt, and query() streams back messages as Claude works through the task.

Core API

Python

from claude_agent_sdk import query

async for message in query(
    prompt="Find all TODO comments in this project and create a summary",
    options={
        "model": "claude-sonnet-4-6",
        "permissionMode": "default",
    }
):
    if message.type == "text":
        print(message.text, end="")
    elif message.type == "tool_use":
        print(f"Using tool: {message.tool}")

TypeScript

import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Find all TODO comments in this project and create a summary",
  options: {
    model: "claude-sonnet-4-6",
    permissionMode: "default",
  },
})) {
  if (message.type === "text") {
    process.stdout.write(message.text);
  }
}

Built-in Tools

The Agent SDK comes with the same tools as Claude Code:

ToolPurpose
ReadRead file contents
EditTargeted file edits
WriteCreate new files
BashRun shell commands
GlobFind files by pattern
GrepSearch file contents
AgentSpawn subagents
WebSearchSearch the web
WebFetchFetch web pages

Custom Tools via MCP

Add custom tools by creating in-process MCP servers:

from claude_agent_sdk import query, create_sdk_mcp_server

server = create_sdk_mcp_server("my-tools")

@server.tool
def lookup_user(user_id: str) -> str:
    """Look up a user by their ID."""
    return db.get_user(user_id).to_json()

async for msg in query(
    prompt="Look up user 123 and summarize their recent activity",
    options={"mcpServers": [server]},
):
    print(msg)

Subagents

Define specialized agents with isolated context, restricted tools, and model overrides:

from claude_agent_sdk import query, AgentDefinition

security_agent = AgentDefinition(
    name="security-reviewer",
    instructions="Review code for security vulnerabilities. Focus on injection, auth bypass, and data leaks.",
    model="claude-opus-4-6",
    tools=["Read", "Grep", "Glob"],
)

async for msg in query(
    prompt="Review the auth module for security issues",
    options={"agents": [security_agent]},
):
    print(msg)

Non-Coding Uses

The Agent SDK isn’t limited to coding tasks:

  • Deep research - search the web, read pages, synthesize findings
  • Content creation - generate documents from templates and data
  • Data processing - read files, transform data, write outputs
  • Note-taking - capture and organize information from multiple sources

Key Features

FeatureDescription
HooksPreToolUse, PostToolUse, Stop, SessionStart, SessionEnd lifecycle events
SessionsCapture session_id, resume with full context
Extended thinkingInternal reasoning blocks for complex problems
Computer useGUI automation via screenshots + mouse/keyboard
MCP nativestdio, HTTP, SSE transports with wildcard permissions
ProvidersAnthropic, Bedrock, Vertex AI, Azure AI Foundry

Next