Claude Agent SDK Documentation
The official docs for Anthropic's Claude Agent SDK, which runs the Claude Code agent loop inside your own Python or TypeScript program: built-in file, shell and web tools, permissions, hooks, subagents, sessions, custom tools as in-process MCP servers, and hosting guidance.
8.2k (Python SDK)
GitHub · Sept 2026
1.8k (TypeScript SDK)
GitHub · Sept 2026
Guide
AI & Machine Learning
Anthropic
A weekend to build a first agent
Intermediate
Free
What the Claude Agent SDK is
The Claude Agent SDK gives you the same agent loop, tools and context management that power Claude Code, as a library you call from Python or TypeScript. You pass a prompt and options to query(), and the SDK drives the whole loop: Claude plans, reads and edits files, runs commands, searches the web and calls your own tools until the task is done, streaming messages back as it works.
The documentation covers:
- Quickstart: install
claude-agent-sdk(Python 3.10 or newer) or@anthropic-ai/claude-agent-sdk(Node.js 18 or newer), set an API key and build an agent that finds and fixes bugs in a file. - Built-in tools: Read, Write, Edit, Bash, Glob, Grep, WebSearch and WebFetch.
- Permissions: allowed and disallowed tools, permission modes, and how rules are evaluated.
- Hooks: your code runs before or after tool calls to log, block or change them.
- Custom tools: define tools with
@toolortool()and a schema, wrap them in an in-process MCP server and pre-approve them by name. - Subagents, sessions, skills and plugins, plus connecting external MCP servers.
- Hosting: running agents in Docker, cloud and CI.
When it is the right choice
It fits agents that work on files, code and commands: repository maintenance, report generation, data clean-up or research that writes files. It is less suited to a simple chat assistant with a few API tools, where the plain Messages API or a lighter framework is enough. The overview page includes a comparison table of the Agent SDK, the Claude Code CLI, the client SDK and Managed Agents to help you choose.
Prerequisites and time
You should be comfortable with async code in Python or TypeScript and have written a basic tool loop, ideally from the tool use docs. The quickstart takes under an hour; a useful agent with custom tools, permissions and hooks is a weekend project.
Free or paid?
The SDK is free to install. Usage is billed through your Anthropic API key, or through Amazon Bedrock, Google Cloud or Microsoft Foundry if you configure those. Use of the SDK falls under Anthropic's Commercial Terms, and the docs include branding rules if you ship a product on it.
What you can do after it
Build an autonomous agent that works on a codebase or document folder, give it your own tools through MCP, restrict what it may do with permissions and hooks, and deploy it as a background job.
Common questions
Is it the old Claude Code SDK? Yes, it was renamed, and the docs include a migration guide from the earlier packages.
Can I use it with a claude.ai subscription? The docs say third-party products must use API key authentication unless Anthropic has approved otherwise.
Ready to start?
Opens on Anthropic in a new tab.
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
Follow along
New writing, resources and project ideas land here first.