<!-- Generated from llms-txt-gatsby/index.html. The canonical document is the HTML page. -->

- [ Home ](/) 
/
- [ How to create ](/how-to-create/) 
/
- Gatsby guide            
# `llms.txt` for Gatsby

Two approaches for Gatsby: a zero-config static file in static/, or programmatic generation in gatsby-node.js using the GraphQL data layer to build links from your content.

Last updated: October 29, 2026

On this page

- [ Option 1: static file in static/ ](#static)
- [ Option 2: generate in gatsby-node.js ](#gatsby-node)
- [ Community plugin: gatsby-plugin-llms-txt ](#plugin)
- [ Verify ](#verify)               
Note

Project status

Gatsby is in limited development. On 2024-11-21 a Gatsby maintainer described the current level
of work in GitHub discussion #39062 as security fixes, limited dependency updates, low-hanging
bug fixes and performance improvements, and handling upcoming third-party API deprecations. The
latest  gatsby  release on npm is 5.16.1 (2026-02-10). Both approaches below rely only
on long-standing Gatsby features.

## Option 1: static file in static/

Gatsby copies everything in the `static/` directory directly into the `public/` build output. Place your file at `static/llms.txt` 
and it will be available at `/llms.txt` after `gatsby build`.
static/llms.txt, directory structure    Copy     

```
# Gatsby static file approach
#
# Place your file at: static/llms.txt
# Gatsby copies everything in static/ directly to the public/ build output.
#
# Project structure:
# your-gatsby-site/
# ├── static/
# │   └── llms.txt   ← add this
# ├── src/
# └── gatsby-config.js

```

This approach requires no code changes and works with all Gatsby deployment targets: **Netlify**, **Vercel**, **Cloudflare Pages**, **AWS Amplify**, and self-hosted.

Example

Pick one source for the file

Use either  static/llms.txt  or a build-time generator (Option 2 or a plugin), not both,
so that only one mechanism writes  public/llms.txt .

## Option 2: generate in gatsby-node.js

For sites where documentation pages are sourced from Markdown, MDX, or a CMS via the Gatsby data
layer, use the `onPostBuild` lifecycle hook in `gatsby-node.js` to generate `llms.txt` after the build completes. This ensures
the link list is always in sync with your content.
gatsby-node.js    Copy     

```
// gatsby-node.js
// Generate llms.txt from your GraphQL data layer
const { writeFileSync } = require('fs');
const { resolve } = require('path');

exports.onPostBuild = async ({ graphql }) => {
// Query your documentation pages (adjust the query to your data model)
const result = await graphql(`
query {
allMarkdownRemark(
filter: { frontmatter: { collection: { eq: "docs" } } }
sort: { frontmatter: { order: ASC } }
) {
nodes {
frontmatter {
title
description
}
fields {
slug
}
}
}
}
`);

if (result.errors) {
throw result.errors;
}

const docs = result.data.allMarkdownRemark.nodes;
const siteUrl = 'https://yoursite.com';

const links = docs
.map(
(doc) =>
`- [${doc.frontmatter.title}](${siteUrl}/docs/${doc.fields.slug}/): ${doc.frontmatter.description ?? ''}`
)
.join('\n');

const content = [
'# Your Site',
'',
'> One-sentence description of your project.',
'',
'## Documentation',
'',
links,
'',
'## Optional',
'',
`- [Changelog](${siteUrl}/changelog/): Release history.`,
].join('\n');

// Write to public/ (Gatsby's build output directory)
writeFileSync(resolve(__dirname, 'public', 'llms.txt'), content, 'utf-8');
};

```

The `onPostBuild` hook receives the same `graphql` function used in page queries.
Adjust the query to match your data model, the example uses `allMarkdownRemark` but you
can query any Gatsby source plugin (`allMdx`, `allContentfulPage`, etc.).

## Community plugin: gatsby-plugin-llms-txt

`gatsby-plugin-llms-txt` is a **community** plugin, not an official Gatsby
package (version 1.0.1, published 2025-09-28). In its `onPostBuild` hook it runs a GraphQL
query you provide, reads the field named by `contentPath` and writes that value to `public/llms.txt`; if the field is empty, no file is created. It suits sites that keep the full `llms.txt` text in a CMS field. Its README lists Gatsby v4 and v5 as supported.
gatsby-config.js, gatsby-plugin-llms-txt    Copy     

```
// npm install gatsby-plugin-llms-txt
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-llms-txt',
options: {
// GraphQL query returning the llms.txt text (example: a CMS settings document)
query: `
query {
settings {
llmsTxt
}
}
`,
// Dot path to the field that holds the content in the query result
contentPath: 'settings.llmsTxt',
},
},
],
};
```

The plugin does not build a link list from your pages. To derive the list from content, the
`gatsby-node.js` approach above remains the direct route.

You can also use **gatsby-plugin-sitemap** as a reference, it uses the same `onPostBuild` pattern to write an XML file to `public/`.

## Verify
Build and verify    Copy     

```
# Build
gatsby build

# Check generated file
cat public/llms.txt | head -10

# After deploying, verify the live URL
curl -I https://yoursite.com/llms.txt
# Expected: content-type: text/plain; charset=utf-8
```

## Related guides

- [How to create llms.txt](/how-to-create/), templates and checklist. 
- [llms.txt format reference](/llms-txt-format/), spec details. 
- [Eleventy guide](/llms-txt-eleventy/), another static site generator approach. 
- [Next.js guide](/llms-txt-nextjs/), React framework with SSR. 
- [Validator](/validator/) · [Generator](/generator/).         
## Sources

- [ llmstxt.org, community proposal ](https://llmstxt.org/)
- [ Gatsby docs, static folder ](https://www.gatsbyjs.com/docs/how-to/images-and-media/static-folder/)
- [ Gatsby docs, gatsby-node.js ](https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/)
- [ GitHub discussion #39062, maintainer reply of 2024-11-21 on Gatsby status ](https://github.com/gatsbyjs/gatsby/discussions/39062)
- [ npm, gatsby (5.16.1) ](https://www.npmjs.com/package/gatsby)
- [ npm, gatsby-plugin-llms-txt (community, 1.0.1) ](https://www.npmjs.com/package/gatsby-plugin-llms-txt)
