Anthropic releases Claude Agent SDK for building AI agents

In a March 14 tutorial on Mager’s blog, its author builds a working terminal client for Claude in about 80 lines of TypeScript. The Claude Agent SDK handles the part that normally takes the most code: the loop that runs tools and feeds their results back to the model.
With the standard Anthropic client SDK, that loop is yours to write. You call messages.create, check whether stop_reason is "tool_use", run the tool yourself, send the result back and repeat. “You write this loop. Every time,” says the comment in Mager’s sample. The Agent SDK replaces all of that with a single query() call that takes a prompt and an allowedTools list, wrapped in for await. The agent reads files, runs commands and edits code by itself, and your code just consumes the stream of messages. The built-in tools are Read, Write, Edit, Bash, Glob, Grep, WebSearch and WebFetch. Mager calls this “Claude Code’s entire toolset, programmable.”
The package used to be the Claude Code SDK. When Anthropic renamed it, the TypeScript package moved from @anthropic-ai/claude-code to @anthropic-ai/claude-agent-sdk and the Python one from claude-code-sdk to claude-agent-sdk. The Python options type ClaudeCodeOptions became ClaudeAgentOptions. Anthropic’s migration guide says the new name reflects capabilities that go beyond coding tasks. Mager’s tutorial sticks to TypeScript and points to pip install claude-agent-sdk for Python. The SDK also supports MCP and subagent delegation, which the tutorial mentions but doesn’t build on.
Mager’s pitch is “same engine that powers Claude Code.” That holds for the tools and the loop, but the instructions are a different matter. Since v0.1.0 the SDK uses a minimal system prompt by default, and you have to request the Claude Code preset explicitly. So the bare query() calls in the tutorial run Claude Code’s tools without Claude Code’s own prompt. Settings work the other way. If you leave out settingSources, the SDK loads user, project and local settings just as the CLI does, including ~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json, CLAUDE.md files and custom commands. That means a repository’s CLAUDE.md already reaches a custom client with no extra code, which covers part of what Mager means by preloading “context your team cares about.”
The client itself has three files. agent.ts wraps query() in an async generator, a function that hands back one message at a time as each arrives, so tool calls show up on screen while the agent is still working. App.tsx renders with Ink, a library that renders React components to the terminal: Box plays the role of a div, Text of a span, and useState and useEffect work as usual. Each assistant message is split into text blocks and tool_use blocks. Tool calls appear in yellow as ⚙ Bash({"command":"ls"}), the model’s replies in white and the final result in green. The stream carries four message types: assistant, result, system (the init event that carries the session ID) and user, which echoes the input. The entry point, index.tsx, is seven lines that join the command-line arguments into a prompt.
Two setup details save time. The demo runs on tsx instead of ts-node because it handles JSX and ESM without loader flags. And package.json needs "type": "module", because Ink’s layout engine, yoga-layout, uses top-level await. “You’ll hit a cryptic error without it,” Mager writes.
Memory between turns depends on that session ID. You capture session_id from the init message and pass it as resume to the next query(). The REPL version is a while (true) loop over readline that does exactly this. In the session demo, the first turn reads the auth module, and the second, “Now find everything that calls it”, answers with zero tool calls because the file is already in context. “No re-reading, no extra API calls,” according to the tutorial.
Hooks are where Mager says “the real power” lies. They are callbacks that fire at fixed points in the agent’s lifecycle. His audit example attaches to PostToolUse and appends a timestamp, the tool name and the first 100 characters of its input to audit.log on every call. matcher: ".*" catches everything, and "Edit|Write" narrows it to changes. PreToolUse can block an operation before it runs, Stop fires when the agent finishes, and UserPromptSubmit can check or rewrite input. Anthropic’s reference email agent combines all of these. It reads an inbox, drafts replies and sends them, with PreToolUse requiring approval before anything goes out, PostToolUse logging every action and session resume carrying context through a multi-step triage.
For interfaces that outgrow Ink, the tutorial rebuilds the same client in Rezi. Rezi is still TypeScript on Node.js, but it renders through a native C engine called Zireael and ships more than 50 widgets, including tables, modals, charts and a command palette. Instead of a React component tree, you write a view function that maps state to UI and change the state through app.update(). Mager compares it to the Elm Architecture in Go’s Bubble Tea. The agent stream feeds both versions the same way.
Mager’s own split: use the Claude Code CLI for daily development and one-off tasks, and the SDK for CI/CD pipelines, custom team tools, production automation, and anything that needs audit trails and permission control. Running the demo takes an Anthropic API key with credits.
For pipelines, Anthropic’s docs reverse the default. They say isolation from filesystem settings is especially important for CI/CD, deployed applications, test environments and multi-tenant systems, so local customizations don’t leak in. To run isolated, pass settingSources: [], or setting_sources=[] in Python.
Up next
Anthropic founders’ net worth surpasses $16 billion each
The seven Anthropic co-founders are now worth $16.6 billion each. All have pledged to give away 80% of their wealth, an unusual move among tech billionaires.
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 to leave a comment. It appears after moderation.

