Anthropic Agent SDK: Use Claude Code's Engine in Your App

June 23, 2026 · How Claude Actually Works (part 18)

▶ Watch on YouTube & subscribe to The Stack Underflow

Claude Code is an impressive CLI tool, but sometimes you do not want a human at the wheel. You want your own code to drive the agent loop — headless, automated, embedded in a service. That is exactly what the Anthropic Agent SDK is for. It takes the same engine that powers Claude Code and packages it as an importable library for Python and TypeScript.

This tutorial unpacks what the Agent SDK actually is, how it relates to Claude Code, and when you would reach for one versus the other.

The one-sentence version: The Agent SDK is Claude Code’s agent engine exposed as a library, so your application code can drive the same loop, tools, and building blocks that the CLI uses — without running the CLI at all.

The layer model: one engine, two entry points

The series has been building up a layered picture of how Claude works. The Agent SDK is best understood as “layer four” in that stack — but critically, it does not replace the layers below it. It is those layers, re-exposed with a programmatic interface.

┌──────────────────────────────────┐
│         Claude Code (CLI)        │  ← human at the wheel
├──────────────────────────────────┤
│    Your App via Agent SDK        │  ← your code at the wheel
├──────────────────────────────────┤
│      Agent Loop + Tools          │  ← shared engine
├──────────────────────────────────┤
│    Context / Token Management    │
├──────────────────────────────────┤
│     Claude API (Anthropic)       │
└──────────────────────────────────┘

Both Claude Code and an Agent SDK app sit on top of the same middle layer. They share the same agent loop, the same context management, the same tool infrastructure. This is not a simplified clone of Claude Code built for developers — it is the same engine.

What ships in the box

The TypeScript package is particularly convenient: it includes the Claude Code binary as an optional dependency. You do not need a separate CLI install to get access to the built-in tools. Out of the box, your SDK-powered agent has access to:

ToolWhat it does
ReadRead files from the filesystem
BashExecute shell commands
EditApply targeted edits to files
WebSearchSearch the web for current information

These are the exact same built-in tools the CLI exposes to Claude when you run claude interactively. Your code gets them for free.

Beyond the built-in tools, every other building block from the CLI is reachable from the SDK: sub-agents, skills, hooks, all six agent lifecycle events, and MCP server connections. If you can wire it up in the CLI, you can wire it up in code.

A minimal working agent

The SDK reduces to three steps: create a client, register tools, run the loop on a task.

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

const agent = new ClaudeAgent();

const result = await agent.run({
  task: "Triage this CI failure: <paste logs here>",
  tools: ["bash", "read"], // built-ins, no extra config needed
});

console.log(result.output);

The loop spins on its own from there. It reads the logs, runs a command or two, proposes a fix, and returns when done. You supply the task; the SDK handles the reasoning and tool orchestration.

Choosing between Claude Code and the Agent SDK

The decision comes down to one question: who is at the wheel?

ScenarioUse
Developer working interactively in a terminalClaude Code (CLI)
Application, service, or headless job driving the agentAgent SDK
Automated pipeline (CI/CD, cron, backend worker)Agent SDK
One-off exploratory task with a human in the loopClaude Code (CLI)

Claude Code is the interactive, human-driven surface. The Agent SDK is the programmable, machine-driven surface. Same engine — different steering.

Billing: agent SDK credits (as of June 2026)

One practical detail worth knowing: on Anthropic subscription plans, Agent SDK usage draws from a separate monthly credit pool distinct from your interactive Claude Code limits. Using the SDK for automated jobs will not eat into your interactive quota, and vice versa. The credit systems are independent even though the underlying model and infrastructure are shared.

Common misconceptions

  • “The Agent SDK is a thin wrapper around the raw Claude API.” It is not. It includes the full agent loop, context management, tool orchestration, sub-agent support, hooks, MCP integration, and the built-in tools. The raw API is just the bottom layer; the SDK is everything above it packaged for programmatic use.

  • “I need to install Claude Code CLI separately before using the SDK.” The TypeScript package ships the Claude Code binary as an optional dependency, so one install gets you everything, including the built-in tools.

  • “The SDK gives me a stripped-down version of Claude Code’s capabilities.” No capability is removed. Sub-agents, skills, all six lifecycle events, and MCP server connections are all available. If the CLI can do it, the SDK exposes it.

  • “SDK usage counts against my interactive Claude Code quota.” As of June 2026, subscription plans maintain a separate Agent SDK credit pool. Interactive and automated usage do not compete for the same budget.

Frequently asked questions

Can I use the Agent SDK in Python, or only TypeScript? Both are supported. The video mentions Python and TypeScript explicitly. The TypeScript package has the additional convenience of bundling the Claude Code binary as an optional dependency, but Python users get the same agent loop and tool access.

Do I have to use the built-in tools, or can I register my own? You can do both. The built-in tools (Bash, Read, Edit, WebSearch) are available out of the box, and you can register additional custom tools alongside them. The tool registration step in agent.run() lets you mix and match.

What are “all six events” mentioned in the video? The agent loop emits lifecycle events at key points — things like when a tool call starts, when it completes, when the model generates a response, and so on. Hooks let you subscribe to these events to add logging, telemetry, approval gates, or any custom side-effect without modifying the core loop.

What does “managed agents” mean, and how is it different from the Agent SDK? The Agent SDK still requires you to host and run the agent process yourself. Managed agents (mentioned at the end of the video as the next topic) are a mode where Anthropic runs the agent infrastructure on your behalf — you hand off the task and Anthropic handles execution. The SDK is “self-hosted agent”; managed agents are “hosted agent.”

Where this fits in the series

This tutorial covers episode 18 of the How Claude Actually Works course. The series has been progressively layering the Claude stack — from raw token processing up through context management, tools, and the CLI. The Agent SDK is the point where the CLI’s internals become a first-class library. The next step, managed agents, goes one level further and removes even the need to run your own agent process. Browse all tutorials to see the full arc.

Found this useful? The deep version lives on YouTube — new breakdowns of how AI dev tools actually work, weekly.

Subscribe on YouTube →