Claude Agent SDK: we built a coding agent and tested it
We built a 30-line coding agent with the Claude Agent SDK and ran it on our secret coding jobs. It passed every check, but by default it also loaded our own Claude Code settings.
The Claude Agent SDK lets you put Claude Code's AI agent inside your own program. An agent is an AI that plans its own steps: it reads files, changes code and runs commands until a job is done. We installed the SDK, built a small coding agent of about 30 lines, and gave it the same secret coding jobs as our Claude Code tests. It passed every check, in every setup. But out of the box, it also loaded our own personal Claude Code settings, which made each job about 18% more expensive.
What is the Claude Agent SDK?
An SDK is a set of building blocks for programmers. The Claude Agent SDK gives you the agent behind Claude Code as a library. You get the same tools to read and edit files and run commands, and the same permission rules. You also get the same loop in which the AI keeps working until the job is done. Anthropic's overview says it "runs the Claude Code binary". So under the hood, your program starts Claude Code and talks to it.
Anthropic has four ways to build with Claude. The Claude Code CLI is the tool you use yourself in a terminal. The Client SDK talks to the Claude API directly, but then you write the tool loop yourself. Managed Agents run on Anthropic's own computers. The Agent SDK sits in between: you get Claude Code's ready-made agent, but it runs inside your own app, script or pipeline.
It used to be called the Claude Code SDK. Anthropic renamed it because it can build agents "beyond coding tasks".
How to install it
You need Node.js 18 or newer for TypeScript, or Python 3.10 or newer for Python. Then one command is enough:
npm install @anthropic-ai/claude-agent-sdk
pip install claude-agent-sdkWe installed version 0.3.296 for TypeScript and 0.2.165 for Python. Both bring their own copy of Claude Code, about 260 MB on Windows, so you do not have to install Claude Code separately.
To log in, the quickstart says to set an API key from the Claude Console as ANTHROPIC_API_KEY. An API key is a secret code for the paid connection between your program and Claude. You then pay per token: the small pieces of text an AI reads and writes. You can also go through Amazon Bedrock, Google Cloud or Microsoft Foundry. The SDK does not read .env files by itself, so load your key yourself.
Our agent in 30 lines
This is the whole agent we built. It reads the job from a file called TASK.md, lets Claude work on it, prints each tool Claude uses, and ends with the cost:
// A small coding agent with the Claude Agent SDK: it reads the job in TASK.md,
// changes the code, runs the tests with node, and reports what it cost.
// Run inside a project folder: npx tsx agent.ts
import { readFileSync } from "node:fs";
import { query } from "@anthropic-ai/claude-agent-sdk";
const job = readFileSync("TASK.md", "utf8");
for await (const message of query({
prompt: job,
options: {
model: "claude-sonnet-5-5",
effort: "medium",
settingSources: [], // do not load your own ~/.claude settings, skills or CLAUDE.md
permissionMode: "dontAsk", // never ask; refuse every tool that is not listed below
allowedTools: ["Read", "Edit", "Write", "Glob", "Grep", "Bash(node:*)"],
},
})) {
if (message.type === "assistant") {
for (const block of message.message.content) {
if (block.type === "tool_use") console.log(`tool: ${block.name}`);
}
}
if (message.type === "result") {
console.log(`done: ${message.subtype}, ${message.num_turns} turns, $${message.total_cost_usd.toFixed(3)}`);
}
}The important part is query(). You give it a prompt and options, and it sends back messages while Claude works: its thoughts, each tool it uses, and at the end a result with the cost. Three options matter most:
- allowedTools: which tools may run without asking. We allowed reading, editing, writing and running
node. - permissionMode: what happens with everything else.
dontAskrefuses it, so the agent can never run another program. We tested what the other modes do in our skip-permissions test. - settingSources: which of your own settings to load. More on that below.
We ran this agent in TypeScript and the same agent in Python on one of our jobs: splitting a bill. Both versions read the files, wrote the solution and tests, ran the tests and finished in 9 steps. Afterwards both passed all 17 secret checks. The Python run cost more ($0.16 against $0.09) because it used a slightly different version of Claude Code. Its cache, the short-term memory that makes repeated text cheap, was still empty.
How we tested
We used our secret test set: three small JavaScript jobs. Job D fixes a bug in a money reader. Job E splits a bill. Job F reads a CSV file. Each job came with a short note, and our secret checks only ran after the agent had finished. Our test page shows the jobs and how the checks work.
We ran each job three times through the TypeScript SDK with Sonnet 5.5, in three setups:
1. Default: no extra options. This is what you get if you copy the quickstart.
2. Isolated: settingSources: [] and an empty settings folder, so none of our own settings were loaded.
3. Isolated with the Claude Code prompt: like 2, plus the system prompt (the hidden instructions) that Claude Code itself uses. By default the SDK uses a much shorter one.
All three got the same tools and the same "medium" effort as our Claude Code runs. We compared them with Claude Code itself: the clean runs of our CLAUDE.md test on 10 October.
Did it work? Yes, every time
All four setups passed all 186 secret checks in all nine tries:
| Setup | Secret checks | Middle time | Cost per job |
|---|---|---|---|
| Claude Code CLI (clean) | 186 of 186 | 33 seconds | $0.135 |
| SDK, isolated | 186 of 186 | 32 seconds | $0.110 |
| SDK, isolated + Claude Code prompt | 186 of 186 | 30 seconds | $0.121 |
| SDK, default options | 186 of 186 | 38 seconds | $0.131 |
The isolated SDK agent was the cheapest: about 11 cents per job, against 14 cents for Claude Code itself. Part of that seems to be the shorter system prompt: with Claude Code's own prompt, the SDK agent cost $0.121. The rest may come from the newer Claude Code version inside the SDK. Speed was about the same everywhere: half a minute per job.
The cost is what the tokens would cost at Anthropic's list prices. The SDK reports this itself in total_cost_usd, and our own sum gave exactly the same number. For a bigger picture of prices, see our AI API price comparison.
Watch out: by default it loads your own setup
This was the biggest surprise. With the default options, the SDK loaded the personal Claude Code setup of the computer it ran on. That was the site owner's own CLAUDE.md file, 37 extra skills and one extra plugin. That is 7,700 extra tokens before the agent did anything, in every job.
| Setup | Size of the first call | Skills loaded |
|---|---|---|
| Isolated | about 32,500 tokens | 22 |
| Isolated + Claude Code prompt | about 34,700 tokens | 22 |
| Default options | about 40,200 tokens | 59 |
In our test this did not change the score, but each job cost about 18% more. The bigger risk is that your agent behaves differently on each computer, because it follows the personal rules of whoever runs it. The 22 skills in the isolated setup are the ones built into Claude Code itself.
How to keep your agent clean
Anthropic's docs say it plainly: when you leave out settingSources, the SDK "reads the same filesystem settings as the Claude Code CLI". That includes CLAUDE.md files and the skills in .claude/ folders. So add one line to your options:
settingSources: [],Two things are still read even then, the docs say: the global ~/.claude.json file and settings managed by a company. If you want to be fully sure, also point CLAUDE_CONFIG_DIR to an empty folder, as we did in our isolated setup. And if your agent needs project rules, load them on purpose with settingSources: ["project"] instead of everything.
Is the Claude Agent SDK free?
The SDK itself costs nothing. You pay for the AI model it uses: per token with an API key, or through Amazon, Google or Microsoft. In our test that was about 11 cents per small coding job with Sonnet 5.5. Bigger jobs read more text and cost more. Our Claude Code pricing article explains how those token costs add up.
"Free" does not mean open source. The Python code has an MIT licence. The TypeScript package says "All rights reserved" and points to Anthropic's terms, and its GitHub page lists no licence. The copy of Claude Code inside both falls under Anthropic's terms too.
If you build a product for other people, Anthropic says it must use an API key: you may not offer people a login with their claude.ai subscription, unless Anthropic agrees.
Questions people ask
What is the difference between Claude Code and the Claude Agent SDK?
Claude Code is the program you work with yourself, in a terminal or an app. The Agent SDK is a library that puts the same engine inside your own Python or TypeScript program. Under the hood it even runs the Claude Code program. In our test both passed all secret checks; the SDK agent cost a little less per job.
Why use the Claude Agent SDK?
Use it when you want an AI agent inside your own app, script or pipeline, with Claude Code’s tools for reading files, editing code and running commands already built in. You do not have to write the tool loop yourself. If you only want to code with AI yourself, Claude Code is simpler.
Is there a Python SDK for the Claude Agent SDK?
Yes. The Python package is called claude-agent-sdk and needs Python 3.10 or newer. We ran the same small agent in Python 3.14 and in TypeScript: both fixed the job and passed all 17 secret checks.
Is the Claude Agent SDK free?
The SDK itself costs nothing to install. You pay for the AI model it uses: per token with an API key, or through Amazon, Google or Microsoft. In our test one small coding job with Sonnet 5.5 cost about 11 cents at Anthropic’s list prices. It is not fully open source: the Python code is MIT, the rest falls under Anthropic’s terms.
How do I use the Claude Agent SDK?
Install it with npm install @anthropic-ai/claude-agent-sdk or pip install claude-agent-sdk, and set your API key as ANTHROPIC_API_KEY. Then call query() with a prompt and options, such as which tools the agent may use. Our 30-line example is in this article.
How we checked
We read Anthropic's Agent SDK pages on 11 October 2026: the overview, the quickstart, the TypeScript and Python references and the page about Claude Code features. We installed both SDKs in a separate test folder on our Windows 11 PC.
We ran the 27 SDK jobs on 11 October 2026 with Sonnet 5.5 and effort "medium". The SDK started its own Claude Code 2.1.296. For our test, the agent logged in with a token from the site owner's own Claude plan. We run all our Claude Code tests that way, so we did not pay per use. That is fine for your own tests, but for a product Anthropic wants an API key (see the screenshot). Costs are worked out from the token counts the SDK reported and Anthropic's list prices. The Claude Code comparison runs are from 10 October 2026, with Claude Code 2.1.280.
This was a small test: three short jobs, one model. The charts were made by us. The screenshots are real and cropped. None of the images was made by AI.

