Documentation

Bundle docs into a package

Bundle docs into a package

Use this path when you publish a library on npm and want version-matched docs available without a network request. Run leadtype generate --bundle at prepack time, include the output in your published files, and every install ships AGENTS.md + per-topic markdown inside node_modules/<your-package>/.

The website is for humans and HTTP agents. The package-bundled docs are for coding agents, IDEs, and CLI tooling that can read files from the installed dependency.

The flow

Rendering diagram...

Why AGENTS.md, not llms.txt?

llms.txt is a website convention — a file at /llms.txt with absolute URLs that an agent fetches over HTTP. Inside an npm tarball it's the wrong shape: every link points at a hosted URL the agent may not be able to reach, and no major coding agent looks for node_modules/<pkg>/llms.txt anyway.

AGENTS.md is the filesystem convention that solves this. Tools like Claude Code, OpenAI Codex, Cursor, GitHub Copilot, Aider, Devin, and others can read AGENTS.md when working with files on disk. An AGENTS.md inside node_modules/<your-package>/ is the right shape for version-matched package docs: relative links work, no network is required, and the content matches the installed version.

leadtype emits both — llms.txt in website mode for HTTP-discoverable agents, and AGENTS.md in --bundle mode for offline filesystem-discoverable agents.

Generate into the package

This writes:

packages/my-package/
AGENTS.md
docs/
index.md
quickstart.md
reference/
cli.md

Every link inside AGENTS.md is a relative path like ./docs/quickstart.md so the file is meaningful both at packages/my-package/AGENTS.md (during local dev) and at node_modules/my-package/AGENTS.md (after install).

--bundle skips llms.txt, llms-full.txt, and the search index — those are website artifacts that don't make sense offline.

Filter to package-specific docs

A monorepo with one shared docs/ and many packages should bundle only the slice each package owns. Use --include (repeatable) and --exclude:

Filters are explicit. If the package needs shared overview pages, list them too. --exclude is applied after --include.

Include in the published tarball

Add AGENTS.md and docs to files and run generation as a build or prepack step:

If you need full control over plugin order or custom validation, run the library APIs directly from a script:

Point your build script at it: "build": "tsup && bun run scripts/generate-docs.ts".

Verify before publishing

npm pack --dry-run should list:

  • AGENTS.md
  • docs/**/*.md

If AGENTS.md is missing, check files in package.json. If .md files are missing, check the --include/--exclude filters.

Tell consuming projects to use the bundle

AGENTS.md inside your tarball is available at node_modules/<your-package>/AGENTS.md after install. Some agents discover dependency docs from tool use or search. The reliable pattern is to point the consuming project at the bundled docs.

Recommend this snippet in your README so consumers add it to their own root AGENTS.md:

This is the same pattern Next.js uses to point agents at node_modules/next/dist/docs/.

When to use this

Use this when agents should understand the package from the installed dependency itself — coding agents that don't have web access, IDE assistants, CLI tools, or air-gapped environments.

Don't use this if your only goal is a public docs website. For that, see Connect a docs site. You can use both — they read the same source MDX, just emit different shapes.

What's next