1:1 mentoring with Big Tech AI engineers
LLM & Agentic

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

Core9 min readFirst readWho Owns the Loop

After this section you can

  • Run a Claude Agent SDK agent and name every message type it yields, in order
  • Configure tools, approvals, turn and budget limits through ClaudeAgentOptions
  • Handle every ResultMessage subtype, and choose between query() and ClaudeSDKClient
27

Your First Agent SDK Agent

Ten lines give you an agent that can read files, search and run commands. The work is not the loop. It is reading what the loop yields and deciding what the agent may touch.

Key idea

The Claude Agent SDK is Claude Code as a library. You call query(prompt, options); the bundled harness runs the loop, executes tools on your machine, and streams back typed messages, ending with a ResultMessage that says how the run ended and what it cost.

Your code calls query(); the bundled Claude Code harness runs the loop and streams back typed messages
ONE query() CALL your code query(prompt, options) async for msg in … you read, you never loop Claude Code harness bundled with the SDK, runs as a subprocess the loop · permissions · hooks context management and compaction built-in tools: Read, Edit, Bash, Grep … claude-agent-sdk Claude API claude-opus-5 one request per turn returns tool_use or text your machine · cwd files, shell and network the tools act on 1 · prompt 4 · messages 2 · request tool_use 3 · run tool Steps 2 and 3 repeat once per turn. You never build a request; you read the transcript the harness yields.

Related

More in LLM & Agentic

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium