콘텐츠로 이동

Tool Use#

Claude Platform Docs

API reference

EnglishConsoleLog in



Search

⌘K

First steps

Intro to ClaudeGet your API keyQuickstartAuthentication

Building with Claude

Features overviewUsing the Messages APIStop reasons and fallbackRefusals and fallbackFallback credit

Model capabilities

EffortTask budgets (beta)Fast mode (research preview)Structured outputsCitationsStreaming MessagesBatch processingSearch resultsStreaming refusalsMultilingual supportEmbeddings

Thinking

Tools

OverviewHow tool use worksTutorial: Build a tool-using agentDefine toolsHandle tool callsParallel tool useTool Runner (SDK)Strict tool useServer toolsWeb search toolWeb fetch toolCode execution toolAdvisor toolTool search toolMemory toolBash toolText editor toolComputer use toolTroubleshooting

Tool infrastructure

Tool referenceManage tool contextTool combinationsTool use with prompt cachingProgrammatic tool callingFine-grained tool streaming

Context management

Context windowsCompactionContext editingPrompt cachingMid-conversation system messages and tool changesBuild an orchestration modeCache diagnostics (beta)Token counting

Working with files

Files APIPDF support

Images and vision

Skills

OverviewQuickstartBest practicesSkills for enterpriseSkills in the API

MCP

Remote MCP serversMCP connector

MCP tunnels

Claude on cloud platforms

Amazon Bedrock (Opus 4.7 and later)Amazon Bedrock (Opus 4.6 and earlier)Claude Platform on AWSGoogle CloudMicrosoft Foundry

Log in

MessagesOverview

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Loading

Claude Platform Docs

Solutions#

Partners#

Learn#

Company#

Learn#

Help and security#

Terms and policies#

Messages/Tools

Tool use with Claude#

Copy page

Connect Claude to external tools and APIs. See where tools execute, when Claude calls them, and which tool fits your task.

Copy page

Tool use lets Claude call functions that you define or that Anthropic provides. Claude determines when to call a tool based on the user's request and the tool's description. It then returns a structured call that your application executes (client tools) or that Anthropic executes (server tools).

Here's a minimal example using a server tool, the Web search tool, which Anthropic executes for you:

cURLCLIPythonTypeScriptC#GoJavaPHPRuby

client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-opus-5",
    max_tokens=1024,
    tools=[{"type": "web_search_20260209", "name": "web_search"}],
    messages=[{"role": "user", "content": "What's the latest on the Mars rover?"}],
)
print(response.content)

Claude runs the search on Anthropic's infrastructure and returns the cited results in the same response. To have Claude call a function that you define, pass a tool with an input_schema, then execute the call when Claude returns a tool_use block. How tool use works shows that round trip end to end. Learn more about defining tools and handling tool calls.

#

How tool use works

Tools differ primarily by where the code executes. Client tools (including user-defined tools and tools with Anthropic-defined schemas, such as bash and text_editor) run in your application. Claude responds with stop_reason: "tool_use" and one or more tool_use blocks. Your code executes the operation and sends back a tool_result. Server tools (such as web_search, web_fetch, code_execution, and tool_search) run on Anthropic's infrastructure: you see the results directly without handling execution, unless Claude calls the tool in the same group of parallel tool calls as one of your client tools (see Stop reasons and fallback).

Here's that round trip in full for a client tool. The first request defines a get_weather tool, and Claude answers the question by calling it: the response carries a tool_use block, your code runs the lookup, and a second request sends the result back in a tool_result block so Claude can reply with the answer.

cURLCLIPythonTypeScriptC#GoJavaPHPRuby

client = anthropic.Anthropic()

tools = [
    {
        "name": "get_weather",
        "description": "Get the current weather for a given location.",
        "input_schema": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "City and state, e.g. San Francisco, CA",
                }
            },
            "required": ["location"],
        },
    }
]
messages = [{"role": "user", "content": "What's the weather in San Francisco?"}]

# Claude replies with a tool_use block naming the tool and its arguments.
response = client.messages.create(
    model="claude-opus-5",
    max_tokens=1024,
    tools=tools,
    # Ask for at most one tool call per turn.
    tool_choice={"type": "auto", "disable_parallel_tool_use": True},
    messages=messages,
)
tool_use = next(block for block in response.content if block.type == "tool_use")
print(f"Claude called {tool_use.name} with {json.dumps(tool_use.input)}")

# Run the tool, then send the result back in a tool_result block.
weather = "15 degrees Celsius, partly cloudy"  # your weather lookup goes here
messages += [
    {"role": "assistant", "content": response.content},
    {
        "role": "user",
        "content": [
            {"type": "tool_result", "tool_use_id": tool_use.id, "content": weather}
        ],
    },
]
followup = client.messages.create(
    model="claude-opus-5",
    max_tokens=1024,
    tools=tools,
    tool_choice={"type": "auto", "disable_parallel_tool_use": True},
    messages=messages,
)

# Claude uses the result to answer the original question.
final_text = next(block for block in followup.content if block.type == "text")
print(final_text.text)

Output

Claude called get_weather with {"location": "San Francisco, CA"}
The current weather in San Francisco is 15 degrees Celsius with partly cloudy skies.

Handle tool calls covers each step in detail, including result formatting and error signaling; Parallel tool use covers responses that call several tools at once. To skip writing this round trip yourself, use Tool Runner: the SDKs execute your tools and send the results back automatically.

For the full conceptual model including the agentic loop and when to choose each approach, see How tool use works.

For connecting to Model Context Protocol (MCP) servers, see the MCP connector. For building your own MCP client, see the Model Context Protocol guide to building an MCP client.

#

When Claude uses tools

With the default tool_choice of {"type": "auto"}, Claude determines on each turn whether to call a tool or respond directly. It calls a tool when the request maps to that tool's described capability and the answer isn't already in context. It responds directly for stable knowledge, creative tasks, and conversational turns.

This boundary is steerable through your system prompt. If Claude isn't calling tools when you expect, a light