⚡ Activation

💭 in your head · nothing to type

Picture a small workshop you can call from your own program, not a chat you have to restart by hand. It has hands — tools, a memory — a session, and a stopping rule — so the work cannot run forever.

If you already know a task your agent should repeat, but you still start each run manually, where is the missing “start” button?

👁 Reflection

💭 in your head · nothing to type

The Agent SDK (tools for embedding an agent in a program) turns the agent loop into a library call. It is the same mechanism as Claude Code: the agent plans, calls tools, and checks its result, while your script sets the boundaries and receives the messages.

Think of handing the workshop a schedule. You do not rewrite how to use every tool, but you decide which tools are on the bench and when the craftsperson must stop.

Keep the Claude Code CLI for one-off interactive work. Use the SDK when the agent becomes part of automated build and deployment (CI/CD — continuous integration and delivery), an application, or an ongoing automation.

💡 Concept

What the SDK gives you

The Agent SDK exposes the Claude Code loop from Python or TypeScript: built-in Read, Edit, Bash, Grep, Glob, and web-search tools, plus MCP servers, hooks, skills, subagents, and sessions. With a client SDK, you would have to assemble the tool loop and file tools yourself.

Install it with:

npm install @anthropic-ai/claude-agent-sdk   # Node 18+
pip install claude-agent-sdk                 # Python 3.10+

Authentication has two roads, the same as in module 02. For yourself, the SDK uses the same sign-in as Claude Code (claude login, your subscription): keep ANTHROPIC_API_KEY unset, otherwise the SDK switches to the key and starts billing tokens. For a product, a client, or production automation the official quickstart describes ANTHROPIC_API_KEY — the client's key, not your subscription. Keep the key out of the repository and out of logs; plan terms change, so check the current documentation before you ship.

A minimal TypeScript agent:

import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Find and fix a bug in auth.py",
  options: {
    allowedTools: ["Read", "Edit", "Bash"],
    permissionMode: "acceptEdits",
    maxTurns: 10,
  },
})) {
  if ("result" in message) console.log(message.result);
}

Three safety controls