- Problem: Building on Claude via Agent SDK, Claude API, or Claude Code can seem very similar; choosing the wrong one leads to redundant work or handover friction.
- Solution: Differentiate using a mental model—who handles the agent loop (harness) and who handles the infrastructure (deployment)—then use our delivery matrix.
- Result: A quick selection framework for every delivery scenario, along with a production checklist for AI agents.
Quick selection: If you need granular control and want to embed AI into your own product, use the Claude API. If you need an agent to read/edit files and run commands directly on your own infrastructure (scripts, CI/CD, automation workflows), use the Claude Agent SDK. If you want to work interactively in the terminal, use Claude Code. If you don't want to manage agent infrastructure, let Anthropic handle it with Managed Agents. Below is a decision matrix by delivery scenario, plus a checklist for moving agents to production.
TL;DR (Executive Summary)
- Problem: Agent SDK, Claude API, and Claude Code sound so similar that it is easy to choose based on intuition—and the cost of a wrong choice usually doesn't show up during coding, but rather during project handover or when the token bill arrives.
- Solution: Don't compare them by "which is better." Instead, ask two questions: who writes the agent loop (harness) and who manages the infrastructure to run it (deployment). These two axes cleanly categorize all four options.
- Result: A decision matrix tailored for real-world delivery scenarios (client POCs, internal automation, client-facing products, CI/CD, compliance) + a production checklist.
Where these three actually differ (from a delivery perspective)
While official documentation describes each tool clearly, when standing in the shoes of someone who has to choose and deliver, I find that two simple questions are enough to set them apart:
- Who writes the agent loop? — meaning the loop of "Claude calls tool → we execute tool → return results → Claude decides next step," along with context management during long conversations. Let's call this the harness.
- Who manages the infrastructure to run it? — the process, machine, sandbox, and session state storage. Let's call this the deployment.
Mapping them along these two axes:
- Claude API (Messages API with Tool Runner) — You define the tools, the SDK (or you) handles the loop, and you self-host. There are no built-in tools or sandboxes. This is the "least magical" level: you control every step, but you must wire everything yourself.
- Claude Agent SDK — Claude Code packaged as a library (
claude_agent_sdkfor Python,@anthropic-ai/claude-agent-sdkfor TypeScript). It carries the exact same harness as Claude Code: the agent loop, context management, and the built-in tools (Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch…), along with hooks, subagents, permissions, and sessions. You only provide the prompt and configuration, but you still self-host it (runs inside your own process). - Claude Code — The same harness, but as an interactive CLI to type in the terminal. Same capabilities as the Agent SDK, just a different interface.
- Managed Agents — Anthropic handles both the harness and the deployment: running the agent loop on Anthropic's infrastructure and provisioning a sandbox for each session. You send events and receive results via REST.
The most common point of confusion: Agent SDK is not the Tool Runner of the Claude API. Tool Runner (client.beta.messages.tool_runner in the anthropic / @anthropic-ai/sdk library) is just a thin helper that runs the loop for tools you define yourself—it doesn't have built-in tools or filesystem access. The Agent SDK (claude-agent-sdk) is the entire engine of Claude Code. They are two different packages operating at two different layers.
The ladder from high control to high convenience:
| Option | What you write | Who handles the agent loop | Who hosts it |
|---|---|---|---|
| Claude API — manual loop | Entire loop + tools | You | You |
| Claude API — Tool Runner | Just tool functions | SDK (thin helper) | You |
| Claude Agent SDK | Prompt + configuration | SDK (Claude Code harness) + built-in tools | You |
| Claude Code (CLI) | Interactive commands | Off-the-shelf product | You (your machine) |
| Managed Agents | Agent config + tool results | Anthropic | Anthropic (per-session sandbox) |
As you move down, you delegate more responsibilities (first the agent loop, then the entire infrastructure) to Anthropic—trading control for convenience.
Before choosing: Do you actually need an agent?
The most frequently overlooked question: An agent (multi-step, self-invoking tools, autonomous decision-making) consumes significantly more tokens and is less predictable than a direct request. I only escalate a task to an "agent" when it meets all four criteria:
- Multi-step & hard to specify upfront — like "translate this design doc into a PR" rather than "extract the title from this PDF."
- Cost-justified — the outcome outweighs the higher cost and latency.
- Feasible for Claude — matching the model's strengths.
- Recoverable from errors — accompanied by tests, review steps, or rollbacks to catch mistakes.
If any of these is missing, step down to a simpler approach: a single Claude API request (classification, summarization, extraction, Q&A) or a programmatically orchestrated workflow. This is rarely mentioned in generic introductory articles, but from a delivery standpoint, it saves the most resources: don't build an agent for a task that can be solved with a single SQL query.
Decision Matrix by Delivery Scenario
This is the matrix I actually use when scoping a project. The primary axis is the delivery scenario, not abstract technical specifications—because the deciding factor is usually "who will operate this once I hand it over," rather than "which one has more features."
| Scenario | Recommended | Why (Delivery Perspective) | Technical Criteria |
|---|---|---|---|
| Quick POC/demo to align scope with client | Claude Code (CLI) | Immediate interaction, pivot on the fly during meetings, zero infrastructure code to write | One-off, interactive |
| Embedding AI as a feature in your product, requiring structured outputs & tight control | Claude API (+ Tool Runner) | Expose only the required tools without pulling in the entire filesystem toolset; control and test every step | Custom harness, custom tools |
| Automating repetitive tasks for the team, running on your own machine/CI | Claude Agent SDK | The agent needs real file read/write and command execution on your infrastructure; ready-made harness saves you from building the loop | Self-hosted, built-in tools |
| CI/CD pipelines: reviewing PRs, generating code, running migrations | Claude Agent SDK (headless) | Non-interactive execution; hooks allow intercepting/logging actions before they occur | SDK, non-interactive + hooks |
| Shipping an autonomous agent product to a client, long-running/async sessions, want to avoid hosting sandboxes | Managed Agents | Anthropic manages the agent loop, per-session sandboxes, and versioning; saves you from running that infrastructure | Harness + deployment managed by Anthropic |
| Client (especially Japanese clients) requires data to never leave their infrastructure | Claude Agent SDK self-hosted | Runs inside your process and interacts with files on your infrastructure → easy to prove data residency | Self-hosted, egress control |
To summarize the matrix: internal automation on your infra → Agent SDK; embedded in your product with control → Claude API; quick interactive work → Claude Code; hands-off infrastructure → Managed Agents.
A few traps you only see in production
- The Agent SDK is surprisingly simple to invoke. At its core, it's just
query(prompt, options)returning a message stream. But "simple to run" does not mean "simple to put in production"—see the checklist below. - Auth: You cannot use claude.ai login for third-party products. The Agent SDK in your app must use an API key (or Bedrock/Vertex/Foundry). This means every client or agent session incurs token costs you need to monitor from day one; don't wait until the end of the project to realize this.
- Session state in the Agent SDK is a JSONL file on your filesystem. Very convenient for resuming/forking, but at handover, you must answer: who backs it up, who deletes it, and how long is it kept? For Managed Agents, state is kept in the event log hosted by Anthropic—trading convenience for control.
- Branding restrictions. A product built on the Agent SDK must not be named or branded as "Claude Code." It sounds minor, but it's something you must align on with the client before printing it on the UI.
AI Agent Production Checklist
Choosing the right tool is only half the battle. The other half—the part generic content farms never touch—is putting it in production without letting costs explode or losing control. For the Agent SDK and Claude Code, I look at six key points:
- Least-privilege for tools. Declare
allowed_tools(Python) /allowedTools(TS) to expose only what is necessary; block others usingdisallowed_tools. If an agent only needs to read files, do not enableBashorEdit. This is a security boundary, not a configuration detail. - Cap token costs. An agent loop consumes far more tokens than a standard request. Set a limit on the number of turns, choose the right model tier for the right step (don't use the strongest model for simple steps), and leverage prompt caching for static system contexts.
- Human-in-the-loop for irreversible actions. Use the
PreToolUsehook to intercept and ask for confirmation before the agent runs delete commands, pushes code, or hits external APIs. Use the appropriatepermission_modeto balance autonomy and safety. - Observability. Implement a
PostToolUsehook to write audit logs every time a file is modified or a command is run. When something goes wrong, you should be able to trace exactly what the agent did, not guess. - Separated auth & billing. Run API keys server-side and track usage per-client from day one. This is the exact data you will need when pricing the next phase.
- Handover scenario. Who operates it after you leave? Where are the JSONL session files stored? Who bears the cost if model pricing changes? Who manages the API keys? Answering these before shipping is what makes the agent truly "done."
Conclusion
The Claude Agent SDK, Claude API, and Claude Code are not ranked from best to worst; they sit on a spectrum of delegation. The higher you go, the more responsibility (first the loop, then the infrastructure) you hand over to Anthropic, trading control for convenience. Choosing correctly means choosing the right rung for the right situation—and always asking "does this actually need an agent?" at the start, and "who will operate this post-handover?" at the end.
If you want to dive deeper into specific parts: the overall picture of building on Claude is covered in Claude Platform 101; Messages API and tool use are explained in Building with the Claude API; Claude Code is explored in Claude Code 101; and subagents (which the Agent SDK reuses under the hood) are discussed in Introduction to Subagents. The complete learning path is compiled at [/learn/claude?lang=en].
Nguyễn Phúc Nguyên Châu
Delivery Manager
14 years of delivery experience (Websites, Systems, AI Automation) for the Vietnam–Japan market
Frequently Asked Questions
What is the difference between Claude Agent SDK and Claude API (Messages API)?
With Claude API, you write the tool loop and execute each tool manually. Claude Agent SDK packages the agent loop and built-in tools (Read, Write, Edit, Bash, Grep, WebSearch...) from Claude Code into a library; you only provide the prompt and configuration, though you get less granular step-by-step control.
Is Agent SDK the same as Claude Code?
They share the same harness but have different interfaces. Claude Code is a CLI for interactive terminal use. Agent SDK is a Python/TypeScript library to embed that same harness into your application, script, or CI/CD pipeline.
When should I NOT use an agent?
When the task is single-step and fully specifiable beforehand (like classification, summarization, extraction, or basic Q&A), a single Claude API request is enough. Agents are only worth the cost when the task is multi-step, hard to fully define upfront, and requires Claude to dynamically decide actions.
What should I choose if the client requires data to remain on their infrastructure?
Claude Agent SDK runs directly within your process and operates on files on your infrastructure, making it much better suited for strict data residency requirements than Managed Agents (which run in a sandbox hosted by Anthropic).