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.
git clone --depth 1 https://github.com/JKHeadley/instarnpx agentmods add skills/jkheadley/instar/smart-web-fetchWrote 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.
[](https://agentmods.dev/skills/jkheadley/instar/smart-web-fetch)<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.
<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>- NVIDIA SkillSpector warn
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]
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.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00000 | $0.02027 |
| Opus 5.5 | $0.00000 | $0.00811 |
| Sonnet 5.5 | $0.00000 | $0.00405 |
| Haiku 4.5 | $0.00000 | $0.00203 |
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 3mo 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 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:
- Check
llms.txt— Many sites publish/llms.txtor/llms-full.txtwith curated content for AI agents. If present, this is the best source: intentionally structured, no noise. - 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.
- 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 [('&','&'),('<','<'),('>','>'),(' ',' '),(''',"'"),('"','"')]:
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)
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.
- 3mo ago First seen · 242 lines · 0 tokens per session scan A acdaebd7290e
smart-web-fetch is a skill published in the GitHub repository JKHeadley/instar (86 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.
smart-web-fetch compared with skills from other repositories
| Mod | Type | Stars | Last push | Licence | Scan | Tokens | Works with |
|---|---|---|---|---|---|---|---|
| smart-web-fetchJKHeadley/instar | Skill | 86 | today | MIT | A | 0 | Claude Code, Codex |
| phaser-pixi-2d-gamesmakifbaysal/tasktrooper | Skill | 123 | today | Apache-2.0 | A | 86 | Claude Code, Codex |
| node-typescript-security-pitfallsmakifbaysal/tasktrooper | Skill | 123 | today | Apache-2.0 | A | 53 | Claude Code, Codex |
| node-typescript-servicemakifbaysal/tasktrooper | Skill | 123 | today | Apache-2.0 | A | 51 | Claude Code, Codex |
| react-typescript-patternsmakifbaysal/tasktrooper | Skill | 123 | today | Apache-2.0 | A | 33 | Claude Code, Codex |
| V3 CLI Modernizationruvnet/ruflo | Skill | 83k | today | MIT | A | 35 | Claude Code |
| V3 Core Implementationruvnet/ruflo | Skill | 83k | today | MIT | A | 37 | Claude Code |