smart-web-fetch

smart-web-fetch is a skill for Claude Code, Codex from JKHeadley/instar. It costs 0 tokens per session (2,027 once invoked), scanned A, original, MIT.

A script for retrieving readable web-page content efficiently. It first looks for llms.txt, a site-provided file intended to help AI tools read documentation, then tries a Cloudflare Markdown version before extracting text from ordinary HTML.

In plain words
What is it for?
Fetching documentation, articles, and other web pages from a URL. It can be installed as a single Python script without extra packages.
Why use it?
Normal web pages contain menus, footers, adverts, and cookie notices that consume time and context. This fetch order can provide the useful page content with less noise when a cleaner source exists.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions CLAUDE.md.

Needs its repository: it runs a file that does not travel with it, so clone the repository first. The line is Usage: python3 .claude/scripts/smart-fetch.py <url> [--raw] [--source].

Good fit Fetching documentation, articles, and other web pages from a URL. It can be installed as a single Python script without extra packages.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/JKHeadley/instar
agentmods
npx agentmods add skills/jkheadley/instar/smart-web-fetch

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for smart-web-fetch

README.md
[![agentmods](https://agentmods.dev/badge/skills/jkheadley/instar/smart-web-fetch/github.svg)](https://agentmods.dev/skills/jkheadley/instar/smart-web-fetch)
Your own site
<a href="https://agentmods.dev/skills/jkheadley/instar/smart-web-fetch"><img src="https://agentmods.dev/badge/skills/jkheadley/instar/smart-web-fetch/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for smart-web-fetch

Your own site · 80×15
<a href="https://agentmods.dev/skills/jkheadley/instar/smart-web-fetch"><img src="https://agentmods.dev/badge/skills/jkheadley/instar/smart-web-fetch.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,027 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe. Third-party audits
  • NVIDIA SkillSpector warn 7 Sept 2026
SkillSpector: 1 finding, up to medium

These are SkillSpector’s own severities. On a checked sample its high-severity flags on skills were ~96% false positives — a documented command, a public API, a “never do X” rule — so we show them as a caution to read, not a verdict. Why →

  • medium MCP Rug Pull · line 238
    npx commands without a version suffix (e.g. @1.0.0) create a rug-pull risk if the upstream server is compromised and publishes a malicious update.
    Fix: Pin the version: npx @scope/[email protected]
How audits are shown
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.02027
Opus 5 $0.00000 $0.01014
Sonnet 5 $0.00000 $0.00405
Haiku 4.5 $0.00000 $0.00203

Measured 9d ago against content hash acdaebd7290e, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

smart-web-fetch scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 9d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

import urllib.request
skills/smart-web-fetch/SKILL.md · 242 lines

How it starts

The opening of the file, as written. The whole thing — 242 lines — stays where its author put it; the contents beside it link to each section on GitHub.

smart-web-fetch — Token-Efficient Web Content Fetching

Fetching a webpage with the default WebFetch tool retrieves full HTML — navigation menus, footers, ads, cookie banners, and all. For a documentation page, 90% of the tokens go to chrome, not content. This script fixes that by trying cleaner sources first.

How It Works

The fetch chain, in order:

  1. Check llms.txt — Many sites publish /llms.txt or /llms-full.txt with curated content for AI agents. If present, this is the best source: intentionally structured, no noise.
  2. Try Cloudflare markdown — Cloudflare's network serves clean markdown for millions of sites via a URL prefix trick. If the site is behind Cloudflare, this returns structured markdown at ~20% of the HTML token cost.
  3. Fall back to HTML — Standard fetch, with HTML stripped to readable text. Reliable but verbose.

The result: typically 60-80% fewer tokens on documentation sites, blog posts, and product pages.


Installation

Copy the script into your project's scripts directory:

mkdir -p .claude/scripts

Then create .claude/scripts/smart-fetch.py with the contents below.


The Script

Save this as .claude/scripts/smart-fetch.py:

#!/usr/bin/env python3
"""
smart-fetch.py — Token-efficient web content fetching.
Tries llms.txt, then Cloudflare markdown, then plain HTML.
Usage: python3 .claude/scripts/smart-fetch.py <url> [--raw] [--source]
"""
import sys
import urllib.request
import urllib.parse
import urllib.error
import re
import json

def fetch_url(url, timeout=15):
    req = urllib.request.Request(url, headers={
        'User-Agent': 'Mozilla/5.0 (compatible; agent-fetch/1.0)'
    })
    try:
        with urllib.request.urlopen(req, timeout=timeout) as r:
            charset = 'utf-8'
            ct = r.headers.get('Content-Type', '')
            if 'charset=' in ct:
                charset = ct.split('charset=')[-1].strip()
            return r.read().decode(charset, errors='replace'), r.geturl()
    except urllib.error.HTTPError as e:
        return None, str(e)
    except Exception as e:
        return None, str(e)

def html_to_text(html):
    # Remove scripts, styles, nav, footer
    for tag in ['script', 'style', 'nav', 'footer', 'header', 'aside']:
        html = re.sub(rf'<{tag}[^>]*>.*?</{tag}>', '', html, flags=re.DOTALL|re.IGNORECASE)
    # Remove all remaining tags
    text = re.sub(r'<[^>]+>', ' ', html)
    # Decode common entities
    for ent, ch in [('&amp;','&'),('&lt;','<'),('&gt;','>'),('&nbsp;',' '),('&#39;',"'"),('&quot;','"')]:
        text = text.replace(ent, ch)
    # Collapse whitespace
    text = re.sub(r'\n\s*\n\s*\n', '\n\n', text)
    text = re.sub(r'[ \t]+', ' ', text)
    return text.strip()

def get_base(url):
    p = urllib.parse.urlparse(url)
    return f"{p.scheme}://{p.netloc}"

def try_llms_txt(base):
    for path in ['/llms-full.txt', '/llms.txt']:
        content, _ = fetch_url(base + path)
        if content and len(content) > 100 and not content.strip().startswith('<'):
            return content, 'llms.txt'
    return None, None

def try_cloudflare_markdown(url):
    # Cloudflare's markdown delivery: prefix with https://cloudflare.com/markdown/
    # Actually the pattern is: replace scheme+domain with r.jina.ai for Jina,
    # or use the /md/ subdomain pattern for CF Pages.
    # Most reliable open technique: jina.ai reader (no API key needed for basic use)
    jina_url = 'https://r.jina.ai/' + url
    content, final_url = fetch_url(jina_url, timeout=20)
    if content and len(content) > 200 and not content.strip().startswith('<!'):
        return content, 'markdown'
    return None, None

def smart_fetch(url, show_source=False):
    base = get_base(url)
    results = []

    # 1. Try llms.txt
    content, source = try_llms_txt(base)
    if content:
        results.append(('llms.txt', content))

    # 2. Try markdown delivery
    content, source = try_cloudflare_markdown(url)
    if content:
        results.append(('markdown', content))

    # 3. HTML fallback
    if not results:
        html, _ = fetch_url(url)
        if html:
            text = html_to_text(html)
            results.append(('html', text))

    if not results:
        print(f"ERROR: Could not fetch {url}", file=sys.stderr)
        sys.exit(1)

    # Use best result (prefer llms.txt > markdown > html)
    best_source, best_content = results[0]

    if show_source:
        print(f"[source: {best_source}]", file=sys.stderr)

    return best_content

if __name__ == '__main__':
    args = sys.argv[1:]
    if not args or args[0] in ('-h', '--help'):
        print(__doc__)
        sys.exit(0)

    url = args[0]
    show_source = '--source' in args

    content = smart_fetch(url, show_source=show_source)
    print(content)

Read the full file on GitHub · 242 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 9d ago First seen · 242 lines · 0 tokens per session scan A acdaebd7290e

Subscribe to this mod's changes

smart-web-fetch is a skill published in the GitHub repository JKHeadley/instar (79 stars, last pushed today), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 2,027 tokens. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.