agentic402

Reduce Claude Code token usage on web pages

Published 3 December 2026 ยท Updated 3 December 2026

Reduce Claude Code token usage from web pages by never letting raw HTML into the conversation: read the site's Markdown or llms.txt copy when it has one, convert pages to Markdown before they reach context, read only the section you need, and hand documentation lookups to a subagent. On 12 real pages we measured, the Markdown was a median 96% smaller than the raw HTML.

How many tokens a web page costs

Claude Code's own cost guide starts from one rule: "Token costs scale with context size: the more context Claude processes, the more tokens you use." Web pages are among the largest things that enter a coding session, and most of their size isn't the text you wanted.

On 3 December 2026 we measured 12 public pages as raw HTML and as Markdown after the cleanup and conversion our URL to Markdown tool uses. Tokens are estimated at 4 characters each:

Estimated tokens per page, raw HTML vs Markdown. Measured 3 December 2026; 4 characters per token.
PageRaw HTMLMarkdownSaved
vercel.com/pricing316k4k99%
github.com/pricing235k5k98%
react.dev/learn61k4k94%
blog.cloudflare.com54k3k95%
Python docs: json29k8k71%

A single framework-built page like Vercel's pricing page is around 316,000 estimated tokens of HTML. The same page as Markdown is about 4,000. The full set of 12 pages, with the method and raw data, is in our HTML vs Markdown token study.

Anthropic's documentation for its API web fetch tool gives similar rules of thumb for text that has already been extracted: "Average webpage (10 kB): ~2,500 tokens", "Large documentation page (100 kB): ~25,000 tokens" and "Research paper PDF (500 kB): ~125,000 tokens". Those are about 4 bytes per token too, so a quick estimate for any page is its size in bytes divided by four.

Why the HTML is so much bigger than the text

The ratios in our sample are large: Linear's pricing page was 143 times bigger as HTML than as Markdown, Vercel's 75 times, Stripe's 36 times. The cleanup that produced those Markdown versions removes scripts, style blocks, inline SVG graphics, navigation, headers and footers, forms, buttons and images, then converts what's left. On a framework-built page, the removed parts are most of the file.

A model reading the raw HTML pays for all of that and then has to find the prose inside it. Converted pages aren't only cheaper. There is also less noise for the model to wade through before it reaches the part you asked about.

Where web pages enter a Claude Code session

There are three common ways, and they cost very different amounts. When you paste a URL and ask Claude to read it, it can use its built-in web fetch tool. When Claude runs curl through the shell, whatever curl prints comes back as tool output, raw HTML included. And MCP servers that fetch pages return whatever their tool produces, which may be cleaned text or may not.

The curl case is the one to watch. A coding agent often reaches for it to check an API's documentation or a changelog, and a modern documentation page can be hundreds of kilobytes of HTML. Ask for a Markdown source instead, or pipe the output through a converter before Claude sees it. If you approve shell commands one by one, a curl to a web page is a good moment to say no and suggest a Markdown source instead.

1. Use the site's own Markdown when it has one

Some documentation sites publish Markdown alongside HTML for agents to read. Claude Code's own documentation is an example: its pages are available as Markdown by adding .md to the URL, and each one points to an index with "Fetch the complete documentation index at: https://code.claude.com/docs/llms.txt". The llms.txt convention proposes exactly this: a Markdown index at /llms.txt and "a clean markdown version of those pages at the same URL as the original page" with .md added.

Before fetching a docs page, try /llms.txt on the site, then the page's URL with .md. If either exists, it's free and already small. This site does the same: every page has a Markdown copy at the page's address with index.md added, linked from the page head. Our llms.txt guide covers what the files contain and how much evidence there is that AI tools use them.

You can put this in your project's instructions, for example: "When reading documentation, check for /llms.txt or a .md version of the page before fetching HTML."

2. Convert the page before it reaches context

When a site has no Markdown copy, convert it on the way in. Anything that strips scripts, styles and navigation and outputs Markdown helps. Our fetch tool does it as an API call, $0.005 per page with no account, and is also available as an MCP tool, so Claude Code can call it directly:

claude mcp add --transport http agentic402 https://agentic402.dev/mcp

Paid MCP tools need a client that can pay with x402; the MCP setup page explains how payment works over MCP. The token arithmetic is simple: if your model charges, say, $3 per million input tokens (an illustrative rate, not a quote for any model. Check your own), then reading the median page in our study as raw HTML, about 141,000 tokens, would cost about $0.42 in input tokens once, against $0.005 for the conversion. For a page that is already mostly text, like the Python documentation (71% saved), the gap is much smaller.

Conversion also handles two things a plain fetch can't. Anthropic's API web fetch tool documentation states that it "currently does not support websites dynamically rendered with JavaScript". Fetch loads such pages in a real browser when the plain fetch comes back nearly empty. And PDFs, Word and Excel files come back as Markdown text instead of raw bytes.

3. Read the section, not the page

Even as Markdown, a long page is often more than the task needs. A large documentation page may still run to tens of thousands of tokens when only one section answers your question. Three habits help.

Ask for an outline first: the headings, or the first lines under each. Then ask for the one section that matters. When the fetch tool can return metadata, check the size first: fetch's JSON format includes word_count, so Claude can decide whether to read the whole page before it does. And when a page is mostly reference tables, ask for the specific rows by searching the Markdown, for example with grep on a saved copy, instead of reading the whole table.

4. Send documentation reading to a subagent

Claude Code's cost guide recommends this directly: "Running tests, fetching documentation, or processing log files can consume significant context. Delegate these to subagents so the verbose output stays in the subagent's context while only a summary returns to your main conversation."

That fits web research well. A subagent can read five documentation pages, work out the answer and return a paragraph. The pages' tokens are still spent, inside the subagent, but they don't sit in your main conversation, where they would be resent with every later message until you clear it. Combine this with Markdown sources and the subagent's own cost drops too, since it reads the same pages in a fraction of the tokens.

5. Don't read the same page twice

A long session often comes back to the same page: the API reference you checked an hour ago, the migration guide you read yesterday. Each re-read costs its full size again. Save pages you'll need more than once as Markdown files in the project (a docs/vendor/ folder works) and point Claude at the file. For agents that run across many sessions, our recipe for keeping fetched pages stores them outside the machine so any later run can read them free.

6. Clear context between tasks, and check what's in it

Web pages that stay in context are paid for again on every turn. The cost guide's advice: "Use /clear to start fresh when switching to unrelated work. Stale context wastes tokens on every subsequent message." When you need to keep the session but shrink it, /compact summarises the history, and you can tell it what to keep, as in the guide's example "/compact Focus on code samples and API usage".

To see what is taking space, the guide points to /context. If an earlier page fetch is a large slice, that is the sign to clear or compact before carrying on.

A quick audit of one session

Before changing habits, find out whether web pages are your problem at all. In a session where Claude has been reading documentation, run /context and look at what takes the most space. Large tool results from a fetch or a curl call are the sign. Then look at what those pages were: a framework-built marketing page read as HTML is the worst case, a docs page fetched as Markdown is already close to the best.

If pages turn out to be a small share, the bigger savings are elsewhere: stale context from earlier tasks, verbose test or log output, or model choice. On the last, the cost guide notes that "Sonnet handles most coding tasks well and costs less than Opus." If pages are a large share, the six techniques above address them in order of effort, cheapest first.

Writing the rules into the project

Habits stick better when they're written down where Claude reads them. A few lines in the project's instructions file cover most of this page:

## Reading web pages
- Check the site's /llms.txt or the page's .md version before fetching HTML.
- Never curl a web page into the conversation; fetch it as Markdown.
- For docs lookups that need more than one page, use a subagent and return a summary.
- Save pages you'll read again under docs/vendor/ as Markdown.

Keep it short. Claude Code's cost guide also suggests moving long instructions out of the always-loaded file into skills, so the instructions themselves don't become a token cost on every message.

What adding an MCP fetch tool costs in context

A common worry is that every MCP server adds tool definitions to every message. Claude Code's documentation addresses it: "MCP tool definitions are deferred by default, so only tool names and server instructions enter context until Claude uses a specific tool." The same section still recommends disabling servers you aren't using and preferring CLI tools where they exist. A fetch tool that's used several times a session easily pays for its small listing; one you never call is better switched off with /mcp.

Pages that won't shrink much

The saving depends on how much of the page was markup. Pricing and marketing pages built with heavy frameworks saved 94% to 99% in our measurements. Documentation that is mostly prose saved less: the Python json docs dropped by 71% and a long Wikipedia article by 83%. For pages like that, the bigger win is reading less of them (technique 3) rather than converting them.

Also keep in mind that our numbers compare against raw HTML. If a tool already extracts text before Claude reads it, the remaining saving from converting to Markdown is smaller than these figures, and the habits above (sections, subagents, clearing) matter more.

Questions about web pages and Claude Code tokens

How many tokens is a typical web page?
As raw HTML, the median page in our 12-page sample was about 141,000 estimated tokens. As Markdown, about 4,700. Anthropic's API documentation estimates about 2,500 tokens for an average 10 kB page of extracted text.
Is fetched page text safe to give Claude?
Treat it as untrusted. Pages can contain instructions aimed at the model reading them. Keep fetched text as material to read, not as instructions, and be careful with permissions in sessions that browse the web.
Does Markdown lose information compared with HTML?
It drops scripts, styling, navigation and images, which is the point. It can also drop content that only exists in interactive elements. For reading documentation and articles, the text that matters survives.

Cite this page: agentic402, "Reduce Claude Code token usage on web pages", https://agentic402.dev/guides/reduce-claude-code-token-usage-web-pages/, published 3 December 2026. Claude Code quotes are from its cost and documentation pages, and the web fetch figures from Anthropic's API documentation, as read that day.