Skip to content
Academy ofAI Learning

Claude Agent SDK basics

What the Claude Agent SDK is, how to build a minimal agent in Python or TypeScript, and how its tools and permission modes control what the agent may do. 9 min

Step 1 of 6

Read

What the Agent SDK is

The Claude Agent SDK is Claude Code as a library. It gives your Python or TypeScript program the same agent loop and built-in tools (read, write and edit files, run commands, search the web), plus permissions, hooks, subagents, sessions and MCP. You give it a goal; it plans, calls tools, checks the results and stops when the job is done.

Compare it with the Client SDK, where you call the Claude API directly and write the tool loop yourself, and with Managed Agents, where Anthropic hosts the loop for you.

Authenticate with an API key from the Claude Console, or through Amazon Bedrock, Google Cloud or Microsoft Foundry. Anthropic does not allow third-party products built on the SDK to offer claude.ai login or rate limits unless previously approved (checked 18 November 2026).

Lesson notes: Claude Agent SDK basics

Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You have run a minimal agent and can set its tools and permissions on purpose.

  1. Step 1 of 6 · Read

    What the Agent SDK is

    The Claude Agent SDK is Claude Code as a library. It gives your Python or TypeScript program the same agent loop and built-in tools (read, write and edit files, run commands, search the web), plus permissions, hooks, subagents, sessions and MCP. You give it a goal; it plans, calls tools, checks the results and stops when the job is done.

    Compare it with the Client SDK, where you call the Claude API directly and write the tool loop yourself, and with Managed Agents, where Anthropic hosts the loop for you.

    Authenticate with an API key from the Claude Console, or through Amazon Bedrock, Google Cloud or Microsoft Foundry. Anthropic does not allow third-party products built on the SDK to offer claude.ai login or rate limits unless previously approved (checked 18 November 2026).

  2. Step 2 of 6 · Read

    A minimal agent

    You need Python 3.10 or later, or Node.js 18.14 or later. Install the package, set ANTHROPIC_API_KEY in the shell where the agent will run (the SDK does not read .env files by itself), and save the script below in a folder that contains a sales.csv export.

    The agent may read and search files freely and edit files in its folder without asking. It streams messages as it works, so you can see each tool call.

    Install (Python with uv)
    uv init
    uv add claude-agent-sdk
    export ANTHROPIC_API_KEY=your-api-key
    Install (TypeScript)
    npm install @anthropic-ai/claude-agent-sdk
    agent.py
    import asyncio
    from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage
    
    
    async def main():
        async for message in query(
            prompt="Read sales.csv and write a 5 bullet summary of sales by region to summary.md.",
            options=ClaudeAgentOptions(
                allowed_tools=["Read", "Glob", "Grep", "Write"],
                permission_mode="acceptEdits",
            ),
        ):
            if isinstance(message, AssistantMessage):
                for block in message.content:
                    if hasattr(block, "text"):
                        print(block.text)
                    elif hasattr(block, "name"):
                        print(f"Tool: {block.name}")
            elif isinstance(message, ResultMessage):
                print(f"Done: {message.subtype}")
    
    
    asyncio.run(main())
  3. Step 3 of 6 · Try it in the terminal

    Run it

    With ANTHROPIC_API_KEY set in this shell, run agent.py inside the uv project.

    Hint: uv run, then the file name.

    Show the command
    $ uv run agent.py
    Tool: Glob
    Tool: Read
    The file has 214 rows across 3 regions. I will summarise them now.
    Tool: Write
    I saved the summary to summary.md.
    Done: success
  4. Step 4 of 6 · Read

    Tools and permissions

    allowed_tools pre-approves tools. It does not hide the others: Claude can still try any tool, and calls that need approval fall through to the permission mode. To remove a tool completely, list it in disallowed_tools. To limit the built-in tool set itself, pass tools.

    Permission modes, checked 18 November 2026: default sends anything that needs approval to your can_use_tool callback; dontAsk denies instead of asking, which suits unattended jobs; acceptEdits approves file edits inside the working folder; plan explores and plans while edits still need approval; auto lets a classifier model review actions; bypassPermissions runs almost everything and belongs only in an isolated environment.

    Checks run in this order: hooks, deny rules, ask rules, the mode, allow rules, then your callback. A deny rule wins even in bypassPermissions. A locked-down reader is allowed_tools=["Read", "Glob", "Grep"] with permission_mode="dontAsk".

  5. Step 5 of 6 · Quiz

    Check your understanding

    You set allowed_tools=["Read"] and permission_mode="bypassPermissions", expecting a read-only agent. What happens when Claude tries to run a Bash command?

    • It is blocked, because Bash is not in allowed_tools
    • The SDK pauses and asks you first
    • It runs. Add Bash to disallowed_tools, or use dontAsk mode, to stop it
    Show the answer

    It runs. Add Bash to disallowed_tools, or use dontAsk mode, to stop it Deny rules are checked before the mode, so disallowed_tools blocks Bash even in bypass mode. dontAsk denies anything you did not pre-approve.

  6. Step 6 of 6 · Sort

    Agent SDK or your own tool loop?

    Which fits each job better?

    • A nightly job that reads a repository, runs the tests and proposes a fix
    • One call that sorts support emails into five categories
    • An internal tool that edits files and hands subtasks to subagents
    • A product feature where your code must control every tool call and its format
    • An agent that should reuse your existing Claude Code skills and CLAUDE.md
    Show the answers
    • A nightly job that reads a repository, runs the tests and proposes a fix: Agent SDK. File access, shell commands and an agent loop are built in.
    • One call that sorts support emails into five categories: Client SDK with your own loop. A single request needs no agent loop or file tools.
    • An internal tool that edits files and hands subtasks to subagents: Agent SDK. Subagents and file editing come with the SDK.
    • A product feature where your code must control every tool call and its format: Client SDK with your own loop. Writing the loop yourself gives you that control.
    • An agent that should reuse your existing Claude Code skills and CLAUDE.md: Agent SDK. The SDK loads skills and memory from .claude folders the same way Claude Code does.