Claude Code's engine, as a library
The Claude Agent SDK gives you the same agent loop, tools, context management and permission system that power Claude Code, as a library for Python and TypeScript. Use it when you want an agent inside your product or pipeline: a support triage bot, a code-migration service, an internal research assistant.
| Use… | When |
|---|---|
| Claude Code (interactive) | You're the one at the keyboard |
claude -p | A shell script or CI step is enough |
| Agent SDK | You need an agent embedded in your own application with full programmatic control |
Your first agent (Python)
pip install claude-agent-sdkimport asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
options = ClaudeAgentOptions(
allowed_tools=["Read", "Grep", "Glob"],
system_prompt="You are a meticulous code auditor. Report findings as a numbered list.",
max_turns=10,
)
async for message in query(prompt="Find any hardcoded secrets in this repo", options=options):
print(message)
asyncio.run(main())Your first agent (TypeScript)
npm install @anthropic-ai/claude-agent-sdkimport { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Summarize the open TODOs in src/ by priority",
options: { allowedTools: ["Read", "Grep", "Glob"], maxTurns: 10 },
})) {
if (message.type === "result") console.log(message.result);
}query() streams messages as the agent works: assistant text, tool calls, tool results and a final result, so your app can show progress live.
What you can configure
| Option | Controls |
|---|---|
| Allowed / disallowed tools | Exactly which tools the agent can use |
| Permission mode and callbacks | Approve or deny actions in your own code |
| System prompt | The agent's role and rules |
| MCP servers | External tools and data |
| Custom tools | Your own functions, exposed as tools |
| Subagents, skills, hooks | The same extension model as Claude Code |
| Sessions | Resume and fork conversations |
| Structured output | Responses that match a JSON schema |
Prototype the workflow interactively in Claude Code with a skill and a few hooks. Once it works reliably, port it to the SDK. The concepts (tools, permissions, skills and hooks) map across directly.
An SDK agent in production needs the same care as any service: least-privilege tools, sandboxed execution for untrusted input, cost tracking, logging and limits on turns and budget.
Check your understanding
What does the Agent SDK provide?
Which function runs an agent and streams its messages?
When is the SDK better than claude -p?
What's a smart path to building an SDK agent?