Generate LLM-friendly llms.txt files from markdown and MDX content files
npm install get-llms-txt
Generate llms.txt files and markdown versions of all content files for LLM consumption, following the llms.txt specification. Optimized for Next.js projects using MDX/MD files, but works with any project that uses markdown or MDX content.
[![NPM version][npm-image]][npm-url]
![npm-typescript]
[![License][github-license]][github-license-url]
- š Markdown/MDX scanning - Recursively finds all .mdx and .md files in your content directory
- š Generate llms.txt - High-level, markdown-like index of your project with categorized file lists
- š Markdown conversion - Converts MDX files to plain markdown, removing JSX components and metadata
- šļø Configurable - Customize content directory, output directory, base URL, and project metadata
- š§° CLI + API - Use as a CLI tool or call programmatically in your own scripts
- ā” Fast and efficient - Only processes content files, ignores node_modules, .next, and out directories
Install the package:
``sh`
npm install --save-dev get-llms-txt
or
`sh`
yarn add -D get-llms-txt
or
`sh`
pnpm add -D get-llms-txt
Run the CLI:
`sh`
npx get-llms-txt
By default, this will:
- Scan ./content directory for .mdx and .md filesllms.txt
- Generate in ./out (if exists) or ./public
- Create plain markdown versions in directory
Basic usage for MD/MDX files:
The tool processes any .md or .mdx files in your content directory:
- Extracts metadata (title, description, tags)
- Converts MDX to plain markdown (removes JSX components)
- Generates categorized llms.txt index file.md
- Creates individual files for each content file
`sh`
npx get-llms-txt [options]
Options:
- -c, --content-dir
- Content directory to scan (default: ./content)
- -o, --output-dir - Output directory for llms.txt and md files (default: ./out if exists, otherwise ./public)
- -u, --base-url - Base URL for links in llms.txt (default: empty)
- -n, --project-name - Project name for llms.txt (default: "Personal Website & Blog")
- -d, --project-description - Project description (default: auto-generated)
- -h, --help - Show help message$3
`sh
Use default settings
npx get-llms-txtSpecify custom directories
npx get-llms-txt --content-dir ./content --output-dir ./outWith base URL for production
npx get-llms-txt --base-url https://example.com --output-dir ./outCustom project name and description
npx get-llms-txt --project-name "My Blog" --project-description "Technical blog about software development"
`$3
`typescript
import {generateLlmsFiles} from 'get-llms-txt';await generateLlmsFiles({
contentDir: './content',
outputDir: './out',
baseUrl: 'https://example.com',
projectName: 'My Next.js Project',
projectDescription: 'A collection of technical content',
});
`š ļø Installation
`sh
npm install --save-dev get-llms-txt
`API
$3
Main function to generate llms.txt files.
Parameters:
-
options.contentDir (string) - Content directory to scan
- options.outputDir (string) - Output directory for llms.txt and md files
- options.baseUrl? (string) - Base URL for links in llms.txt
- options.projectName? (string) - Project name for llms.txt
- options.projectDescription? (string) - Project description$3
Process an MDX file and extract metadata and content.
$3
Process a Markdown file and extract metadata and content.
$3
Extract title from file metadata, first H1, or filename.
$3
Extract description from metadata or first paragraph.
What It Does
1. Scans Content Directory: Recursively finds all
.mdx and .md files in the content directory
2. Extracts Metadata: Extracts title, description, and other metadata from MDX files
3. Converts to Markdown:
- Removes MDX metadata exports
- Strips JSX components
- Converts to plain markdown
4. Generates Individual .md Files: Creates markdown versions in directory
5. Generates llms.txt: Creates llms.txt file in the output directory with:
- Project name and description
- Content structure overview
- Categorized file lists with linksOutput Structure
`
/
āāā llms.txt
āāā md/
āāā blog/
ā āāā post1.md
ā āāā ...
āāā apps/
ā āāā app1.md
ā āāā ...
āāā research/
āāā ...
`File Processing
$3
The script supports two common metadata formats used in Next.js projects:
1. YAML Frontmatter (most common):
`mdx
---
title: My Post
description: A great post
tags: [blog, tech]
--- # My Post
Content here...
`2. Export const metadata (Next.js MDX format):
`mdx
export const metadata = {
title: 'My Post',
description: 'A great post',
tags: ['blog', 'tech'],
}; # My Post
Content here...
`The script automatically detects and handles both formats. It also:
- Removes React/JSX components
- Strips import statements
- Converts to plain markdown
- Preserves markdown structure
$3
- Extracts YAML frontmatter (if present)
- Preserves markdown content as-is
Integration with Build Process
For Next.js static export (or any static site generator), add to your build script:
`json
{
"scripts": {
"build": "next build && npx get-llms-txt --output-dir ./out",
"deploy:prod": "next build && npx get-llms-txt --output-dir ./out --base-url https://example.com && firebase deploy --only hosting"
}
}
`Compatibility
ā
Optimized for Next.js projects using MDX/MD files, but also works with:
- ā
Any static site generator (Gatsby, Astro, etc.)
- ā
Documentation sites (Docusaurus, VitePress, etc.)
- ā
Any project with markdown/MDX content files
Supported formats:
- ā
YAML frontmatter (most common)
- ā
export const metadata (Next.js MDX format)
- ā
Mixed formats
- ā
Files with no metadata (falls back to filename/H1 extraction)
- ā
Any directory structure (recursively scans)
- ā
Locale suffixes (.en, .ru, etc.) are handled automaticallyRequirements:
- Node.js 22+
- MDX or MD files in a content directory (configurable)
- TypeScript support (for programmatic usage)
URL Generation
- Locale suffixes (
.en, .ru) are removed from filenames
- All files are converted to .md` extensionMIT
[package-name]: get-llms-txt
[npm-url]: https://www.npmjs.com/package/get-llms-txt
[npm-image]: https://img.shields.io/npm/v/get-llms-txt
[github-license]: https://img.shields.io/github/license/romankurnovskii/get-llms-txt
[github-license-url]: https://github.com/romankurnovskii/get-llms-txt/blob/main/LICENSE
[npm-typescript]: https://img.shields.io/npm/types/get-llms-txt
[build-status]: https://github.com/romankurnovskii/get-llms-txt/workflows/CI/badge.svg
[build-status-url]: https://github.com/romankurnovskii/get-llms-txt
[install-size]: https://packagephobia.com/badge?p=get-llms-txt
[install-size-url]: https://packagephobia.com/result?p=get-llms-txt