Anthropic releases Claude Agent SDK for building AI agents

The Claude Agent SDK packages the agent loop behind Claude Code as a library: a single query() call, eight built-in tools and a for await stream the calling code controls. A walkthrough published by Mager builds a working terminal client on top of it in roughly 80 lines of TypeScript.
At a glance
- Instead of the hand-written while loop over stop_reason "tool_use" that the standard Anthropic client requires, the SDK executes tools internally and streams assistant, tool_use and result messages back to the caller.
- Read, Write, Edit, Bash, Glob, Grep, WebSearch and WebFetch ship with the runtime, and the allowedTools option narrows that set per session, so a review agent can be denied write access.
- Hooks such as PreToolUse and PostToolUse and the resume option for session IDs give teams audit trails, approval gates and context that survives across separate query() calls.
The split between the API and the SDK reads as a division of labour: the API sells model access, the SDK sells the runtime around it, including tool execution, permissions and session state. That likely matters most to teams that have already written the same tool-dispatch loop several times, and to anyone who wants Claude Code behaviour inside CI, a bot or an internal tool rather than an interactive terminal session.
Eight built-in tools cover the full Claude Code toolset
With the standard Anthropic client, tool use is the caller's problem: the code inspects stop_reason, dispatches the call to its own executor and sends the result back in a fresh messages.create request. The Agent SDK collapses that into query({ prompt, options }), iterated with for await.
The bundled tools are Read, Write, Edit, Bash, Glob, Grep, WebSearch and WebFetch: file access, precise edits, shell and git commands, pattern and regex search over files, plus web search and URL fetching. According to Mager, that is Claude Code's entire toolset exposed programmatically, with allowedTools controlling which of them a given run may touch.
A working Ink terminal client runs to about 80 lines of TypeScript
The demo at github.com/mager/claude-tui-demo wraps query() in an async generator, then renders the stream with Ink, which maps React components onto the terminal: Box for layout, Text for coloured output, useState and useEffect unchanged. The entry point is seven lines, reading the prompt from process.argv.
The SDK streams several message types: assistant for Claude's output, result for the final outcome, system with an init event carrying the session ID, and user for echoed input. Mager flags two setup traps, namely that the demo runs on tsx rather than ts-node, and that package.json needs "type": "module", because Ink's yoga-layout engine uses top-level await.
The same repository includes a rebuild on Rezi, a state-driven TypeScript toolkit with more than 50 widgets and native rendering through a C engine, where a view function maps state to UI and app.update() replaces hooks, alongside six built-in themes and semantic colour variants.
Hooks and session resume add audit logs and cross-call context
Hooks fire at points in the agent lifecycle. The demo registers a PostToolUse hook with matcher ".*" that appends a timestamp, tool name and truncated arguments to audit.log on every call; PreToolUse can block an operation before it runs, Stop detects completion and UserPromptSubmit pre-processes input.
Session state travels through the system init message: the caller stores session_id and passes it as resume on the next query(). In the demo's session example the second turn issues zero tool calls, because the file read in the first turn is still in context. A readline REPL applies the same mechanism in a while loop.
Python, MCP and the email agent
The SDK is also available for Python through pip install claude-agent-sdk, and supports MCP servers and subagent delegation. Anthropic publishes a reference email agent that reads an inbox, drafts replies and sends them, combining PreToolUse approval, PostToolUse logging and session resume across a multi-step triage workflow. Documentation and the reference agents sit at platform.claude.com/docs/en/agent-sdk/overview and github.com/anthropics/claude-agent-sdk-demos; running the demo requires an Anthropic API key with credits.
Related stories
- Anthropic hits pause on Claude Agent SDK credit changes
- Claude Code sessions can now talk to each other
- Claude Code has four kinds of agent loops: /goal, /loop, /schedule
- Letting Claude filter its own tool output took Opus 4.6 from 45.3% to 61.6% on BrowseComp
- A hardcoded instruction in Claude Code 2.1.219 and 2.1.220 blocks Opus 5 from spawning sub-agents
- Analysis of the agent control model in Claude Code
Comments
No comments yet. Be the first.
Join the conversation
Sign in with Google to leave a comment. Your name and avatar come from your Google profile, and the comment appears after moderation.
