Your First Agent SDK Agent
Run a Claude Agent SDK agent in ten lines: query() vs ClaudeSDKClient, every message type the stream yields, and configuring model, budget and tool restrictions through ClaudeAgentOptions.
Last updated
After this section you can
- Run a Claude Agent SDK agent and read every message type it yields
- Configure model, budget, turn limit and tool restrictions through ClaudeAgentOptions
- Choose between query() and ClaudeSDKClient
- Restrict tools with disallowed_tools rather than mistaking allowed_tools for a filter
Your First Agent SDK Agent
Ten lines gets you an agent with a filesystem, a shell and a search tool already attached. The work is not building the loop — it is deciding what to let it touch.
The Agent SDK is Claude Code as a library. You do not supply a loop, tools, or context management — those arrive built in. Your job starts at the options object: which tools, which permissions, which budget.
Install and run
# the Claude Code CLI ships bundled — nothing else to install
pip install claude-agent-sdk
import anyio
from claude_agent_sdk import query, AssistantMessage, TextBlock
async def main():
prompt = "What does config.py do? Read it first."
async for message in query(prompt=prompt):
if isinstance(message, AssistantMessage):
for block in message.content:
if isinstance(block, TextBlock):
print(block.text)
anyio.run(main)
That agent can already read files and run commands in the working directory. It is a real agent on the first run, which is the part worth being careful about.