The Claude Agent SDK
Explore how the Claude Agent SDK simplifies building complex agent loops by integrating built-in and custom tools, managing permissions, and enabling sub-agent delegation. Understand how to maintain sessions with ClaudeSDKClient, use hooks to control tool calls, and configure agents for efficient multi-step workflows in customer-facing applications.
A Messages API tool loop is code we write and maintain ourselves. We send the conversation, read stop_reason, run each tool, return the results, and repeat. That control is valuable, and it also means every customer project rebuilds the same loop, the same permission checks, and the same logging.
The Claude Agent SDK is a library that runs Claude Code’s agent loop inside our own Python application. It gives us the loop, a set of built-in tools, permissions, hooks, sessions, and sub-agents, all configured through one options object. We decide what the agent may do, and the SDK runs the turns.
The SDK installs with pip install claude-agent-sdk and bundles the Claude Code command-line tool it drives, so no separate installation is needed. The examples here use version 0.2.163 with Python.
What the Agent SDK packages
The SDK brings Claude Code’s capabilities into a library. Six of them matter most when building agents for customers:
Agent loop: The SDK sends requests, runs tools, and feeds results back until the task is done.
Built-in tools: Ready-made tools such as
Read,Write,Edit,Bash,Glob,Grep,WebSearch, andWebFetch.Custom tools: Our own Python functions, exposed to Claude as tools.
Permissions: Rules that decide which tools run automatically, which are blocked, and which need approval.
Hooks: Callbacks that run our code at points in the agent’s work, such as just before a tool call.
Sessions and sub-agents: Conversations that keep context across turns, and specialized agents the main agent can delegate to.
The table below compares how each capability works with the Messages API and with the Agent SDK.
The trade is control for speed. The Messages API suits narrow workflows that need full control of each call. The Agent SDK suits agents that take many steps or need sessions, and many engagements use both.
These capabilities share one entry point, the query() function.