How to add llms.txt to an Astro site

Astro does not create llms.txt. Put a file in public/ or build one with an endpoint, then check the header. Watch the base option.

Astro · llms.txt · Not built in

What Astro does today

Astro does not generate llms.txt. On 2026-10-19, a search for "llms" in the Astro integrations directory with the Official filter returned 0 results. The same search without the filter listed many community packages. Astro's own docs site returned 404 for /llms.txt that day.

You can add the file in two ways that Astro supports out of the box: copy a static file, or generate it at build time with an endpoint. llms.txt mostly helps coding agents and tools that fetch documentation, not Google or chat-assistant visibility. Documentation sites gain the most.

Add llms.txt to Astro

  1. Static file. Create public/llms.txt. Astro's docs say files in public/ "will be copied into the build folder untouched" and name robots.txt as a typical example, so public/llms.txt ends up at /llms.txt.

    # Example Co
    
    > Project-planning software with a REST API. Start with the guides.
    
    ## Docs
    
    - [Quickstart](https://example.com/docs/quickstart): Create a project in five minutes
    
  2. Generated file. Create src/pages/llms.txt.ts. Astro removes the .ts extension at build time, so this file builds /llms.txt. In a static site, Astro calls endpoints "at build time to produce static files". Use getCollection() to list your pages.

    import type { APIRoute } from "astro";
    import { getCollection } from "astro:content";
    
    export const GET = (async ({ site }) => {
      const docs = await getCollection("docs");
      const links = docs
        .map((entry) => `- [${entry.data.title}](${new URL(`/docs/${entry.id}/`, site)})`)
        .join("\n");
      const body = `# Example Co\n\n> Project-planning software with a REST API.\n\n## Docs\n\n${links}\n`;
      return new Response(body, {
        headers: { "Content-Type": "text/plain; charset=utf-8" },
      });
    }) satisfies APIRoute;
    

    Change "docs" to your collection name, title to a field your schema defines, and the /docs/${entry.id}/ path to match your page URLs. We did not run this snippet in a real project.

  3. Set site. Add site: "https://example.com" to astro.config.mjs. The endpoint receives it as site, which is undefined when the option is not set.

  4. On-demand only if you need it. The build-time endpoint works in a fully static site. If the file must change between deploys, enable an on-demand rendering mode. In static mode, add export const prerender = false to the endpoint.

  5. Or use a community package. For a Starlight docs site, starlight-llms-txt generates llms.txt, llms-full.txt and llms-small.txt. It needs site set. A GitHub user maintains it, not the withastro organization. Other packages in the directory are community-maintained too. Check each README and its supported Astro version.

Check that it works

Run astro build and look for llms.txt at the top of your build folder. After you deploy, run curl -sI https://example.com/llms.txt. Expect a 200 status and a text content type, not your 404 page as HTML. Astro's docs do not say what content type a host sends for a .txt file, so check the header.

Paste the file into the llms.txt validator. The llms.txt exists check explains what the audit accepts.

Limits and workarounds

  • base moves the pages. Astro's docs say base is "the root for your pages and assets". With base: "/docs", expect the endpoint at /docs/llms.txt. We could not verify from Astro's documentation that public/ files move too. The audit requests /llms.txt at your domain root and tries the docs., developers. and developer. subdomains. It does not try sub-paths. To pass, serve a copy at the domain root or host the docs on one of those subdomains.
  • No trailing slash. Astro's docs say endpoints with a file extension "can only be accessed without a trailing slash". Link to /llms.txt, not /llms.txt/.
  • Keep it curated. List the pages you would send a new engineer to. Your sitemap already lists every URL.

How common is it on Astro?

Among 71 measured Astro sites, the median w2agent Score is 56/100.

  • llms.txt exists: 86% of 71 Astro sites pass
  • llms.txt follows spec: 97% of 61 Astro sites pass
  • llms.txt links resolve: 72% of 61 Astro sites pass

Latest audit of each measured site. Sites where a check did not apply are left out.

Related checks

Check it

Test your file with the llms.txt validator.

Check your own site →

Sources

Verified against these sources on