TOOL WIKI · AGENT SDKS
Claude Agent SDK
Exposes Claude’s agent loop and built-in tools for working in an application environment.
Jump to a section 10 sections
EXAMPLE USE CASE
Summarize a project using file evidence
A developer needs a small, observable agent or retrieval step before connecting real business services.
- Input
- A sample-project directory with README.txt and read/search tools.
- Expected output
- A purpose summary naming the files used and the terminal outcome.
- Success check: The result names README.txt and describes the fixture.
- Try a failure: Remove README.txt and check that the agent reports missing evidence.
Example scope: Actual file-reading agent; the example exposes no write or shell tool.
Official reference · Claude Agent SDK
Authenticate the request and define the goal before calling the framework.
Tasks that benefit from a working directory and file or code tools. Configure the available tool inventory separately from tool approval.
invokeTo 03 · Model providertool callTo 04 · Tool servicemeasureTo 06 · EvaluationThe application supplies provider credentials, model selection, and budgets.
decisionBack to 02 · Claude Agent SDKValidate each operation and return authoritative observations.
Choose the checkpoint or session store and its retention policy deliberately.
Result or stopping pointCheck completion, cost, latency, and tool behavior against fixtures.
Result or stopping point
Tasks that benefit from a working directory and file or code tools. Configure the available tool inventory separately from tool approval.
When to consider it
- Tasks that benefit from a working directory and file or code tools.
A design decision to make
- Configure the available tool inventory separately from tool approval.
Prerequisites and setup
- Python 3.11+ in an empty directory. A compatible model and provider credentials are required.
- Running the model-backed example can incur API charges; this website displays it without calling a provider.
- Save the code at the displayed path, then use the corresponding run command.
python3 -m venv .venv
source .venv/bin/activate
python -m pip install claude-agent-sdk
export ANTHROPIC_API_KEY="your-api-key"
mkdir -p sample-project
printf "A tiny order-status service.\n" > sample-project/README.txtTry a small integration
review.py
import asyncio
from claude_agent_sdk import (
query, ClaudeAgentOptions, ResultMessage
)
async def main():
options = ClaudeAgentOptions(
cwd="./sample-project",
tools=["Read", "Glob", "Grep"],
allowed_tools=["Read", "Glob", "Grep"],
max_turns=5,
)
async for message in query(
prompt=(
"Read the text files in this project. "
"Summarize its purpose and name the files you used."
),
options=options,
):
if isinstance(message, ResultMessage):
print("Outcome:", message.subtype)
print(message.result or "No final text returned.")
if __name__ == "__main__":
asyncio.run(main())Run and check the result
python review.py- The result names README.txt and describes the fixture.
- The available tools are Read, Glob, and Grep; the sample supplies no write or shell tool.
Common failures
- A missing working directory fails before useful file analysis; create sample-project first.
- Inspect ResultMessage.subtype as well as result text. A turn limit or tool failure is not a successful review.
Production decisions
- Replace the local fixture with a service that enforces authenticated tenant and resource permissions.
- Add timeouts, bounded retries, tracing redaction, and a regression case for each observed failure.
- Model calls consume provider API usage when you run this example; this website only displays the code.
Keep exploring
Explore the same layer
Compare candidates on your own workload. This entry describes a product’s role; it is not a claim that products in the category are interchangeable.