How to add llms.txt to Docusaurus
A documentation site is the textbook use case for llms.txt — your sidebar is already a curated index of exactly the pages an AI should read. Docusaurus makes serving the file trivial: it's a static-site generator, so you fully control the output root.
Generate the file first — paste your docs URL and get a spec-compliant llms.txt built from your real pages, then drop it in with the method below.
Generate my llms.txt →Method A — Static file (simplest)
Drop the file at static/llms.txt. Everything in static/ is copied verbatim to the build output root, so after npm run build it's live at /llms.txt with the correct text/plain type. Add static/llms-full.txt the same way for the full-text bundle.
Method B — Generate at build time from your docs
Want the file to stay in sync as docs change? Write it in a small lifecycle plugin that runs during postBuild, straight into the build output:
// plugins/llms-txt/index.js
const fs = require("fs");
const path = require("path");
module.exports = function llmsTxtPlugin() {
return {
name: "llms-txt-plugin",
async postBuild({ outDir, siteConfig }) {
const base = siteConfig.url;
const body = `# ${siteConfig.title}
> ${siteConfig.tagline}
## Docs
- [Introduction](${base}/docs/intro): start here
- [Guides](${base}/docs/guides): step-by-step tutorials
- [API](${base}/docs/api): reference
`;
fs.writeFileSync(path.join(outDir, "llms.txt"), body);
},
};
};
// docusaurus.config.js
module.exports = {
plugins: [require.resolve("./plugins/llms-txt")],
};Build the link list from your sidebars.js or by globbing docs/**/*.md frontmatter so the index tracks your real docs.
What to watch for
- baseUrl — if your site lives under a sub-path, static files inherit it. Serve Docusaurus at the domain root, or redirect
/llms.txtto the real path at your CDN. - Don't hand-list every page — llms.txt is a curated index. Point AI at your top-level sections, not all 300 doc pages.
- Don't block AI bots — a beautiful llms.txt is wasted if your host (Netlify, Vercel, Cloudflare Pages) or robots.txt blocks GPTBot / ClaudeBot.
Generate llms.txt and llms-full.txt from your docs URL, then ship it with Method A or B.
Try the free llms.txt generator →Related: llms.txt for VitePress · llms.txt for Next.js · How to create llms.txt · vs sitemap.xml