Loading...
    • Developer Guide
    • API Reference
    • MCP
    • Resources
    • Release Notes
    Search...
    ⌘K
    First steps
    Intro to ClaudeQuickstart
    Models & pricing
    Models overviewChoosing a modelWhat's new in Claude 4.5Migrating to Claude 4.5Model deprecationsPricing
    Build with Claude
    Features overviewUsing the Messages APIContext windowsPrompting best practices
    Capabilities
    Prompt cachingContext editingExtended thinkingEffortStreaming MessagesBatch processingCitationsMultilingual supportToken countingEmbeddingsVisionPDF supportFiles APISearch resultsStructured outputs
    Tools
    OverviewHow to implement tool useFine-grained tool streamingBash toolCode execution toolProgrammatic tool callingComputer use toolText editor toolWeb fetch toolWeb search toolMemory toolTool search tool
    Agent Skills
    OverviewQuickstartBest practicesUsing Skills with the API
    Agent SDK
    OverviewQuickstartTypeScript SDKTypeScript V2 (preview)Python SDKMigration Guide
    MCP in the API
    MCP connectorRemote MCP servers
    Claude on 3rd-party platforms
    Amazon BedrockMicrosoft FoundryVertex AI
    Prompt engineering
    OverviewPrompt generatorUse prompt templatesPrompt improverBe clear and directUse examples (multishot prompting)Let Claude think (CoT)Use XML tagsGive Claude a role (system prompts)Prefill Claude's responseChain complex promptsLong context tipsExtended thinking tips
    Test & evaluate
    Define success criteriaDevelop test casesUsing the Evaluation ToolReducing latency
    Strengthen guardrails
    Reduce hallucinationsIncrease output consistencyMitigate jailbreaksStreaming refusalsReduce prompt leakKeep Claude in character
    Administration and monitoring
    Admin API overviewUsage and Cost APIClaude Code Analytics API
    Console
    Log in
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...
    Loading...

    Solutions

    • AI agents
    • Code modernization
    • Coding
    • Customer support
    • Education
    • Financial services
    • Government
    • Life sciences

    Partners

    • Amazon Bedrock
    • Google Cloud's Vertex AI

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Company

    • Anthropic
    • Careers
    • Economic Futures
    • Research
    • News
    • Responsible Scaling Policy
    • Security and compliance
    • Transparency

    Learn

    • Blog
    • Catalog
    • Courses
    • Use cases
    • Connectors
    • Customer stories
    • Engineering at Anthropic
    • Events
    • Powered by Claude
    • Service partners
    • Startups program

    Help and security

    • Availability
    • Status
    • Support
    • Discord

    Terms and policies

    • Privacy policy
    • Responsible disclosure policy
    • Terms of service: Commercial
    • Terms of service: Consumer
    • Usage policy
    Agent SDK

    Agent SDK overview

    Build production AI agents with Claude Code as a library

    The Claude Code SDK has been renamed to the Claude Agent SDK. If you're migrating from the old SDK, see the Migration Guide.

    Build AI agents that autonomously read files, run commands, search the web, edit code, and more. The Agent SDK gives you the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript.

    import asyncio
    from claude_agent_sdk import query, ClaudeAgentOptions
    
    async def main():
        async for message in query(
            prompt="Find and fix the bug in auth.py",
            options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"])
        ):
            print(message)  # Claude reads the file, finds the bug, edits it
    
    asyncio.run(main())

    The Agent SDK includes built-in tools for reading files, running commands, and editing code, so your agent can start working immediately without you implementing tool execution. Dive into the quickstart or explore real agents built with the SDK:

    Quickstart

    Build a bug-fixing agent in minutes

    Example agents

    Capabilities

    Everything that makes Claude Code powerful is available in the SDK:

    Claude Code features

    The SDK also supports Claude Code's filesystem-based configuration. To use these features, set setting_sources=["project"] (Python) or settingSources: ['project'] (TypeScript) in your options.

    FeatureDescriptionLocation
    SkillsSpecialized capabilities defined in Markdown.claude/skills/SKILL.md
    Slash commandsCustom commands for common tasks.claude/commands/*.md
    MemoryProject context and instructionsCLAUDE.md or .claude/CLAUDE.md
    PluginsExtend with custom commands, agents, and MCP serversProgrammatic via plugins option

    Get started

    Ready to build? Follow the Quickstart to create an agent that finds and fixes bugs in minutes.

    Compare the Agent SDK to other Claude tools

    The Claude platform offers multiple ways to build with Claude. Here's how the Agent SDK fits in:

    Changelog

    View the full changelog for SDK updates, bug fixes, and new features:

    • TypeScript SDK: view CHANGELOG.md
    • Python SDK: view CHANGELOG.md

    Reporting bugs

    If you encounter bugs or issues with the Agent SDK:

    • TypeScript SDK: report issues on GitHub
    • Python SDK: report issues on GitHub

    Branding guidelines

    For partners integrating the Claude Agent SDK, use of Claude branding is optional. When referencing Claude in your product:

    Allowed:

    • "Claude Agent" (preferred for dropdown menus)
    • "Claude" (when within a menu already labeled "Agents")
    • "{YourAgentName} Powered by Claude" (if you have an existing agent name)

    Not permitted:

    • "Claude Code" or "Claude Code Agent"
    • Claude Code-branded ASCII art or visual elements that mimic Claude Code

    Your product should maintain its own branding and not appear to be Claude Code or any Anthropic product. For questions about branding compliance, contact our sales team.

    License and terms

    Use of the Claude Agent SDK is governed by Anthropic's Commercial Terms of Service, including when you use it to power products and services that you make available to your own customers and end users, except to the extent a specific component or dependency is covered by a different license as indicated in that component's LICENSE file.

    Next steps

    Quickstart

    Build an agent that finds and fixes bugs in minutes

    Example agents
    • Capabilities
    • Claude Code features
    • Get started
    • Compare the Agent SDK to other Claude tools
    • Changelog
    • Reporting bugs
    • Branding guidelines
    • License and terms
    • Next steps

    Email assistant, research agent, and more

    1. 1

      Install Claude Code

      The SDK uses Claude Code as its runtime:

      See Claude Code setup for Windows and other options.

    2. 2

      Install the SDK

    3. 3

      Set your API key

      export ANTHROPIC_API_KEY=your-api-key

      Get your key from the Console.

      The SDK also supports authentication via third-party API providers:

      • Amazon Bedrock: set CLAUDE_CODE_USE_BEDROCK=1 environment variable and configure AWS credentials
      • Google Vertex AI: set CLAUDE_CODE_USE_VERTEX=1 environment variable and configure Google Cloud credentials
      • Microsoft Foundry: set CLAUDE_CODE_USE_FOUNDRY=1 environment variable and configure Azure credentials

      Unless previously approved, we do not allow third party developers to offer Claude.ai login or rate limits for their products, including agents built on the Claude Agent SDK. Please use the API key authentication methods described in this document instead.

    4. 4

      Run your first agent

      This example creates an agent that lists files in your current directory using built-in tools.

      import asyncio
      from claude_agent_sdk import query, ClaudeAgentOptions
      
      async def main():
          async for message in query(
              prompt="What files are in this directory?",
              options=ClaudeAgentOptions(allowed_tools=["Bash", "Glob"])
          ):
              if hasattr(message, "result"):
                  print(message.result)
      
      asyncio.run(main())

    Email assistant, research agent, and more

    TypeScript SDK

    Full TypeScript API reference and examples

    Python SDK

    Full Python API reference and examples