An mdBook 0.5 renderer that follows the llms.txt convention. It writes:
llms.txt: an index of every chapter, grouped by SUMMARY.md partsllms-full.txt: every chapter in reading order, in one file<chapter>.md: each chapter's Markdown at the path its HTML would use
It also includes mdbook-strip-frontmatter, a preprocessor that keeps YAML
frontmatter out of the HTML pages.
Output comes from mdBook's preprocessed book, so {{#include}} and friends are
already expanded.
cargo install --locked mdbook-llmsFrom a local checkout, use cargo install --path . instead.
Prebuilt binaries for Linux, macOS and Windows are attached to each
GitHub Release as
mdbook-llms-<tag>-<target>.tar.gz (.zip on Windows), each with a .sha256
file. The archive holds both binaries.
To generate only the llms files, list only this output. mdBook then skips HTML,
CSS and JS completely, and the files land directly in book/:
[output.llms]
site-url = "https://example.com/my-book"To publish alongside the site, keep both. The files go into book/html/, next
to the HTML:
[preprocessor.strip-frontmatter]
[output.html]
site-url = "/my-book/"
[output.llms]To skip HTML for one build without touching book.toml:
MDBOOK_OUTPUT='{"llms":{}}' mdbook buildAll go under [output.llms].
| Key | Default | Effect |
|---|---|---|
site-url |
output.html.site-url |
Prefix for links. Without either, links are relative to the output root. |
index |
true |
Write llms.txt. |
full |
true |
Write llms-full.txt. |
pages |
true |
Write per-chapter .md files. When false, links point at .html. |
merge-into-html |
true |
When HTML also runs, write into its directory rather than book/llms/. |
discovery-links |
true |
When merged into the HTML output, add <link rel="alternate" type="text/markdown"> and <link rel="describedby"> to each HTML page, as llms.txt v2 recommends. |
sizes |
false |
End each llms.txt entry with its file's size, as (about 1.4k tokens): a quarter of its bytes, rounded up to the hundred below a thousand and to a tenth of a thousand above. |
preamble |
none | A file under src/ whose text goes after the title and description of llms.txt and llms-full.txt. |
optional-files |
none | Files that are not chapters, listed under ## Optional at the end of llms.txt (see below). |
With pages = false, the links only resolve if the HTML site is published too.
The llms.txt convention ends the index with an
## Optional section for what a reader may skip. List each file under
[[output.llms.optional-files]]:
[[output.llms.optional-files]]
path = "llms-full.txt"
description = "Every chapter in one file"
[[output.llms.optional-files]]
path = "data/model.json"
title = "model.json"
description = "The whole model as JSON"path is under src/, and the file is copied to the same path in the output;
llms-full.txt is the one exception, since the renderer writes it. title
defaults to the file name. With sizes = true, each entry shows its size too.
A listed file that does not exist fails the build.
mdBook does not understand frontmatter, so its HTML renderer would print the block on the page. This crate also installs a preprocessor that removes it. Add this whenever HTML is enabled:
[preprocessor.strip-frontmatter]It steps aside for the llms renderer, which needs to read the block, so no
renderers setting is required. For llms-only books you can leave it out.
A description adds text to that chapter's llms.txt entry. Other keys, such
as tags, are allowed and removed from all output:
---
description: How to install the CLI
tags:
- setup
---
# InstallA block counts as frontmatter only if it opens the file with ---, closes with
---, and every line in between looks like YAML. A chapter that simply starts
with a horizontal rule is left alone.
- Links between chapters are rewritten so they work from
llms-full.txt, andREADME.mdlinks follow the chapter to its publishedindex.md. - Draft chapters have no page, so they are skipped and their children move up.
- Standalone builds empty the output directory first, as the HTML renderer does.
- Code lines mdBook hides in HTML (
#in Rust,hidelinesprefixes elsewhere) are kept in the llms output with the marker removed, so code stays complete. - When merged into the HTML output, each HTML page gets
<link>tags pointing at its.mdfile and atllms.txt, includingindex.htmlandprint.html. Setdiscovery-links = falseto leave the HTML untouched. - Relative links in
llms.txtand the per-chapter.mdfiles are checked after the build, and each missing target prints awarning: mdbook-llms: broken link in <file>: <link>line. Anchors and external URLs are not checked, and the build does not fail.
- Requires mdBook 0.5.
- mdBook publishes a
README.mdchapter asindex.htmlbut does not rewrite links to it, so they point at a missingREADME.htmlin the HTML site. Only the llms output fixes them.
skills/mdbook-llms/SKILL.md is an agent skill
for setting up and checking this renderer in a book. To load it in this
repository, link it into .claude/skills/ (the link is gitignored):
mkdir -p .claude/skills
ln -s ../../skills/mdbook-llms .claude/skills/mdbook-llmsTo use it elsewhere, copy or link the folder into that project's
.claude/skills/.