---
title: CLI
description: 'leadtype generate and leadtype lint — flags, exit codes, and JSON output.'
group: reference
lastModified: '2026-05-11T20:02:32-07:00'
lastAuthor: 'github-actions[bot]'
---
# CLI

```bash
leadtype <command> [options]
```

Two commands: `generate` runs the full pipeline, `lint` validates content. Run `leadtype help <command>` for inline usage.

## generate

Convert MDX, then either produce website artifacts (default) or a package bundle (`--bundle`).

```bash
leadtype generate [options]
```

|Flag|Default|Description|
|--|--|--|
|`--src <dir>`|`.`|Repo or root directory containing the docs folder.|
|`--docs-dir <dir>`|`docs`|Docs source folder relative to `--src`. Repeat to merge multiple folders into one generated docs tree.|
|`--out <dir>`|`public`|Output root. The pipeline writes to `<out>/llms.txt` and docs-scoped artifacts under `<out>/docs/*` in site mode, or `<out>/AGENTS.md` and `<out>/docs/*.md` in bundle mode.|
|`--bundle`|off|Bundle mode. Emits `AGENTS.md` and `docs/*.md` for offline agents. Skips `llms.txt`, `llms-full.txt`, search, sitemap, robots, and Agent Readability artifacts.|
|`--base-url <url>`|—|Base URL for canonical artifacts like `sitemap.xml`, `robots.txt`, search metadata, and full-context fallback URLs. Site mode only; ignored in `--bundle`.|
|`--name <name>`|from `docs.config.ts` or `package.json#name`|Product name written into the index file (`llms.txt` or `AGENTS.md`). Overrides config.|
|`--summary <text>`|from `docs.config.ts` or `package.json#description`|Product summary written into the index file. Overrides config.|
|`--include <glob>`|none|Docs-root-relative glob to include. Repeatable. Works in both modes.|
|`--exclude <glob>`|none|Docs-root-relative glob to exclude. Applied after `--include`.|
|`--enrich-git`|off|Add `lastModified` and `lastAuthor` to frontmatter from git history.|
|`--format <fmt>`|`text`|`text` or `json`. JSON prints a single result object on stdout.|
|`--json`|—|Alias for `--format json`.|
|`-h`, `--help`|—|Print usage.|

Exit codes: `0` success, `1` runtime error (docs dir missing, config load error, unknown group, conversion error), `2` CLI usage error.

### Config loading

`leadtype generate` automatically loads `docs.config.ts` from the docs folder (`<src>/<docs-dir>/docs.config.ts`). JavaScript config files also work: `docs.config.js`, `docs.config.mjs`, and `docs.config.cjs`.

```ts
import { defineDocsConfig } from "leadtype";

export default defineDocsConfig({
  product: {
    name: "My Library",
    summary: "A library that does one thing well.",
  },
  groups: [
    { slug: "get-started", title: "Get Started" },
    { slug: "reference", title: "Reference" },
  ],
});
```

The config supplies product metadata, group titles, group order, group descriptions, best starting points, and agent guidance. Pages still declare membership with `group:` in frontmatter. If a page names a group that is not in the loaded config, generation fails.

If no config file exists, the CLI falls back to `package.json` for product metadata and infers groups from the union of `group:` values across the generated pages. Inferred groups are sorted alphabetically and title-cased. Use `docs.config.ts` when order or descriptions matter.

### Multiple source folders

Repeat `--docs-dir` when a project keeps related agent-readable content outside the main docs folder, such as a sibling changelog:

```bash
leadtype generate \
  --src . \
  --docs-dir docs \
  --docs-dir changelog \
  --out public
```

The first source folder is mounted at the generated docs root. Additional source folders are mounted under their folder name, so `changelog/v1.mdx` becomes `public/docs/changelog/v1.md` and `/docs/changelog/v1.md`. `--include` and `--exclude` still match docs-root-relative paths after that merge, for example `--include "changelog/**"`.

Use `<dir>=<url-prefix>` when a source should have its own public URL prefix:

```bash
leadtype generate \
  --src . \
  --docs-dir docs \
  --docs-dir changelog=/changelog \
  --out public
```

That keeps the internal generated copy at `public/docs/changelog/v1.md` for search and runtime helpers, also writes a static markdown mirror at `public/changelog/v1.md`, and emits canonical links such as `/changelog/v1.md` in `llms.txt`, search metadata, sitemap entries, and `agent-readability.json`.

### Bundle mode

```bash
leadtype generate --bundle --src . --out packages/my-package
```

Writes `<out>/AGENTS.md` (relative-link index, agent-discoverable) plus `<out>/docs/*.md` (one per page, group subdirs preserved). Skips every URL-anchored artifact (`llms.txt`, `llms-full.txt`, `search-index.json`, `search-content.json`) — those are website-only. Use this for npm packages that ship docs alongside the published code; see [Bundle docs into a package](/docs/package-docs/bundle).

### JSON output shape

`--json` prints a single object describing what was generated. The shape varies by mode:

```json
{
  "mode": "site",
  "srcDir": "/abs/path/to/repo",
  "docsDir": "/abs/path/to/repo/docs",
  "docsDirs": ["/abs/path/to/repo/docs"],
  "outDir": "/abs/path/to/repo/public",
  "product": { "name": "...", "summary": "..." },
  "groups": [{ "slug": "get-started", "title": "Get Started" }],
  "filters": { "include": [], "exclude": [] },
  "mounts": [{ "pathPrefix": "", "urlPrefix": "/docs" }],
  "files": {
    "llmsTxt": "/abs/path/.../public/llms.txt",
    "docsLlmsTxt": "/abs/path/.../public/docs/llms.txt",
    "llmsFullTxt": "/abs/path/.../public/llms-full.txt",
    "searchIndex": "/abs/path/.../public/docs/search-index.json",
    "searchContent": "/abs/path/.../public/docs/search-content.json",
    "docsSitemapXml": "/abs/path/.../public/docs/sitemap.xml",
    "docsSitemapMd": "/abs/path/.../public/docs/sitemap.md",
    "docsRobotsTxt": "/abs/path/.../public/docs/robots.txt",
    "agentReadabilityManifest": "/abs/path/.../public/docs/agent-readability.json"
  },
  "search": { /* index stats */ }
}
```

The sitemap and robots files are docs-scoped so the host app can merge them with blog, marketing, changelog, or product pages before serving site-root `/sitemap.xml`, `/sitemap.md`, and `/robots.txt`.

In `--bundle` mode, `mode` is `"bundle"` and `files` contains only `agentsMd`. Site-only fields (`search`, `llmsTxt`, sitemap, robots, etc.) are absent.

Errors in JSON mode print `{"error": "...", ...}` to stderr.

### Custom script config

Custom build scripts do not auto-discover config. Import `docs.config.ts` directly and pass the values to the lower-level APIs:

```ts
import { generateLlmsTxt } from "leadtype/llm";
import docsConfig from "../docs/docs.config";

await generateLlmsTxt({
  srcDir: process.cwd(),
  outDir: "public",
  baseUrl: "https://leadtype.dev",
  product: docsConfig.product,
  groups: docsConfig.groups, // titles + order honored
});
```

See [LLM files](/docs/reference/llm) for the rest of the script.

## lint

Validate frontmatter, `meta.json`, and internal links before generation runs.

```bash
leadtype lint [srcDir] [options]
```

|Flag|Default|Description|
|--|--|--|
|`[srcDir]`|`content`|Source docs root. Equivalent to `--src`.|
|`--src <dir>`|—|Same as the positional.|
|`--changelog <dir>`|—|Subdirectory under `srcDir` validated against the changelog schema.|
|`--format <fmt>`|`pretty`|`pretty`, `json`, or `github` (annotation format).|
|`--ignore <glob>`|shared & node\_modules defaults|Glob to skip. Repeatable; passing any `--ignore` overrides defaults.|
|`--warn-unknown`|on|Report unknown frontmatter and meta fields as warnings.|
|`--error-unknown`|off|Report unknown fields as errors.|
|`--max-warnings <n>`|unlimited|Exit non-zero when warning count exceeds `n`.|
|`-h`, `--help`|—|Print usage.|

Exit codes: `0` no errors and warnings within budget, `1` lint errors or budget exceeded, `2` CLI usage error.

Default ignored paths: `**/shared/**`, `**/_shared/**`, `**/_partials/**`, `**/node_modules/**`. Pass `--ignore` to extend (each pass overrides the defaults — re-add what you need).

See [Lint reference](/docs/reference/lint) for the full rule list, schema, and how to plug in custom Valibot schemas via the library API.

## help

Show usage:

```bash
leadtype help            # main usage
leadtype help generate
leadtype help lint
```

## Library entry points

The CLI is a thin wrapper. Every command is also available as a TypeScript API for custom build scripts:

* [`leadtype/convert`](/docs/reference/convert) — `convertAllMdx`, `convertMdxToMarkdown`, `writeMdxFileAsMarkdown`.
* [`leadtype/llm`](/docs/reference/llm) — `generateLlmsTxt`, `generateLLMFullContextFiles`, `generateAgentReadabilityArtifacts`, `generateAgentsMd`, `resolveDocsNavigation`.
* [`leadtype/llm/readability`](/docs/reference/llm#agent-readability-helpers) — JSON-LD, markdown response, frontmatter, and agent request helpers for hosted docs sites.
* [`leadtype/search/node`](/docs/reference/search) — `generateDocsSearchFiles`.
* [`leadtype/lint`](/docs/reference/lint) — `lintDocs`.
* [`leadtype/remark`](/docs/reference/remark) — `defaultRemarkPlugins` and individual plugins.

Use the CLI for the happy path, the library entry points when you need custom plugin order, base URL precedence, or alternate output paths.
