Framework · Agent SDKs

Claude Agent SDK

Embed Claude Code's autonomous agent loop — same tools, same context management — as a programmable library in Python or TypeScript so production agents can read files, run commands, edit code, and execute multi-step workflows.

Description

The Claude Agent SDK is Anthropic's Python and TypeScript library for building agents that run Claude Code's loop inside your own process. It gives you the same tools, agent loop, and context management that power Claude Code, programmable in either language. The SDK exposes built-in tools (Read/Write/Edit/Bash/Glob/Grep/WebSearch/WebFetch/Agent/Skill), MCP servers (in-process and external), filesystem-defined Agents, Skills and Slash Commands under .claude/, hooks, and a canUseTool approval callback. It is the renamed successor of the Claude Code SDK; distinct from the lower-level Anthropic Client SDK (where you implement the tool loop) and from Managed Agents (Anthropic-hosted sandbox).

Solution

Imperative query() / ClaudeSDKClient loop that wraps the Claude Code harness. Receive prompt → evaluate and respond → execute tools → repeat → return result. Turns continue until Claude produces output with no tool calls. Caller caps the loop with max_turns / maxTurns, max_budget_usd / maxBudgetUsd, effort, and permission_mode. Subagents spawn via the Agent tool, run with their own fresh context, and return a single final message. Sessions persist as JSONL under ~/.claude/projects/ and can be resumed, continued, or forked.

Primary use cases

  • production coding agents that mirror the Claude Code shape
  • agents that need filesystem + bash + browser tools out of the box
  • agents with mid-run approval gates via canUseTool
  • agents using Anthropic skills and MCP servers

Open the full interactive page

Diagram, neighbourhood map, code examples, related patterns and full provenance.

Related