All insights

Coding agents

Claude Code Web Search: Built-In Tools vs. the Claude API

Learn what web search in Claude Code means, how it differs from search in a Claude API application, and what to verify before choosing a production approach.

Illustration for Claude code web search

Short answer

Claude Code can search the web as part of its agent workflow. If you’re asking Claude to research something while working in a coding session, describe the question and ask it to search the web. Anthropic’s Claude Code documentation lists WebSearch and WebFetch among its tools; WebSearch requires permission in Manual mode. (Claude Code docs; permissions)

That is a different product path from adding web search to an application built with the Claude API. Anthropic documents a web-search tool for API requests, with its own tool versions and settings. The Agent SDK is another distinct option when you want to build an application using the Claude Code agent and its capabilities. (Claude API web-search docs; Agent SDK overview)

Choose based on where the task runs: use Claude Code for research during coding work; use the Messages API when your application makes Claude requests and needs search in that workflow; consider the Agent SDK when you want to embed the Claude Code agent. Don’t assume the products have identical search behavior or controls.

Which search approach fits your task?

Your need Start with Why Verify before relying on it
Look up current documentation, an error, or a technical fact while coding Claude Code Its official docs describe Claude Code as able to search the web, and its tool reference includes WebSearch and WebFetch. Confirm the tools are available in your environment and that permissions allow the search or fetch. In Manual mode, WebSearch requires approval. (Claude Code docs)
Add web-grounded answers to your own product using direct Claude API calls Messages API web-search tool Anthropic documents adding a web-search tool to the request; the response can include citations for sources drawn from search results. Under the default auto tool choice, Claude decides whether to call a tool; including web search does not itself guarantee that a search happens. Check current tool-choice support, model, platform, request settings, response format, and service constraints for your deployment. (web-search docs; tool-use docs)
Build an application that uses Claude Code’s agent loop and tools Agent SDK Anthropic describes the SDK as making Claude Code’s agent loop and capabilities programmable in Python and TypeScript. Check the SDK’s current setup, authentication, permissions, and deployment requirements. It is not simply the same thing as a direct Messages API request. (Agent SDK overview)
Choose your own search provider or enforce retrieval steps in application code External search plus your application’s model call Your application can decide when to search and what retrieved material to pass to the model. Evaluate search-provider terms, source retrieval, security, failure handling, and cost separately. No provider superiority is established here.

The choice is about the product surface and control you need, not a claim that one route is inherently more accurate. Anthropic says API web search returns citations for sources drawn from search results, but citations alone do not prove that every answer claim is supported. (Claude API web-search docs)

What “Claude Code web search” means

In Claude Code, web search is part of the tools the agent can use while carrying out a task. The official tool reference names WebSearch and WebFetch; the broader guide says Claude Code can search the web and interact with external services. (Claude Code tools reference)

A practical prompt might be:

Search the web for the current official guidance on this error. Prefer the project’s documentation, compare it with my installed version, and cite the sources you used.

If Claude asks permission to use WebSearch, approve it if appropriate for your task. Permission behavior depends on mode and settings; Anthropic’s permissions documentation says WebSearch requires approval in Manual mode. (Claude Code permissions)

For a URL you already have, ask Claude Code to inspect that page and answer a specific question. The tool reference documents WebFetch, but check current Claude Code documentation for its exact fetch behavior and access rules rather than inferring them from third-party descriptions. (Claude Code tools reference)

Claude API web search is a separate integration

For an application that calls Claude directly, Anthropic’s Messages API documentation says to add a web-search tool to the request’s tools array. Settings such as max_uses, domain lists, and user location belong on that tool. The documented response can include citations to sources from search results. (Claude API web-search docs)

The documentation lists three tool versions: web_search_20250305 for basic search, web_search_20260209 for dynamic filtering, and web_search_20260318 for response-inclusion control in agentic workflows. Anthropic describes dynamic filtering as available with Claude 4.6 and later models and Claude Mythos Preview. Treat that as the documentation’s stated scope, not a guarantee about every future model or deployment: check the exact model and platform you plan to use. For example, Anthropic’s documentation says Microsoft Foundry deployments hosted on Azure support only basic web search (web_search_20250305), without dynamic filtering. (Claude API web-search docs)

Enabling the API tool is not the same as guaranteeing a search. Anthropic’s tool-use documentation says the default tool_choice is auto, under which Claude decides whether to call a provided tool. The general tool-use documentation also describes any and named-tool choices, but confirm that the control you need is supported for web search with your exact model and platform before relying on it. If your application must decide deterministically when retrieval happens, external search orchestrated by your application is the clearer starting point. (tool-use overview; tool definitions)

This is not a Claude Code command. A third-party article dated September 15, 2025 shows a Messages API request using web_search_20250305, but that dated example does not establish today’s schema, model availability, or limits. Use Anthropic’s current API documentation for implementation. (Claude API web-search docs)

Production checklist: verify before you ship

Before using web-grounded answers in production, verify the details that can change the behavior or the decision:

  1. Confirm the product path. Are you using the Claude Code CLI or Agent SDK, a direct Messages API request, or an external search service followed by a Claude request? Their tool loops and controls are not interchangeable. (Agent SDK overview)
  2. Check the exact tool, model, and platform combination. Confirm the current search-tool version and that it is supported for your target model and deployment platform. Anthropic documents different tool versions and notes that availability differs by product and platform. (Claude API web-search docs)
  3. Decide who controls retrieval. With the default API auto tool choice, Claude decides whether to search. Test the relevant tool-choice behavior for your deployment; if your application must determine exactly when retrieval occurs, consider application-orchestrated external search. (tool-use overview)
  4. Inspect the real response. Test a representative request and confirm how search use, citations, and any returned source information appear in your chosen SDK or platform. Do not assume an old sample’s response structure is still current.
  5. Check claims against cited sources. Open the cited material; verify that it actually supports the important statements and is recent enough for the question. A citation is a lead to evidence, not an accuracy score.
  6. Test difficult cases. Include stale documentation, conflicting sources, questions that should not need a search, and queries where useful evidence is sparse. Record whether the system searched when needed and whether its final claims were supported.
  7. Review permissions and operational constraints. For Claude Code, check tool permissions and the environment. For API or external search, check the relevant provider’s current availability, billing, quotas, data handling, and failure behavior before selecting it. (Claude Code permissions)

There is no comparative accuracy benchmark in the sources cited here. If answer quality is a production requirement, evaluate it on your own representative queries rather than relying on unsupported claims that a particular MCP or search provider is “better.”

Official documentation

Sources

Tools reference - Claude Code Docs

How Claude Code works - Claude Code Docs

Configure permissions - Claude Code Docs

Web search tool - Claude Platform Docs

Agent SDK overview - Claude Code Docs

Tool use with Claude - Claude Platform Docs

Define tools - Claude Platform Docs

Contact us