
Anthropic
Claude Code as a library — production agents with built-in file, shell, and code-edit tools.
GitHub Stars
7.0K
Contributors
65
npm / Week
5.9M
PyPI / Month
13.0M
The Claude Agent SDK is Anthropic’s official agent framework, released in 2025 under the MIT license. It is a polyglot SDK with first-class Python and TypeScript packages that expose the same agent loop, built-in tools, and context management that power Claude Code — arguably the most production-proven coding agent in the market. The SDK lands in the intersection of Agent Runtime, Inference SDK, and Orchestration categories, and it competes most directly with frameworks like LangChain, CrewAI, and Mastra for teams building agents that require file system access, shell execution, and code editing as core primitives.
The SDK’s design philosophy is pragmatic: rather than providing abstract primitives for tool calling and hoping you wire them up correctly, it ships Claude Code’s actual production internals as a library. This isn’t a framework built from scratch — it’s the harness that already runs hundreds of thousands of developer sessions daily, packaged so you can embed it into your own applications. The Python package has over 5,000 stars on GitHub, the TypeScript package is approaching 1,000 stars, and both are actively maintained by Anthropic’s Claude Code team.
Building with the Claude Agent SDK means working with a single, imperative agent loop. You create an agent session, provide a prompt (or a stream of messages), and the SDK handles context management, tool selection, execution, and response generation automatically. There are no graph definitions, no chain nodes, no declarative pipelines. Control flow is handled internally by Claude’s reasoning — the model decides which tool to invoke and in what order, and the SDK executes those decisions against your environment.
The core abstraction is the query() function (Python) or the equivalent Agent class (TypeScript). You pass a prompt and optional configuration (ClaudeAgentOptions), and you receive an async iterator of AssistantMessage objects containing text, tool calls, and structured output blocks. The agent loop is event-driven: the SDK processes each model turn, runs requested tools, appends results back to the context, and continues until the task is complete or a turn limit is reached.
The programming model is code-first. You configure permissions, hooks, and system prompts programmatically. You extend the agent by adding custom tools via function decorators or by connecting external tool servers through the Model Context Protocol (MCP). Sessions can be persisted to external storage (Redis, Postgres, filesystem) and resumed, which allows long-running or stateful agents.
Built-in tools that are production-grade. The SDK ships nine tools out of the box: Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch, and Monitor. These are the same tools that Claude Code uses to navigate and modify codebases. You do not need to implement or configure tool execution — the SDK handles calling the shell, reading files, applying edits, and searching the web. For teams building agents that interact with code, this removes an enormous amount of integration work.
Hooks and subagents. The SDK provides a hook system with PreToolUse, PostToolUse, and Stop callbacks that let you intercept and modify agent behavior at each lifecycle stage. You can log tool calls, enforce approval gates, inject context before a tool runs, or terminate the agent based on custom criteria. Subagents allow you to delegate specialized subtasks to child agent instances. A parent agent can spawn a subagent to handle a focused research query, a code review, or a file refactor, and then incorporate the result.
MCP and skills support. The SDK natively connects to any tool server that implements the Model Context Protocol. You can wire in access to databases, APIs, or internal services without writing custom tool code. It also loads Claude Code skills and slash commands from .claude/ directories — meaning teams can reuse existing Claude Code configurations and community-written skills directly in their own agent applications.
Streaming, type safety, and resumable sessions. Responses stream in real time with visibility into tool calls and intermediate text output. Both SDKs are fully typed (TypeScript natively, Python with py.typed stubs). Sessions can be serialized and resumed, which is essential for long-running research agents or multi-turn workflows that survive process restarts.
Confirmed capabilities match what you need for production: multi-agent (via subagents), streaming, tool use, human-in-the-loop approval hooks, persistent memory (via sessions and CLAUDE.md), type-safe APIs, self-hosted or cloud-hosted (Anthropic, Bedrock, Vertex, Foundry).
Coding agents in CI/CD pipelines. Teams deploy the SDK in automated CI/CD workflows to run code reviews, apply lint fixes, or execute refactors as part of pull requests. The agent reads the diff with Read, runs linters with Bash, applies changes with Write or Edit, and commits them — all within a GitHub Action or similar runner.
Codebase research and large-scale refactors. A long-running agent can traverse a repository using Glob and Grep to understand code structure, then propose or apply targeted edits. Because sessions are resumable, you can let a research agent explore for hours, then review and approve changes before applying them.
Local prototyping for Managed Agents. Developers build and iterate agent behavior locally with the SDK, using the same tool set and context management that will run in production. Once the agent logic is stable, it moves to Anthropic’s Managed Agents for hosted execution at scale, with no code changes required.
The SDK is a strong fit for any workload that involves reading, writing, editing, or searching files while executing commands. It is a weaker fit for non-coding workflows that require complex multi-agent orchestration with state graphs or DAGs — frameworks like LangGraph or CrewAI offer more structure for those patterns.
Install the Python package:
1pip install claude-agent-sdk
The package bundles the Claude Code CLI automatically. No separate installation is required for the agent runtime.
The simplest meaningful example, a streaming agent that answers a question:
1import anyio2from claude_agent_sdk import query34async def main():5 async for message in query(prompt="What is the current time?"):6 print(message)78anyio.run(main)
That’s fewer than 10 lines to get a fully functional agent with file, shell, and web tools. To go further, you configure permissions, add custom tools, or connect MCP servers.
What you need around it: An Anthropic API key (or access through Bedrock, Vertex, or Foundry). For many production deployments, you will also want OpenTelemetry tracing (the SDK supports it natively), a session store (Redis, Postgres), and a guard system for approval workflows. The SDK does not include its own evaluation harness or observability dashboard — bring your own.
Documentation: Start at the official docs at code.claude.com/docs/en/agent-sdk/overview. The GitHub repositories for Python and TypeScript contain examples, the full API reference, and migration guides.
Claude Agent SDK vs. LangChain. LangChain is more flexible — it supports dozens of models, providers, and memory backends, and its LangGraph extension adds graph-based orchestration. Choose the Claude Agent SDK when you want the simplest possible path to a production agent that uses Anthropic models and needs code manipulation. LangChain makes sense if you need multi-model switching, complex retrieval pipelines, or structured graph workflows.
Claude Agent SDK vs. CrewAI. CrewAI focuses on role-based multi-agent teams with hierarchical task delegation and sequential processes. It abstracts away the tool loop and lets you define agent roles, tasks, and tools declaratively. The Claude Agent SDK gives you more control over the agent loop itself, and its built-in tools are specifically designed for code. Choose CrewAI if you are building a multi-agent workflow with clearly separated roles (researcher, writer, reviewer) that do not require deep file system integration. Choose the Claude Agent SDK if your agents need to read, write, and execute code as a primary action.
What the SDK does well: Production-grade file and shell tools, seamless transition to Managed Agents, tight integration with Claude’s reasoning loop, and a minimal API surface.
What you own: Observability, evaluation, and multi-agent orchestration for non-linear workflows. The SDK is opinionated about the agent loop and opinions that lean heavily into code execution — if your agent never touches a file or runs a command, you may be paying for overhead you do not need.
What the framework gives you out of the box, in plain language.
Read, Write, Edit, Bash, Glob, Grep, WebSearch, WebFetch, and Monitor are ready to use — no tool plumbing needed.
Intercept the agent lifecycle with PreToolUse/PostToolUse hooks and delegate to specialised subagents.
Connect external systems via Model Context Protocol, and load Claude Code skills and slash commands from .claude/.
The jobs this framework is best suited for.
Agents that read files, run commands, and edit code as part of automated pipelines and bots.
Long-running agents that explore a repo with Glob and Grep, then propose or apply targeted edits.
Build and iterate locally with the SDK, then move to Anthropic Managed Agents for hosted production runs.

Side-by-Side
Add a second or third framework and see stars, downloads, and capabilities lined up next to each other.
Close alternatives worth a look before you decide.
Composable building blocks for LLM apps — chains, agents, retrievers, and integrations.
Composable LLM building blocks
Stars
137.3K
npm / wk
2.3M
PyPI / mo
247.9M
Multi-agent crews with role-based prompts and explicit task hand-offs.
Role-based multi-agent crews
Stars
51.6K
npm / wk
—
PyPI / mo
9.6M