CLI ToolsApr 6, 2026·3 min read

Claude Agent SDK — Build Agents with Claude Code Power

Anthropic's official TypeScript SDK for building AI agents with Claude Code's full capabilities — file editing, command execution, codebase understanding, and complex workflows. npm package.

TL;DR
Anthropic's official TypeScript SDK that gives your applications Claude Code's agent capabilities programmatically.
§01

What it is

The Claude Agent SDK is Anthropic's official TypeScript SDK for building AI agents with Claude Code's full capabilities. It provides file editing, command execution, codebase understanding, and complex workflow orchestration through a clean programmatic API. Available as an npm package.

It is designed for developers who want to embed Claude Code's agent capabilities into their own applications, CI pipelines, or automation scripts rather than using the interactive CLI.

§02

How it saves time or tokens

The SDK handles tool management, conversation state, and error recovery automatically. Instead of building your own agent loop with raw API calls, you get Claude Code's battle-tested orchestration out of the box. The working directory parameter ensures the agent operates in the right context without manual path management.

§03

How to use

  1. Install: npm install @anthropic-ai/claude-agent-sdk
  2. Set your API key: export ANTHROPIC_API_KEY=sk-...
  3. Create a Claude instance and call claude.agent() with a prompt and working directory
§04

Example

import { Claude } from '@anthropic-ai/claude-agent-sdk';

const claude = new Claude({
  apiKey: process.env.ANTHROPIC_API_KEY
});

// Analyze a codebase
const result = await claude.agent({
  prompt: 'Analyze this codebase and create a summary of the architecture',
  workingDirectory: './my-project',
});

console.log(result.output);

// Fix a bug
const fix = await claude.agent({
  prompt: 'Find and fix the null pointer exception in the auth module',
  workingDirectory: './my-project',
});

console.log(fix.output);
§05

Related on TokRepo

§06

Common pitfalls

  • Requires Node.js 18+ and a valid Anthropic API key with sufficient quota
  • The agent has file system access in the working directory; ensure proper sandboxing in production environments
  • Long-running agent tasks can consume significant tokens; set budget limits for automated pipelines

Frequently Asked Questions

How is the SDK different from the Claude Code CLI?+

The CLI is an interactive tool for developers. The SDK is a programmatic interface for embedding Claude Code's agent capabilities into your own applications, scripts, or CI/CD pipelines without interactive prompts.

What tools does the agent have access to?+

The agent can read and write files, execute shell commands, search codebases with glob and grep, and use all the tools available in Claude Code CLI. The exact tool set depends on the permissions you configure.

Can I use the SDK in CI/CD pipelines?+

Yes. The SDK is designed for programmatic use. Set the API key as an environment variable, call claude.agent() with your prompt, and process the output. Common uses include automated code reviews, test generation, and documentation updates.

Is there a Python version of the SDK?+

The official SDK is TypeScript/JavaScript. For Python integration, you can use the Anthropic Python SDK with manual tool implementation, or call the Claude Code CLI from Python as a subprocess.

How much does it cost to use?+

The SDK uses your Anthropic API credits. Cost depends on the complexity of the task and the number of tokens consumed. Monitor usage through the Anthropic dashboard and set spending limits for automated workflows.

Citations (3)
🙏

Source & Thanks

Created by Anthropic. Governed by Anthropic Commercial Terms.

claude-agent-sdk-typescript — ⭐ 1,200+

Thank you to Anthropic for making Claude Code's capabilities available as a programmable SDK.

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets