Skip to content

// Engineering - November 12, 2026

Claude Agent SDK: build an agent that works your board.

The Claude Agent SDK is Anthropic's Python and TypeScript library that runs Claude Code's agent loop, tools, permissions, hooks and MCP support inside your program. You call query() with a prompt and options, and it streams messages until the work is done. Connect it to a task board's MCP server and the agent can take its own cards.

What is the Claude Agent SDK?

It is Claude Code, packaged as a library. Anthropic's Agent SDK overview sums it up as "Build production AI agents with Claude Code as a library" and says the SDK gives you "the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript". Beyond the built-in tools, it supports hooks, subagents, MCP servers, permissions, sessions, and the skills and CLAUDE.md files Claude Code already reads. In our guide to agent harnesses, that makes it a harness: the loop, tools and checks around the model.

Five facts to know before you start (as of November 12, 2026):

  • It used to be the Claude Code SDK. The migration guide says the change "reflects the SDK's broader capabilities for building AI agents beyond coding tasks". The npm package went from @anthropic-ai/claude-code to @anthropic-ai/claude-agent-sdk (version 0.1.0 on npm was published September 29, 2025), and the Python package from claude-code-sdk to claude-agent-sdk.
  • Current versions: TypeScript 0.3.322 (published November 10, 2026) and Python 0.2.180 (November 9, 2026, on PyPI). The quickstart asks for Node.js 18.14+ or Python 3.10+.
  • It runs the real Claude Code binary. Both SDKs bundle a native Claude Code binary, so most installs need nothing else.
  • It needs API credentials. Set ANTHROPIC_API_KEY, or use Bedrock, Claude Platform on AWS, Google Cloud or Microsoft Foundry credentials. A claude.ai login is not the intended route (see the FAQ).
  • Two defaults matter. Since version 0.1.0 the SDK uses a minimal system prompt unless you ask for the claude_code preset. And if you leave out settingSources, it loads user, project and local settings, the same as the CLI.

How is it different from Claude Code, the Client SDK and Managed Agents?

The difference is who runs the agent and what comes built in. This table condenses the comparison in Anthropic's overview:

Option Who runs the loop Good fit
Claude Code CLIYou, in a terminalInteractive work and one-off tasks
Claude Agent SDKYour program, in a process you operate, with Claude Code's tools and permissionsAgents built into your own app, script or CI job
Client SDK (Messages API)Your code: you write the tool loop, or use the beta tool runnerFull control over every model call
Managed AgentsAnthropic, in a hosted or self-hosted sandboxLong-running work without running infrastructure

If you would rather not host the loop at all, our Claude Managed Agents guide sets up the hosted version against the same board.

How does query() work?

You pass a prompt and an options object, then read the messages as they stream. Install the TypeScript SDK the way the quickstart does:

mkdir flux-worker && cd flux-worker
npm init -y && npm pkg set type=module
npm install @anthropic-ai/claude-agent-sdk
npm install --save-dev tsx

A minimal agent fits in a few lines. allowedTools pre-approves the tools you list, and acceptEdits lets file edits through without asking:

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

for await (const message of query({
  prompt: "Find and fix the failing test in src/date.test.ts",
  options: { allowedTools: ["Read", "Edit", "Glob", "Grep"], permissionMode: "acceptEdits" },
})) {
  if (message.type === "result") console.log(message.subtype, message.total_cost_usd);
}

Each message has a type. A system message with subtype init comes first and lists the tools and the status of each MCP server. assistant messages carry Claude's text and tool calls. The run ends with one result message, which carries the session ID, the turn count and an estimated cost. Its subtype is success or an error such as error_max_turns or error_max_budget_usd. A single-shot query() throws after it yields an error result, so wrap the loop in try.

Why give an SDK agent a task board?

Because the SDK keeps state on one machine, and your team needs a shared record. Sessions are saved on the machine that ran them, and you resume one by passing its ID. The SDK's built-in todo list (the Task tools, or TodoWrite) lives inside one session. The todo docs say those tools are on by default only for Claude Opus 4.7, Sonnet 4.6, Haiku 4.5 and earlier models, and that newer models track multi-step work without a written list.

None of that shows a teammate what is queued, which agent took which task, or what is waiting for review. A shared board does. In Flux, each task is a card: the description is the brief, comments are the progress log, and a person takes over in a Needs review column. Our kanban board for AI agents guide shows the layout; this worker calls its first column Ready.

How do you connect the Agent SDK to the Flux MCP server?

Add Flux under mcpServers with its URL and a Bearer header, then allow the tools you want. The Flux MCP server is a remote server that speaks streamable HTTP and reads a Flux API key, which is the type: "http" case in Anthropic's SDK MCP docs:

mcpServers: {
  flux: {
    type: "http",
    url: "https://flux.umin.ai/api/mcp",
    headers: { Authorization: `Bearer ${process.env.FLUX_API_KEY}` },
  },
},
allowedTools: ["mcp__flux__get_board", "mcp__flux__get_card"],

Three rules from those docs trip people up:

  • Tools are named mcp__flux__<tool>, after the key you give the server.
  • MCP tools need explicit permission. Without an allow rule, Claude sees the tools but can't call them. acceptEdits does not approve MCP tools, and bypassPermissions approves far more than you need.
  • A failed connection does not throw. Check the server's status in the init message. failed or needs-auth means no Flux tools, and Claude may carry on with other tools. pending is not a failure on its own; it can mean the server is still connecting.

To make a key, open Settings in Flux, then the API Keys tab, and click Create key. Read is always on; turn on Write so the agent can comment and move cards. The board ID is the short ID in the board's URL. To find the column IDs, read the board once over REST:

curl -s https://flux.umin.ai/api/boards/k3J9xQ2a \
  -H "Authorization: Bearer $FLUX_API_KEY"

A complete worker: take the top card, hand it to review

This script takes the first card in Ready, moves it to In Progress, does the work, comments, and moves it to Needs review. Save it as flux-worker.ts in the repository the cards are about, since the session runs in the current directory. It type-checks against version 0.3.322 of the SDK.

// flux-worker.ts: take the top card in Ready, do it, hand it to review.
import { query, type HookCallback, type PreToolUseHookInput } from "@anthropic-ai/claude-agent-sdk";

function env(name: string): string {
  const value = process.env[name];
  if (!value) throw new Error(`Set ${name}`);
  return value;
}
const FLUX_KEY = env("FLUX_API_KEY"); // flux_... key with Read and Write
const BOARD = env("FLUX_BOARD"); // the short ID in the board's URL
const IN_PROGRESS = env("FLUX_IN_PROGRESS_COLUMN"); // column UUIDs, from get_board
const REVIEW = env("FLUX_REVIEW_COLUMN");

const rules = `You work one card on a Flux board through the flux MCP tools.
1. Call get_board with board ${BOARD}. Take the first card in the Ready
   column. If Ready is empty, stop and report status "no_work".
2. move_card it to column ${IN_PROGRESS}, then call get_card with its id
   (a UUID). The description is your brief.
3. add_comment: "[sdk-worker] Started."
4. Do the work in this repository and run the checks the brief names.
5. add_comment with what you changed and how you checked it, then
   move_card to column ${REVIEW} and report status "needs_review".
If the brief is unclear, add_comment with your question, leave the card
where it is and report status "question". Never move a card anywhere else.`;

// Client-side guard: move_card may only target In Progress or Needs review,
// and only for the first card the agent took (a UUID).
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
let cardId: string | undefined;
const guardMoves: HookCallback = async (input) => {
  const { card_id: id, target_column_id: target } = (input as PreToolUseHookInput)
    .tool_input as { card_id?: string; target_column_id?: string };
  const okTarget = target === IN_PROGRESS || target === REVIEW;
  const okCard = !!id && UUID.test(id) && (cardId === undefined || id === cardId);
  if (okTarget && okCard) {
    cardId = id;
    return {};
  }
  return {
    hookSpecificOutput: {
      hookEventName: "PreToolUse",
      permissionDecision: "deny",
      permissionDecisionReason: "Only the card you took, to In Progress or Needs review.",
    },
  };
};

// Run receipt over REST: the script writes it, not the model.
async function receipt(text: string): Promise<void> {
  if (!cardId) return;
  const res = await fetch(`https://flux.umin.ai/api/cards/${cardId}/comments`, {
    method: "POST",
    headers: { Authorization: `Bearer ${FLUX_KEY}`, "Content-Type": "application/json" },
    body: JSON.stringify({ content: text }),
  });
  if (!res.ok) console.error(`Receipt failed: HTTP ${res.status}`);
}

const outcome = {
  type: "object",
  properties: {
    status: { type: "string", enum: ["needs_review", "question", "no_work"] },
    summary: { type: "string" },
  },
  required: ["status", "summary"],
};

try {
  for await (const message of query({
    prompt: "Work the next card.",
    options: {
      systemPrompt: { type: "preset", preset: "claude_code", append: rules },
      settingSources: ["project"], // this repo's CLAUDE.md and .claude/ only
      mcpServers: {
        flux: {
          type: "http",
          url: "https://flux.umin.ai/api/mcp",
          headers: { Authorization: `Bearer ${FLUX_KEY}` },
        },
      },
      allowedTools: [
        "Read", "Edit", "Glob", "Grep", "Bash(npm test *)",
        "mcp__flux__get_board", "mcp__flux__get_card",
        "mcp__flux__add_comment", "mcp__flux__move_card",
      ],
      disallowedTools: [
        "mcp__flux__create_card", "mcp__flux__update_card",
        "mcp__flux__create_column", "mcp__flux__reorder_cards",
      ],
      permissionMode: "dontAsk",
      hooks: { PreToolUse: [{ matcher: "mcp__flux__move_card", hooks: [guardMoves] }] },
      outputFormat: { type: "json_schema", schema: outcome },
      maxTurns: 60,
      maxBudgetUsd: 3,
    },
  })) {
    if (message.type === "system" && message.subtype === "init") {
      const flux = message.mcp_servers.find((s) => s.name === "flux");
      console.log(`flux MCP server: ${flux?.status ?? "missing"}`);
    }
    if (message.type === "result") {
      const out = message.subtype === "success"
        ? (message.structured_output as { status: string; summary: string } | undefined)
        : undefined;
      const status = out?.status ?? message.subtype;
      console.log(status, out?.summary ?? "");
      await receipt(
        `[sdk-worker] Run ${message.session_id}: ${status}, ` +
        `${message.num_turns} turns, about $${message.total_cost_usd.toFixed(2)}.`,
      );
    }
  }
} catch (error) {
  console.error(`Run ended with an error: ${error}`);
  process.exitCode = 1;
}

Run it with five variables set:

export ANTHROPIC_API_KEY=sk-ant-...      # from the Claude Console
export FLUX_API_KEY=flux_...             # Read and Write
export FLUX_BOARD=k3J9xQ2a               # from the URL /board/k3J9xQ2a
export FLUX_IN_PROGRESS_COLUMN=<column UUID>
export FLUX_REVIEW_COLUMN=<column UUID>
npx tsx flux-worker.ts

What each option does in this worker:

Option Why it is there
systemPrompt preset + appendKeeps Claude Code's own system prompt and adds the board rules to it.
settingSources: ["project"]Loads the repository's CLAUDE.md, .claude/settings.json and project skills, but not your user settings in ~/.claude.
allowedToolsApproves file tools, npm test, and four Flux tools.
disallowedToolsRemoves the four Flux write tools the worker never needs. That includes create_card and reorder_cards, the other two tools that can put a card in a column.
permissionMode: "dontAsk"Nobody is watching, so any call that would prompt is denied instead.
hooks.PreToolUseLets move_card target only In Progress or Needs review, and only for the card it took (the first card UUID it moves). Anthropic's docs say a hook deny applies even in bypassPermissions mode.
outputFormatMakes the last answer a JSON object with status and summary, checked against the schema.
maxTurns, maxBudgetUsdStop a run that goes on too long. The budget can overshoot by one response.

The last step is the run receipt. The script, not the model, posts it to the card over the Flux REST API. Flux records REST comments in the board's activity log, but does not record MCP changes there today. So the receipt (session ID, outcome, turns, estimated cost) is the one entry from the run in the activity log, next to the agent's own comments on the card. Once the agent has moved a card, the receipt posts even if the run stops at a limit, because the hook saved the card ID.

What happened when we ran it?

We ran the script on November 12, 2026, with SDK 0.3.322 and its bundled Claude Code binary, against two local stand-ins: a scripted model API and a mock of the Flux MCP and comment endpoints. No real model or Flux board was involved, so this shows the wiring, not how well Claude does the work. The scripted model tried each call below in order:

Call Result
Connect to the Flux mockinit reported connected. Every request carried the Bearer header.
get_boardRan without a prompt.
move_card to DoneBlocked by the hook before any request left: "PreToolUse:mcp__flux__move_card hook error: Only the card you took, to In Progress or Needs review." (the SDK's wording for a hook deny)
move_card with the humanId PROJ-42 instead of the UUIDBlocked by the hook the same way.
move_card to In Progress, get_card, add_commentRan without prompts.
list_cards (not allowed)Denied: "Permission to use mcp__flux__list_cards has been denied because Claude Code is running in don't ask mode."
update_card (disallowed)The tool was never offered to the model; when the scripted model called it anyway, the SDK returned "No such tool available".
move_card of a second card to Needs reviewBlocked by the hook: the worker is locked to the card it took.
move_card to Needs review, then the structured answerResult needs_review, then the receipt went to the taken card's comments endpoint: "[sdk-worker] Run <session ID>: needs_review, 12 turns, about $0.01." (the cost comes from the stand-in's fake token counts)

One more thing we saw: the requests to the model did not carry the Flux tool definitions up front. Tool search is on by default, so MCP tool definitions load only when Claude needs them. A 12-tool server then takes no context it doesn't use.

What should you know before you rely on it?

  • The guards live in your script. The Flux key still has Write. The same key used in curl or another client can move any card to any column on the board, because Flux checks only the Write scope and the key owner's member role. "A person moves cards to Done" is a team rule, backed here by the hook. For the same guard in an interactive Claude Code session, see our Claude Code hooks guide.
  • MCP changes skip the Flux activity log. The agent's comments and moves over MCP are not written to the activity log and can't be undone there. The signed comments and the REST receipt are the record.
  • Sign every comment. Comments made with a Flux key show under the name of the account that made the key, so the [sdk-worker] prefix tells people which agent wrote what.
  • There is no claim lock. Two workers reading the same Ready column can take the same card. Moving it to In Progress first narrows the gap but does not close it. Give each worker its own column or board.
  • Card text is part of the prompt. get_card returns the description and every comment, so anyone who can comment on the card can steer the agent. Keep the tool list short. In dontAsk mode, tools such as WebSearch are denied unless you allow them, and WebFetch is denied except for Claude Code's built-in preapproved documentation domains. File reads inside the working directory and read-only Bash commands still run without an allow rule. Edit plus npm test lets the agent run any code it writes (it can change the test files or the scripts in package.json), so run the worker in a container or CI job that holds only these two keys, or turn on the SDK's sandbox option. If you use the sandbox, set autoAllowBashIfSandboxed: false and allowUnsandboxedCommands: false, because both default to true and would widen what the agent may run; on Linux it needs bubblewrap and socat.
  • Pass card UUIDs. get_board lists each card's id (a UUID) and its humanId such as PROJ-42. Give get_card, move_card and add_comment the UUID; a PROJ-42 ID doesn't work reliably in get_card today.

To run the worker on a schedule, start it from cron or a CI job. Each run is a fresh session that takes one card. The board shows everyone what happened.

// FAQ
06 questions
01

What is the Claude Agent SDK?

+

The Claude Agent SDK is Anthropic's library for running Claude Code's agent inside your own program, in Python (claude-agent-sdk) or TypeScript (@anthropic-ai/claude-agent-sdk). It brings Claude Code's tools, agent loop, context management, hooks, MCP support and permissions. You call query() with a prompt and options, and the agent plans its steps and calls tools until it finishes.

02

Is the Claude Agent SDK the same as the Claude Code SDK?

+

Yes. Anthropic renamed the Claude Code SDK to the Claude Agent SDK. The npm package moved from @anthropic-ai/claude-code to @anthropic-ai/claude-agent-sdk (version 0.1.0 was published on September 29, 2025), and the Python package from claude-code-sdk to claude-agent-sdk.

03

Can the Claude Agent SDK connect to remote MCP servers?

+

Yes. Add the server under mcpServers with type "http" (streamable HTTP) or "sse", its URL and any headers, such as a Bearer API key. Its tools are named mcp__<server>__<tool>, and the agent can call them only after you allow them, for example in allowedTools. The SDK runs no interactive OAuth flow, so pass a token in the headers.

04

Can I use my Claude subscription login with the Agent SDK?

+

Anthropic's docs say to use API key authentication. Unless previously approved, Anthropic does not allow third-party developers to offer claude.ai login or rate limits in products built on the SDK. Amazon Bedrock, Claude Platform on AWS, Google Cloud and Microsoft Foundry credentials also work.

05

How much does the Claude Agent SDK cost to run?

+

You pay for the model tokens on the API key or cloud account you use. Each result reports total_cost_usd, which Anthropic calls a client-side estimate, not billing data. Cap a run with maxBudgetUsd and leave headroom, because the response that reaches the cap still completes.

06

Does Flux run my Agent SDK agents?

+

No. Flux is the task board, not the agent host. Your SDK script runs wherever you run it and reaches your Flux board through the Flux MCP server with a Flux API key. MCP works on every Flux plan, including Free, and agents that connect with a key never take a paid seat.

// One board, every agent

Your script runs the agent. Your board keeps the work.

Connect Agent SDK workers, Claude Code and Managed Agents to one Flux board over MCP. Each agent takes a card, and a person reviews it in Needs review. Free to start, and agents that connect with an API key never take a seat.