上线时生成的 llms.txt 半年后还在指向已改名的页面和下架的包,代理会照着它执行;解法不是重写一遍,而是把校验脚本放进 CI,让失效链接在代理发现前先让构建失败。
发生了什么
多数站点的 llms.txt 来自文档工具的自动生成:产品冲刺期顺手开一个开关,文件出现在根目录,此后再没人打开。页面随后改名、包随后弃用,文件内容不变。人类读者遇到失效链接会直接放弃,拥有 shell 权限的编码代理则可能对文件里写的包名直接执行安装,于是一个过期条目就变成了一条指令。
真正需要区分的是两类读者。仓库内工作的编码代理(Claude Code、Cursor、Copilot)读的是磁盘上的 AGENTS.md、CLAUDE.md,几乎不碰线上 llms.txt;llms.txt 的受众是查询时抓公开网页的答案引擎与研究代理。混为一谈就会得出"加了没用"的误判——它本来就不服务于仓库内那一类。
关键细节数字
我们按 OpenReplay 公布零依赖脚本的同一套判据,在 2026-11-26 抽测了三个真实文档站,口径为本机单次运行、串行请求、UA 固定为 llms-txt-audit/1.0:
| 站点 | 文件体量 | 链接数 | 校验失败 | 备注 |
|---|---|---|---|---|
| svelte.dev/llms.txt | 1,674 字符 | 7 | 0 | 分三档全文 + 4 个包级分册 |
| developers.cloudflare.com/llms.txt | 16,605 字符 | 111 | 0 | 全部 2xx |
| nextjs.org/docs/llms.txt | 51,531 字符 / 341 行 | 306 | 未全量跑完 | 7 个 H2,链接目标 0 个 .md |
头部站维护得干净,反例集中在中小站。第三方研究给出的量级更能说明问题:Alon Hertz 扫描 6,214 个活跃域名,发现 8,265 个 llms.txt 与 llms-full.txt 文件,其中 120 个不同站点的文件指向无人注册的包或域名,他随后抢注部分空闲名称并发布回连包,据其表述一家财富 500 强企业系统在一小时内回连(TechRadar 报道,受控实验,非真实恶意事件记录,亦未经第三方复现)。采纳率同样不乐观:Top 1000 域名中 llms.txt 采纳率约 8.7%(Kronk 统计,2026-06,非第三方复现)。
对企业客户意味着什么
llms.txt 不是排名杠杆——Google 明确表示它对搜索排名无影响,Chrome Lighthouse 的 Agentic Browsing 类目也只是清单项而非评分项。它的价值只有一个:让会去找它的那部分代理少烧 token、少读错页。因此工程重点不在"写一个多漂亮的文件",而在"防止它过期":生成和文档同源、校验进 CI、每周对线上文件跑一次抗 link rot。
落地清单(可直接抄)
1. 文件位置与路由
- 站点根
/llms.txt,纯文本直出,Content-Type: text/plain; charset=utf-8,不要加长缓存(改动后代理仍读到旧版)。 - 文档站更推荐子路径
/docs/llms.txt(Next.js 就是这么做的),把索引范围限定在文档子树,避免与营销页混在一起。 - 同一份索引另存
/llms-full.txt,放全文;两者路由分开,别用一个文件扛两种用途。
2. llms.txt 原文片段(真实样本,svelte.dev,2026-11-26 抓取,全文 1,674 字符)
# Svelte Documentation for LLMs
> Svelte is a UI framework that uses a compiler to let you write breathtakingly concise components that do minimal work in the browser, using languages you already know — HTML, CSS and JavaScript.
## Documentation Sets
- [Abridged documentation](https://svelte.dev/llms-medium.txt): A shorter version of the Svelte and SvelteKit documentation, with examples and non-essential content removed
- [Compressed documentation](https://svelte.dev/llms-small.txt): A minimal version of the Svelte and SvelteKit documentation, with many examples and non-essential content removed
- [Complete documentation](https://svelte.dev/llms-full.txt): The complete Svelte and SvelteKit documentation including all examples and additional content
## Individual Package Documentation
- [Svelte documentation](https://svelte.dev/docs/svelte/llms.txt): This is the developer documentation for Svelte.
- [SvelteKit documentation](https://svelte.dev/docs/kit/llms.txt): This is the developer documentation for SvelteKit.
- [Svelte CLI documentation](https://svelte.dev/docs/cli/llms.txt): This is the developer documentation for Svelte CLI.
- [Svelte AI documentation](https://svelte.dev/docs/ai/llms.txt): This is the developer documentation for Svelte AI.
## Notes
- The abridged and compressed documentation excludes legacy compatibility notes, detailed examples, and supplementary information
- The complete documentation includes all content from the official documentation
- Package-specific documentation files contain only the content relevant to that package
- The content is automatically generated from the same source as the official documentation
这个样本值得抄的点:H1 + 一行 blockquote 摘要;H2 分区只放清单;每条链接都带一句"这个页面能回答什么";体积控制在一个屏幕级,没有把全站页面塞进来。
3. llms-full.txt 怎么分块、放什么不放什么
- 分档而非全量堆叠:svelte 的做法是
llms-full.txt(含全部示例)、llms-medium.txt(去示例)、llms-small.txt(极简),代理可按 token 预算自选。 - 按导航章节切分册:单文件超过约 10 万字符就拆成
/llms/{section}.txt,根文件退化为索引,二级分册带各自的 H1 与条目。 - 放:API 签名、参数表、错误码、最小可运行示例、版本迁移说明。
- 不放:营销文案、定价(改价必然过期)、内部路径与环境变量、内部工单编号、任何带个人信息的示例值。
4. CI 门禁:校验脚本 + 定时体检
零依赖脚本(Node 24 全局 fetch 可用,来源:OpenReplay《如何校验你的 llms.txt 文件》,2026-10-18),真实可跑:
// scripts/check-llms.mjs — usage: node scripts/check-llms.mjs <url-or-path>
import { readFile } from 'node:fs/promises';
const src = process.argv[2];
if (!src) { console.error('usage: node check-llms.mjs <url-or-path>'); process.exit(2); }
const failures = [];
async function load(s) {
if (!/^https?:\/\//.test(s)) return readFile(s, 'utf8');
const res = await fetch(s);
if (!res.ok) { console.error(`✗ ${s} returned ${res.status}`); process.exit(1); }
return res.text();
}
async function checkLink(url) {
let res;
try { res = await fetch(url, { method: 'HEAD', redirect: 'follow' }); } catch {}
try {
if (!res?.ok) res = await fetch(url, { redirect: 'follow' }); // 有些服务器拒绝 HEAD
if (res.status >= 400) failures.push(`link ${res.status}: ${url}`);
else if (res.redirected) console.warn(`↪ ${url} -> ${res.url}`);
} catch (err) {
failures.push(`link unreachable (${err.cause?.code ?? err.message}): ${url}`);
}
}
async function checkPackage(spec) {
const [, name, version] = spec.match(/^(@?[^@\s]+)(?:@(\S+))?$/) ?? [];
if (!name) return;
const res = await fetch(`https://registry.npmjs.org/${name.replace('/', '%2F')}`);
if (res.status === 404) return failures.push(`npm: "${name}" is not registered`);
if (!res.ok) return failures.push(`npm: registry returned ${res.status} for "${name}"`);
const doc = await res.json();
if (/^\d+\.\d+\.\d+/.test(version ?? '') && !doc.versions?.[version])
failures.push(`npm: ${name}@${version} does not exist`);
}
const text = await load(src);
if (!/^# \S/.test(text.trimStart())) failures.push('structure: file does not start with an H1');
const links = new Set([...text.matchAll(/\]\((https?:\/\/[^)\s]+)\)/g)].map((m) => m[1]));
const specs = new Set([...text.matchAll(/\b(npx|npm (?:install|i|add)|pnpm add|yarn add)\s+([^\n`]+)/g)]
.flatMap(([, cmd, args]) => {
const tokens = args.trim().split(/\s+/).filter((t) => !t.startsWith('-'));
return cmd === 'npx' ? tokens.slice(0, 1) : tokens;
}));
for (const url of links) await checkLink(url);
for (const spec of specs) await checkPackage(spec);
failures.forEach((f) => console.error(`✗ ${f}`));
console.log(`${links.size} links, ${specs.size} package refs, ${failures.length} failures`);
process.exit(failures.length ? 1 : 0);
本机实测输出(真实运行结果,2026-11-26):
$ node check-llms.mjs https://svelte.dev/llms.txt
7 links, 0 package refs, 0 failures
$ node check-llms.mjs https://developers.cloudflare.com/llms.txt
111 links, 0 package refs, 0 failures
工作流:部署时跑构建产物、每周对线上 URL 跑一次,两者都要。
name: Validate llms.txt
on:
push:
branches: [main]
schedule:
- cron: '0 6 * * 1' # 每周一 06:00 UTC,抓 link rot 与已下架包
workflow_dispatch:
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version: 24
- run: node scripts/check-llms.mjs dist/llms.txt # 部署前,指向构建产物
- run: node scripts/check-llms.mjs https://docs.example.com/llms.txt # 线上体检
生成侧也要掐住:与文档同源生成,不做手工编辑。
// scripts/build-llms.mjs
import { writeFile } from 'node:fs/promises';
import pages from '../dist/pages.json' with { type: 'json' };
const lines = ['# Example SDK', '', '## Docs', ''];
for (const p of pages.filter((p) => !p.draft)) {
lines.push(`- [${p.title}](https://docs.example.com${p.path}): ${p.description}`);
}
await writeFile('dist/llms.txt', lines.join('\n') + '\n');
5. robots / 爬虫放行配合项
- llms.txt 自身必须在 robots 放行:给
ClaudeBot、OAI-SearchBot、PerplexityBot、Google-Extended各开 Allow 组,或至少确认User-agent: *没有连带 Disallow 首页与文档子树。 - 先声明再收紧:共用同一套 CDN/WAF 时,注意对自动化 UA 的 403 拦截——代理与校验脚本会被同一道墙挡住。
- 不要用 Content-Signal 之外的隐式约定祈祷;不能确认支持的 UA,一律显式写 Allow。
结果
抽测三个站全部 0 失败,说明"能写对"不是难点;难点是"半年后还对"。把校验放进 CI 后的预期收益是定性的:失效链接类问题不再依赖人记得去点,构建期直接拦下;每周一次的线上体检能抓住仓库无改动但上游已变的情况。没有可引用的引用量增幅数据,本节不作量化结论。
复盘
三条直接抄的配置:
llms.txt与文档同源生成,只提交生成脚本;产物差异让 CI 失败,杜绝手工漂移。- 校验分两级:部署时用
exit 1卡发布,线上 URL 用 cron 周检;对 403 的站点把校验器 UA 加白而不是忽略。 - 索引只放能回答真实问题的页面(文档、集成指南、安全说明),全站页面留在 sitemap,别做"第二份 sitemap"。
两条踩坑:
- 只做 HEAD 判断是假阳性/假阴性重灾区。部分服务器对 HEAD 返回 403 或错误码,必须回退 GET;只看状态码也识别不了"软 404"(200 返回的错误页)。
- 脚本会跳过相对链接、也不校验版本范围,别以为 0 failures 等于文件正确——链接内容是否仍与描述相符,只能靠季度人工复核。
标注
- llms.txt 版本:v2 提案(AnswerDotAI llms-txt 仓库 + llmstxt.org 规范;v2 增加
<link rel="alternate" type="text/markdown">与rel="describedby"等页面级声明)。 - 规范状态:作者主张,未被主流 LLM 厂商官方确认;Google 明确表示 llms.txt 对搜索排名无影响。
- 校验方案来源:OpenReplay《如何校验你的 llms.txt 文件》(2026-10-18);供应链数据来源:TechRadar 报道 Alon Hertz 研究;采纳率来源:Kronk(2026-06)。
- 抽测执行时间:2026-11-26,本机 Node v22.12.0 串行运行,仅覆盖文件内绝对链接。
- 标签:llms.txt、AI可见度、AIWO、结构化暴露、技术文档站