BUILD · 5 MIN READ

Build with the Claude Agent SDK

Give Claude a scoped working directory and an explicit tool inventory.

Where it fits

The Claude Agent SDK exposes an agent loop with built-in capabilities for working with a local environment. This example reads a sample project and asks for a short summary. Tool configuration limits the available inventory to reading and searching.

Prepare the example

Install claude-agent-sdk, set ANTHROPIC_API_KEY, and create a sample-project directory containing a few non-sensitive text files. The SDK needs a supported platform installation. Save this file as review.py and run python review.py.

Shell · install in a virtual environment
pip install claude-agent-sdk
Python · 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())

Educational example. Uses your configured environment and credentials; no paid model call is made by this website.

Separate inventory from approval

tools selects the tool inventory. allowed_tools controls automatic approval for those tools. These settings serve different purposes. A dedicated runtime or container supplies the isolation boundary for a real deployment.

Inspect the outcome

Consume the message stream and check the result subtype. A turn limit can stop the run before the task is complete. Treat missing files and incomplete summaries as separate outcomes rather than assuming every final message means success.

Keep exploring

A browser or coding agent in a sandboxDesign tools an agent can use well