The Agent SDK in Claude
The Claude Agent SDK lets developers build their own AI agents using the same engine that powers Claude Code. This guide explains in plain language what an agent is, what the SDK gives you, how permissions and safety work, and how to start wisely.
Imagine you want to hire a capable assistant to handle a task such as reviewing a folder of documents, fixing problems in a piece of software, or gathering information from several sources. You could give instructions one step at a time, waiting after each one. Or you could hire someone who can take the whole job, work out the steps, use the right tools, check their own work, and come back with a result. That second kind of worker is what people mean by an AI agent. The Claude Agent SDK is a toolkit that lets a developer create such a worker, built on the very same machinery that powers Claude Code. Instead of building all the plumbing yourself, you get a ready-made engine and decide what the worker is allowed to do.
1What Is the Claude Agent SDK?
It is a software toolkit for building AI agents that can read, act, and check their own work.
SDK stands for software development kit, which is a package of ready-made building blocks that programmers use to build something. The Claude Agent SDK gives developers the same agent loop, built-in tools, and context management that power Claude Code, available in the TypeScript and Python programming languages. According to Anthropic’s documentation, it was formerly called the Claude Code SDK, and the name changed because it is useful for far more than coding.
In simple terms, the SDK handles the hard, repetitive parts of running an agent. When Claude decides to read a file, run a command, or search the web, the SDK carries out that action and hands the result back to Claude, which then decides what to do next. This repeats until the task is complete. With the ordinary Claude API, a developer must write that loop by hand. With the Agent SDK, the loop is already built.
Think of building a car. You could forge every part yourself, or you could start from a tested engine and chassis, and focus on the body, the seats, and where the car should go. The Agent SDK is the tested engine: the part that has already been built, tested, and used in a real product, Claude Code.
flowchart LR
A["Your program gives Claude a task"] --> B["Claude decides what to do"]
B --> C["The SDK runs the tool: read, edit, search, or run"]
C --> D["The result goes back to Claude"]
D --> E{"Is the task done?"}
E -- "No" --> B
E -- "Yes" --> F["Your program receives the final result"]
Anthropic’s Agent SDK overview, quickstart, and reference pages in its documentation explain the current details. Package versions and options change often, so those pages are the best place to confirm exact information.
2Key Terms You Need First
A few simple words appear again and again in this topic. Here they are in plain English.
Agent
An AI that works toward a goal by taking several steps on its own, using tools and checking results, instead of answering just once.
Agent loop
The repeating cycle of thinking, acting with a tool, reading the result, and thinking again until the job is done.
SDK
A kit of ready-made building blocks that programmers use inside their own code.
Tool
An action the agent can take, such as reading a file, editing a file, searching the web, or running a command.
Permissions
The rules about which tools the agent may use, and when it must stop and ask for approval.
Hook
A checkpoint where your own code can look at, change, or block what the agent is about to do.
Subagent
A helper agent that the main agent can hand a smaller job, working with its own instructions and tool permissions.
MCP
The Model Context Protocol, an open standard for connecting AI agents to outside tools and services.
3What Is an Agent, Really?
An agent is an AI that does work, not just an AI that answers questions.
In an ordinary chat, you ask a question and get an answer. The AI does not leave the conversation. An agent is different. Given a goal, such as “find and fix the bugs in this file”, it can read the file, understand it, edit it, run the tests, notice that a test failed, and try again. It uses tools to affect the world outside the chat, and it uses the results of those tools to decide its next move.
This ability is powerful because many real jobs are not single questions. They are chains of steps where each step depends on what the previous one revealed. An agent can handle such chains without a human guiding every step. That same freedom is also why safety matters so much, a point we return to later.
| Feature | Ordinary chat or single request | Agent |
|---|---|---|
| Number of steps | One question, one answer | Many steps toward a goal |
| Uses tools? | Usually not | Yes, such as files, commands, and web search |
| Checks its own work? | Rarely | Can run tests or review results and retry |
| Human involvement | Every message | Set up, supervise, and review |
| Main risk | A wrong answer | A wrong answer plus a wrong action |
4How the SDK Relates to Claude Code and the API
Three related things share the same family, and it helps to tell them apart.
There are three ways a developer might use Claude, and each sits at a different level. The Messages API is the most basic: you send a request and receive a reply, and you write any loop or tool handling yourself. Claude Code is a finished product for software engineers, where Claude works in a terminal and other places. The Agent SDK sits between them: it offers the engine of Claude Code as a library you can program, so you can build your own agent products without starting from nothing.
| Option | What it is | Who it suits |
|---|---|---|
| Claude API (Messages) | Basic building block: send requests, get replies, and build everything else yourself | Developers who want full control and simple, single-step uses |
| Claude Code | A ready-to-use coding assistant that works in your projects | Engineers who want to use an agent, not build one |
| Claude Agent SDK | The Claude Code engine as a programmable library | Developers who want to build their own agents with files, commands, and tools |
flowchart TD
A["Claude models"] --> B["Messages API: you build the loop"]
A --> C["Agent SDK: loop, tools, permissions included"]
C --> D["Claude Code: a finished product on the same engine"]
C --> E["Your own custom agent"]
If your task is a simple single request, such as summarizing a paragraph, the Messages API is usually enough. The Agent SDK is meant for work that needs tools and many steps.
5What You Get Out of the Box
The SDK comes with the main parts of an agent already assembled.
The agent loop
The cycle of deciding, acting, and checking is handled for you. You give a task, and the SDK streams back messages as Claude works.
Built-in tools
Ready-made tools to read files, search for files and text, edit files, run commands, and search the web, so the agent can work without you writing that code.
Permissions
Controls for which tools are allowed, and how much human approval is required.
Hooks
Points where your own logic can inspect, log, change, or block actions.
Subagents
Helper agents with their own instructions, tool permissions, and working context.
MCP connections
A standard way to plug in outside tools and services, so the agent can reach your other systems.
Sessions and context management
Ways to continue, resume, or branch earlier work, and to manage the context window as the task grows.
Custom system prompts
The ability to give your agent a role and standing instructions that fit your product.
These features carry over from Claude Code, so lessons you learn about using Claude Code, such as keeping tasks focused and checking work, also help when you build an agent with the SDK.
6Getting Started: The Big Picture
A first agent can be small, and it is worth keeping it that way.
Anthropic’s quickstart guides a developer through a short, practical first agent: one that reviews a small file for bugs and fixes them. The steps are simple to describe even if you are not a programmer. You install the SDK for your language, make sure your access credentials are set up securely, write a short program that gives the agent a task and a list of allowed tools, and run it. As the agent works, the program receives a stream of messages that show what Claude is doing, ending with a final result.
Prepare a safe workspace
Create a new folder with a few practice files. By default the SDK can reach the files in the folder you run it from, so begin with something that does not matter.
Install the SDK
Install the package for your language, TypeScript or Python, following the quickstart for current instructions and requirements.
Set up access securely
Provide your credentials through secure settings, never by writing them into your code. You will need access through the Claude platform.
Write a small program
Give the agent a clear task, such as reviewing one file, and list the specific tools it may use.
Run it and watch the messages
See each step Claude takes, and read the final result.
Expand slowly
Add one capability at a time, such as web search or a custom instruction, and test each change.
The SDK needs access credentials, usually through the Claude platform, and usage is billed. Plan details, including how usage on subscriptions is counted, have changed over time, so check the current documentation and your account’s billing information before running large jobs.
7Tools: What the Agent Can Do
Tools are the agent’s hands. You decide which hands it gets.
Without tools, an agent can only talk. With tools, it can act. The quickstart shows that tools come in useful groups. Some tools only read, such as reading a file and searching for files or text. Others change things, such as editing a file. Others run commands on the machine, which is the most powerful and the most risky. Web search and web fetching let the agent look things up online.
The key lesson is to give the agent the smallest set of tools that lets it do its job. The documentation shows this clearly with example sets: read-only tools for analysis, read and edit tools for fixing code, and a broader set including command running for full automation.
| Tool set | What the agent can do | Risk level |
|---|---|---|
| Read and search only | Look at files and understand them, with no changes | Low |
| Read, search, and edit | Analyze and modify files | Medium, since it can change your work |
| Read, edit, and run commands | Full automation, including running tests and scripts | Higher, since commands can do many things |
| Adding web access | Look things up online | Adds exposure to untrusted web content |
When you let a contractor into your house, you decide which rooms they may enter and which tools they may use. A painter does not need the keys to your safe. An agent does not need a command-running tool to review a text file.
A good first agent only reads and reports. Once you trust how it behaves, add edit powers, and only then, if truly needed, command running.
8Permissions: Deciding How Much to Trust
Permissions set both which tools are allowed and how much human approval is needed.
The SDK offers two related controls. The first is the list of allowed tools, which decides which tools the agent may use at all. The second is the permission mode, which decides how much human oversight you want, from asking before actions, to automatically approving file edits, to approving everything. The quickstart shows a common middle setting in which file edits are approved automatically, while other actions still follow the usual rules.
Anthropic’s documentation also gives a precise caution about outside tools connected through MCP. These tools require explicit permission before Claude can use them. It advises preferring an explicit list of allowed tools over broad permission modes for this access, because the most permissive mode approves outside tools but also disables all other safety prompts, which is broader than necessary. In other words, give access to exactly the server you need, and nothing more.
Ask for approval
The agent pauses and asks before actions. Safest for learning and for sensitive work.
Auto-approve file edits
Convenient for trusted tasks inside a safe workspace, while other actions still follow the usual checks.
Custom rules and callbacks
Your own code decides case by case whether each tool use is allowed.
Bypass all checks
Removes safety prompts entirely. Appropriate only in a fully isolated, disposable environment.
flowchart TD
A["Agent wants to use a tool"] --> B{"Is the tool on the allowed list?"}
B -- "No" --> C["Blocked"]
B -- "Yes" --> D{"What does the permission mode say?"}
D -- "Ask" --> E["Pause for human approval"]
D -- "Auto-approve for this kind of action" --> F["Run the tool"]
D -- "Custom rule" --> G["Your code decides"]
Skipping approval prompts saves time, but it removes your chance to catch a mistake before it happens. Use the most permissive settings only in isolated, throwaway environments.
9Hooks: Your Checkpoints in the Loop
Hooks let your own rules step in at key moments.
A hook is a point in the agent’s life at which your code gets a say. For example, before the agent uses a tool, a hook can look at what it is about to do. If the action breaks a rule, such as touching a protected folder, the hook can block it. After a tool runs, another hook can record what happened for an audit trail. Hooks turn a general-purpose agent into one that obeys your organization’s specific rules.
Blocking dangerous actions
Before a command runs, check it against a list of things that must never happen, such as deleting important folders, and stop it if it matches.
Keeping an audit log
Record every tool use, with the time and the details, so that people can review what the agent did.
Adding checks before finishing
Run tests or validation before the agent is allowed to declare the task complete.
Modifying or approving actions
Approve safe actions automatically and send risky ones to a human.
Telling an agent in words to “never delete files” is useful, but a hook that actually blocks deletion is stronger. Where a mistake would be serious, back instructions with enforcement in code.
10Subagents: Dividing the Work
Big jobs go better when a main agent can hand pieces to helpers.
A subagent is a helper agent that the main agent can call on to do a focused piece of work. According to the documentation, each subagent has its own instructions, its own tool permissions, and its own working context. This has two benefits. First, the helper’s detailed reading and exploring happens off to the side, so the main agent’s context stays tidy and focused. Second, you can give each helper only the tools its small job requires, which keeps the power of each one narrow.
The main agent receives a large task
For example, “review this project for security and style problems”.
It hands parts to specialists
One subagent reviews security with read-only tools, another reviews style with read-only tools.
Each helper works in its own space
Their reading and notes do not fill up the main agent’s context window.
The main agent combines the findings
It receives short reports and writes a single clear summary.
Subagents can multiply cost and complexity. The documentation describes limits such as depth, concurrency, and spending caps for subagents, and notes that a helper only bypasses permission checks when its parent does. Check the current rules before relying on delegation.
11MCP: Connecting to Your Other Systems
MCP is a standard way to plug outside tools and services into an agent.
Real work often needs information or actions from systems beyond files and commands: a ticket tracker, a database, a document store, a chat tool. The Model Context Protocol, or MCP, is an open standard for connecting AI agents to such services. The Agent SDK supports it, so a developer can attach an MCP server and the agent gains access to the tools it offers.
One standard way to connect
Instead of writing a custom connection for every service, you can use servers that follow the shared standard.
Reach your real data
Agents can read from and act in the systems where your work actually lives.
Explicit permission required
The documentation notes that MCP tools need explicit permission, so an agent cannot use them silently.
Every connected tool widens what the agent can touch, and content coming back from outside systems may contain misleading text. Connect only servers you trust, and give the agent only the specific tools it needs from each.
12System Prompts and Sessions
Two more controls shape how your agent behaves over time.
Custom system prompts
The SDK lets you give your agent a custom system prompt, which is a standing set of instructions about its role and rules. This is how an agent becomes a code reviewer, a research helper, or a support triager. Clear, specific instructions, kept as short as the job allows, work best, and sensitive secrets should never be placed in them.
Sessions
A session is one continuous piece of agent work. The documentation describes ways to continue, resume, or branch sessions, so that work can pick up where it left off instead of starting again. This helps with long tasks and with returning to earlier work. It also means that sessions can hold sensitive material, so treat stored sessions with the same care as other records.
| Control | What it does | Good habit |
|---|---|---|
| System prompt | Sets the agent’s role, tone, and rules | Be specific and brief, and keep secrets out |
| New session | Starts clean with no memory of earlier work | Use for unrelated tasks |
| Resumed session | Continues earlier work with its history | Use for the same task over time |
| Branched session | Explores an alternative from an earlier point | Use to try two approaches safely |
13What Kinds of Agents Can You Build?
The SDK is general. Its best uses are jobs that involve many steps and real tools.
A code review helper
An agent that reads recent changes, checks them against your team’s rules, and writes a short report, using read-only tools.
A bug-fixing assistant
An agent that finds a crash, edits the code, runs tests, and reports what it changed, working in an isolated copy of the project.
A research and summary agent
An agent that searches the web, reads several pages, and writes a sourced summary on a topic.
A document organizer
An agent that reads a folder of files, sorts them, and produces an index, working only on a copy of the originals.
A support triage agent
An agent that reads incoming requests through a connected system, categorizes them, and drafts replies for a human to approve.
For anything that touches customers, money, or important data, let the agent prepare and propose, and let a person approve the final action.
14Safety Habits for Agent Builders
An agent that can act needs more care than a chatbot that can only talk.
Work in an isolated environment
Run agents in a disposable folder, container, or virtual machine, with only the files the task needs.
Give the minimum tools and access
Allow only what the task needs, and keep read-only wherever possible.
Guard your credentials
Store keys in secure settings, never in code or prompts, and do not give the agent access to secrets it does not need.
Treat outside content as untrusted
Web pages, files, and tool results can contain text written to mislead an AI. Do not let such text authorize actions on its own.
Enforce rules in code
Use permissions and hooks to block what must never happen, instead of relying only on instructions.
Set limits on cost and time
Cap how long and how much an agent may run, so a loop or a mistake cannot run up a large bill.
Log and review
Keep records of what the agent did, and review them, especially at the beginning.
Never point a new agent at the only copy of important files. Work on a copy or a version-controlled project, so any mistake can be undone.
15A Worked Example: A Safe Review Agent
Let us follow an imagined developer named Arun as he builds his first agent.
He chooses a small, safe job
Arun wants an agent that reviews a small project for crash bugs and writes a report. He copies the project into a practice folder and keeps the original safe.
He installs the SDK and sets credentials safely
He follows the quickstart for his language and stores his access key in secure settings, not in his code.
He gives read-only tools
His first version may only read and search files. The agent reads the code, finds two functions that can crash, and writes a clear report. Nothing is changed.
He checks the findings himself
He opens the code, confirms that both problems are real, and notes that the report’s explanation of one is slightly off.
He adds edit power, with approval
Now he allows editing, but keeps the mode that asks before changes. He reads each proposed change before approving it.
He adds a hook and a limit
He adds a hook that blocks edits outside the practice folder, and sets a cap on how long the agent may run.
He reviews and grows carefully
He reviews the logs, runs the tests himself, and only then considers giving the agent more freedom or a second task.
Arun began small, kept the agent read-only at first, checked its work, added power one step at a time, and enforced limits in code. That is the habit of a careful agent builder.
16Mistakes to Avoid
Most agent problems come from a few avoidable habits.
Problem
Giving the agent every tool and the most permissive mode from the start.
Why It’s Harmful
A single mistake or misleading instruction can lead to real damage, with no chance to stop it.
Correct Approach
Begin read-only with approvals on, and add power one step at a time.
Problem
Running an agent directly on your only copy of important files.
Why It’s Harmful
If the agent edits or deletes the wrong thing, there is no way back.
Correct Approach
Work on a copy or a version-controlled project in an isolated environment.
Problem
Using the SDK for a job that one simple request could handle.
Why It’s Harmful
You add cost, complexity, and risk for no benefit.
Correct Approach
Use the Messages API for simple single-step tasks, and the SDK where tools and many steps are truly needed.
Problem
Relying only on instructions such as “never delete anything” to protect important data.
Why It’s Harmful
Instructions can be misread or tricked, and they are not enforcement.
Correct Approach
Enforce rules with permissions and hooks, and keep important data out of reach.
Problem
Letting an agent run with no limits on time or cost.
Why It’s Harmful
A bug or loop can run for hours and produce a large bill.
Correct Approach
Set caps on duration and spending, and monitor early runs closely.
Problem
Trusting every report and change from the agent without review.
Why It’s Harmful
Agents can misread code, miss edge cases, or state things that are not true, and an unchecked error can spread.
Correct Approach
Review outputs, run tests yourself, and keep a human approving important actions.
17Advantages and Trade-offs
The SDK saves a great deal of work and adds responsibility.
Advantages
- You get a tested agent loop and built-in tools instead of building them
- The same engine that powers Claude Code, available in TypeScript and Python
- Permissions, hooks, subagents, and MCP are included
- Sessions let long tasks continue and be resumed
- Faster path from an idea to a working agent
Disadvantages / Trade-offs
- Agents can take real actions, so mistakes can have real effects
- Multi-step runs use more tokens, time, and money than single requests
- The loop is opinionated, so very custom designs may need more control
- Options, versions, and billing details change quickly
- Safe design needs care, testing, and ongoing review
18Best Practices at a Glance
A checklist to keep beside you when you start building.
Pick the right tool for the job
Use the Messages API for simple tasks and the SDK for tool-using, multi-step work.
Start small and read-only
Prove the agent’s behavior before giving it any power to change things.
Give the minimum tools
Allow only what the task needs, and be specific with outside tools.
Isolate the environment
Use copies, version control, and disposable workspaces.
Enforce rules in code
Use permissions and hooks for what must never happen.
Guard credentials
Keep keys in secure storage, and out of code, prompts, and logs.
Cap time and cost
Set limits and monitor early runs closely.
Review and keep humans in the loop
Check outputs, run tests yourself, and approve important actions manually.
19Frequently Asked Questions
Quick answers to the questions beginners ask most often.
A toolkit, available for TypeScript and Python, that gives developers the same agent loop, built-in tools, and context management that power Claude Code, so they can build their own AI agents.
It is the renamed version. Anthropic’s documentation says the Claude Code SDK is now the Claude Agent SDK, reflecting that it is useful for much more than coding.
With the Messages API you write the tool-handling loop yourself. With the Agent SDK, the loop, built-in tools, and permission system are already provided.
It can read and search files, edit them, run commands, and search the web, depending on the tools you allow, and it can connect to outside systems through MCP.
Through a list of allowed tools, a permission mode that sets how much approval is needed, and hooks that let your own code approve, change, or block actions.
A helper agent that the main agent can hand a focused job, with its own instructions, tool permissions, and context, so the main conversation stays tidy.
The Model Context Protocol, an open standard for connecting AI agents to outside services. The SDK supports it, and the documentation notes that MCP tools need explicit permission.
It can be, if you work on a copy or version-controlled project in an isolated environment, grant minimal tools, keep approvals on at first, and review the changes. Never use your only copy.
Start with a small, read-only agent in a practice folder. Check its work, then add one capability at a time, with limits and logging in place.
You need to be comfortable with programming in TypeScript or Python. The quickstart is designed to get a first agent running quickly, but careful design and testing still take skill.
Agent runs use tokens, and billing arrangements, including how usage relates to subscription plans, have changed over time. Check the current documentation and your account information before running large jobs.
In the Agent SDK overview, quickstart, permissions, hooks, subagents, and MCP pages of Anthropic’s documentation, and in the TypeScript and Python reference pages.
20Summary and Key Takeaways
The Claude Agent SDK is a toolkit for TypeScript and Python that packages the engine behind Claude Code, including the agent loop, built-in tools, permissions, hooks, subagents, MCP connections, sessions, and context management, so developers can build their own agents instead of writing everything from scratch. It sits between the basic Messages API and the finished Claude Code product. Because agents take real actions, the most important skills are safety skills: give the smallest set of tools, begin read-only, keep approvals on while learning, work on copies in isolated environments, guard credentials, treat outside content as untrusted, enforce rules in code with permissions and hooks, cap time and cost, and keep humans in the loop for important actions. Built this way, the SDK can turn a good idea into a useful, controlled agent.
Key Takeaways
- The SDK packages Claude Code’s engine — a TypeScript and Python toolkit with the agent loop, built-in tools, permissions, hooks, subagents, MCP, and sessions.
- It runs the loop for you — unlike the Messages API, where you write the tool-handling loop yourself.
- Choose it for multi-step work with tools — use the simpler API for single requests.
- Tools and permissions define the agent’s power — allow the minimum, start read-only, and use approval modes while you learn.
- Hooks and subagents add control and structure — hooks enforce your rules in code, and subagents divide work with narrow permissions.
- Isolate and protect — work on copies, guard credentials, treat outside content as untrusted, and cap time and cost.
- Keep humans in the loop — review outputs, run tests yourself, and approve important actions manually, and check current documentation because options change quickly.