Web & External Data
After this lesson, you will be able to:
- Use `WebFetch` to pull a specific URL into Claude's context, docs, blog posts, API references
- Use `WebSearch` to discover current information when you don't know the URL
- Pick the right grounding source, WebFetch for known URLs, WebSearch for discovery, MCP for structured APIs, Context7 for library docs
- Avoid the four web-grounding pitfalls, stale data, hallucinated URLs, paywall failures, and over-fetching
Before you start
#The Three Grounding Tools
| Tool | Use For | Example |
|---|---|---|
| WebFetch | Specific URL you know | "Read https://docs.example.com/guides/getting-started" |
| WebSearch | Discovery, find current info | "What's the latest Next.js caching behavior?" |
| Context7 (MCP) | Library docs (React, Prisma, FastAPI...) | "How do I configure Drizzle migrations?" |
Claude Code picks automatically based on prompt. You can also force a tool by referencing it explicitly.
#WebFetch: Pull a Known URL
> Read this and summarize: https://example.com/docs/release-notes
WebFetch(url), retrieves the page (HTML → markdown), and reads it into context.WebFetch(url="https://example.com/docs/release-notes")What you get back: the page content as cleaned markdown. Images are referenced but not loaded by default.
Best for
- Reading a specific blog post or RFC
- Pulling an API reference page
- Reviewing a GitHub issue or discussion
- Quoting an official doc
Not great for
- Discovering pages (use WebSearch)
- Authenticated content (use MCP integration)
- JS-heavy SPAs (content may not render server-side)
#WebSearch: Discovery
> What are the breaking changes in React 19 vs React 18?
WebSearch(query) and gets back a structured result list:[
{ "title": "React 19 Migration Guide", "url": "react.dev/blog/2025/...", "snippet": "..." },
{ "title": "Breaking changes in React 19", "url": "github.com/...", "snippet": "..." },
{ "title": "What's new in React 19 - YouTube", "url": "youtube.com/...", "snippet": "..." }
]
WebFetch on the most relevant URLs to read full content.Best for
- "What's the current state of X?"
- "Are there known issues with library Y version Z?"
- "How do other teams approach problem A?"
- Recent CVE / security advisory lookup
#Context7 MCP: Library Docs
For any well-known library, the Context7 MCP server returns version-pinned, structured documentation, better than scraping web pages.
> Use context7 to get the latest Drizzle ORM migration syntax
mcp__context7__resolve-library-id("drizzle") then mcp__context7__query-docs(...) and gets back curated docs.Best for
- React, Next.js, Vue, Angular hooks/components
- Backend frameworks (FastAPI, Express, Spring Boot, Django, Rails)
- ORMs (Prisma, Drizzle, SQLAlchemy)
- Cloud SDKs (AWS, GCP, Azure)
- AI/ML libraries (LangChain, LlamaIndex, Anthropic SDK)
Context7 is faster and more accurate than scraping for these cases. Use it before falling back to WebFetch.
#When to Ground vs When to Trust Training
| Question Type | Ground? |
|---|---|
| "How does Python's GIL work?" (stable, fundamental) | ❌ trust training, well-established |
| "Latest Next.js 16 caching behavior" | ✅ ground, recent and changing |
| "Best practice for X in 2026" | ✅ ground, opinions evolve |
| "Syntax of Python f-strings" | ❌ trust training, stable |
| "Available models on Anthropic API right now" | ✅ ground, changes weekly |
| "Migrating from React 18 to 19" | ✅ ground, version-specific |
| "What's a Hash table?" | ❌ trust training, universal CS |
Rule: if the answer could change between now and Claude's training cutoff, ground.
#The Four Pitfalls
#1. Stale Cache
WebFetch pages may be cached by Claude or by intermediate layers. For rapidly-changing content (live docs, status pages), ask explicitly for a fresh copy, or add a harmless query parameter to the URL so an older cached copy is not reused:
> Fetch https://status.example.com/api/v1/incidents (force fresh, ignore cache)
#2. Hallucinated URLs
docs.example.com/api/v3/messages for a version that was never released). Mitigation:- Use WebSearch FIRST when you don't have a verified URL
- Don't paste imagined URLs into the prompt, Claude will trust them
#3. Paywall / Auth Failures
Many sites (NYTimes, Medium, Substack, LinkedIn) return paywalled or login-required content. WebFetch returns whatever the unauthenticated request gets, often an error page or stub.
Mitigation: for content behind auth, use a dedicated MCP server (e.g., GitHub MCP for private repos) or paste the content directly.
#4. Over-Fetching
WebFetching 20 pages to answer a simple question wastes tokens and time. Be specific:
❌ "Search the web for everything about Drizzle ORM"
✅ "What's the current Drizzle ORM syntax for adding a foreign key?"
#Recipes
#Compare library versions
> Use context7 to compare Tanstack Query v4 vs v5 — what's the migration path?
#Verify a library API exists
> Before writing code with `prisma.user.findUniqueOrThrow`, verify this method exists in current Prisma docs (use context7)
#Pull a security advisory
> Look up CVE-2025-XXXX — affected versions, mitigation, patch availability
#Read a GitHub issue
> Read https://github.com/OWNER/REPO/issues/142 — summarize the bug and current status
#Synthesize across multiple sources
> Research best practices for Postgres connection pooling in 2026. Cross-reference at least 3 sources.
research-investigator sub-agent from the Subagents lesson.)#Combining Web Tools with Sub-agents
For deep research, delegate to a research sub-agent so the multi-page reading happens in a separate context. A sub-agent is a Markdown file with YAML frontmatter:
---
name: research-investigator
description: Multi-source web research with a sourced summary. Use for time-sensitive questions.
tools: WebFetch, WebSearch, Read
model: sonnet
---
Research the user's question. Cross-reference at least 3 reputable sources.
Synthesize a focused answer with source links. Note version/date for time-sensitive claims.
Then in main session:
> Use research-investigator to find the current best practice for React 19 server components data fetching
Main session gets a synthesized report; doesn't bloat with raw page content.
#Key Takeaways
- Three grounding tools: WebFetch (known URL), WebSearch (discovery), Context7 (library docs)
- Ground for time-sensitive info. Library versions, recent CVEs, current API specs
- Trust training for stable fundamentals. Language semantics, classic algorithms, well-established patterns
- Avoid the pitfalls: stale cache, hallucinated URLs, paywall failures, over-fetching
- Delegate deep research to sub-agents to keep main context clean
#Quick Check
User asks 'what's the current Anthropic API model list?'. Best approach?
You ask Claude for the latest Stripe SDK API for webhook verification. Which grounding sequence gives the highest-fidelity answer?