Trawl saves tokens on big fetches

published

An AI coding agent reads the web through its own fetch tool, which returns a short answer about one page. That suits one question, but a documentation site means one fetch per page, and a long page is cut short. trawl, my command-line crawler, saves a site to disk once. The agent then searches the files with the search tools grep and jq and reads only the lines that match. I crawled a documentation site with trawl 0.1.0 to measure where each one costs less, and checked how trawl compares with other crawlers.

Takeaways

  • For one question about one page, the agent's fetch tool costs fewer (the units a model's usage is counted in) than trawl.
  • For many pages from one site, a trawl crawl that the agent searches costs fewer tokens.
  • The saving comes from searching the files, and an agent that reads every file in full spends more than a fetch would.
  • A fetch tool reads the start of a long page, and trawl keeps the whole page.
  • The agent's search finds the site, trawl keeps it, and grep and jq answer the questions.
  • An agent uses its own fetch tool unless the request names trawl.
  • trawl crawls, extracts and records the run in one local command, and the nearest tools each cover part of that or run as a hosted service.

When does the agent's fetch tool cost less?

For one question about one page, the fetch tool costs less, because only its answer reaches the agent. Claude Code's WebFetch is the example here. It reads the first 100,000 characters of a page, and a separate model call reads them against the agent's question and returns only its answer. A crawl, by contrast, costs a command, its output and then whatever the agent reads from the files.

When does trawl cost less?

For many pages from one site, trawl costs less, because one crawl replaces a fetch per page and the agent reads only search results. I crawled the Claude Code docs with this command:

trawl https://code.claude.com/docs/en/overview --level 1 --scope path --exclude files,data,images,media

It saved 52 pages in 116 seconds, rendering each in Chrome. It also merged 1,857 table rows into 190 CSV (comma-separated values) files. Each row names the page it came from.

Why does searching the files matter?

Searching the files is where the saving comes from, because the files hold far more text than any one answer needs:

OutputCharacters
Markdown for all 52 pages3,854,727
hooks.md, the longest page apart from the changelog293,226
grep -rl PreToolUse pages, the 12 pages that name the PreToolUse hook event334
jq -r '[.wordCount, .url] | @tsv' pages.jsonl, every page with its length2,625
grep -rn PreToolUse pages, every matching line43,048

A search that names files costs a few hundred characters, and a list of every page a few thousand. An unfocused search over the whole crawl still costs tens of thousands. An agent that opens every file in full reads millions of characters, far more than a fetch's short answer.

What happens to a long page?

A fetch tool reads the start of a long page, and trawl keeps all of it. Eight of the 52 pages were longer than 100,000 characters in trawl's Markdown. hooks.md was 293,226, so a tool that stops at 100,000 sees about a third of it. With trawl, the agent searches all of it for the section it needs.

Which tool fits which job?

The agent's search finds the site, trawl keeps it, and grep and jq answer the questions. Claude Code's web search returns titles and URLs (web addresses), and the agent fetches the pages it picks.

JobBetter tool
Finding which pages existthe agent's web search
One question about one pagethe agent's web fetch
A docs section, a site, or many pages from one sitetrawl
Tables, figures, data files and PDFs (Portable Document Format files)trawl, which writes tables as CSV and a PDF's text beside it
Pages behind a sign-intrawl with --profile
Text in charts and imagestrawl with --ocr
Material needed again in a later sessiontrawl, whose output folder stays on disk

When is trawl the best choice?

trawl is the best choice when one crawl replaces several fetches, or when a fetch would see only part of the answer. That covers a question that spans several pages of one site, a page longer than the 100,000 characters a fetch reads, an answer inside a table, chart, PDF or data file, pages behind a sign-in, and material needed again. For one question about one short page, the agent's own fetch tool costs less.

An agent reaches for its own fetch tool unless the request names trawl. The request that works names trawl, the part of the site to crawl and how to read the output:

Crawl https://example.com/docs/ with trawl --level 1 --scope path --exclude files,data,images,media,
with --out in your scratch folder. Answer from the output with grep -rl, then a focused grep,
and jq over pages.jsonl and run.json. Do not read every file in full.

How does trawl compare with other crawlers?

trawl crawls, extracts and records the run in one local command. The nearest tools each cover part of that or run as a hosted service:

ToolWhat it is
FirecrawlA hosted service that turns pages and whole sites into Markdown, with a free tier and paid plans. Its server is open source under AGPL-3.0, so anyone can run their own copy.
Jina ReaderA hosted service: r.jina.ai/ in front of a URL returns that page as Markdown. Use is rate-limited, with more for an API key.
Crawl4AIAn open-source Python library under Apache-2.0, with a crwl command. It renders pages in a browser through Playwright and writes Markdown.
trafilaturaA Python library that extracts a page's main text. It finds pages through sitemaps and feeds.
HTTrackA site copier that saves a site's HTML, images and other files to a folder.
ScrapyA Python framework for crawlers, where each site gets a spider written for it.

What trawl gives me over them is all of these from one command:

  • Markdown per page, one JSON (a plain-text data format) line per page, tables merged into CSV, PDF text and images.
  • run.json, which lists what was fetched, skipped or blocked, and why, so a crawl can be checked for completeness.
  • Polite defaults: robots.txt, per-host delays, a stop at bot checks, and a guard that keeps a public crawl off the local network.
  • Everything runs locally, free.
  • Signed-in profiles bound to their site, text read from charts, and collapsed sections opened before the text is taken.

trawl starts from a URL I give it, and it writes files. Finding the URL is the search tool's job, and answering the question is the agent's.