Skip to main content
Doctor can generate documentation optimized for LLM consumption, following the llms.txt standard.

Overview

Two files are generated:
FilePurposeTypical Size
llms.txtIndex with links and descriptions~30 KB
llms-full.txtComplete docs concatenated~1 MB (~300k tokens)

Output Directories

Understanding where files are generated is important:
CommandOutput LocationPurpose
gen:llmsdocs-mkdocs/Local generation
gen:llms --deploydocs-mkdocs/ + websiteLocal + deploy to website
gen:mkdocs --with-llmsdocs-mkdocs/Generate MkDocs then LLM docs

Directory Structure

instructor-php/
├── docs-mkdocs/              # MkDocs output (source for LLM docs)
│   ├── llms.txt              # Generated here by gen:llms
│   ├── llms-full.txt         # Generated here by gen:llms
│   ├── index.md
│   ├── packages/
│   └── cookbook/

└── ../instructor-www/public/  # Website (deployment target)
    ├── llms.txt              # Deployed here with --deploy
    ├── llms-full.txt         # Deployed here with --deploy
    └── docs/                 # Full docs deployed here
// @doctest id="9e36"

Commands

Basic Generation

# Generate LLM docs to docs-mkdocs/
composer docs gen:llms

# Generate only the index file
composer docs gen:llms --index-only

# Generate only the full file
composer docs gen:llms --full-only
# @doctest id="ad6a"

With Deployment

# Generate and deploy to website (configured in config/docs.yaml)
composer docs gen:llms --deploy

# Deploy to custom target
composer docs gen:llms --deploy --target=/path/to/website/public
# @doctest id="98ce"

Combined with MkDocs

# Generate MkDocs first, then LLM docs (to docs-mkdocs/)
composer docs gen:mkdocs --with-llms
# @doctest id="be07"
Note: --with-llms does NOT deploy to the website. It only generates files in docs-mkdocs/.

Typical Workflows

Development: Generate Locally

# Regenerate MkDocs and LLM docs
composer docs gen:mkdocs --with-llms

# Files are now in docs-mkdocs/
ls docs-mkdocs/llms*.txt
# @doctest id="4277"

Production: Generate and Deploy

# Option 1: Two-step process
composer docs gen:mkdocs --with-llms
composer docs gen:llms --deploy

# Option 2: Generate fresh and deploy
composer docs gen:llms --deploy
# @doctest id="4d76"

CI/CD Pipeline

# In your deployment script:
composer docs gen:mkdocs --with-llms
composer docs gen:llms --deploy --target=/var/www/html/public
# @doctest id="a221"

Output Files

llms.txt

A markdown index file with links to all documentation:
# Instructor for PHP

> Structured data extraction in PHP, powered by LLMs.

## Main
- [Overview](index)
- [Getting Started](getting-started)
- [Features](features)

## Packages
- [Overview](packages/index)

### Instructor
- [Introduction](packages/instructor/introduction)
- [Quickstart](packages/instructor/quickstart)
...

## Cookbook
- [Introduction](cookbook/introduction)
...
// @doctest id="2a28"

llms-full.txt

All documentation concatenated into a single file with clear separators:
# Instructor for PHP

> Structured data extraction in PHP, powered by LLMs.

This file contains the complete documentation...

================================================================================
FILE: index.md
================================================================================

# Welcome

This is the home page...

================================================================================
FILE: getting-started.md
================================================================================

# Getting Started
...
// @doctest id="ba68"
Features:
  • YAML frontmatter is stripped
  • Files are ordered according to navigation structure
  • Clear separators between files
  • Token estimate included in generation output
  • Release notes excluded by default (configurable)

Configuration

Configure LLM docs in config/docs.yaml:
llms:
  # Enable/disable generation
  enabled: true

  # Output filenames
  index_file: 'llms.txt'
  full_file: 'llms-full.txt'

  # Project description for headers
  project_description: 'Structured data extraction in PHP, powered by LLMs.'

  # Sections to exclude from llms-full.txt (saves tokens)
  exclude_sections:
    - 'release-notes/'

  # Deployment settings
  deploy:
    # Target directory (relative to project root)
    target: '../instructor-www/public'
    # Subfolder for markdown files (llms.txt goes to target root)
    docs_folder: 'docs'
# @doctest id="7f3c"

Configuration Options

OptionDefaultDescription
enabledtrueEnable/disable LLM docs generation
index_filellms.txtFilename for the index
full_filellms-full.txtFilename for concatenated docs
project_description(see config)Description in file headers
exclude_sections['release-notes/']Patterns to exclude from full file
deploy.target''Deployment target directory
deploy.docs_folderdocsSubfolder for markdown files

Deployment Details

When using --deploy, files are copied to the website:
instructor-www/public/          # deploy.target
├── llms.txt                    # → https://instructorphp.com/llms.txt
├── llms-full.txt               # → https://instructorphp.com/llms-full.txt
└── docs/                       # deploy.docs_folder
    ├── index.md
    ├── getting-started.md
    ├── packages/
    │   ├── instructor/
    │   └── polyglot/
    └── cookbook/
// @doctest id="ac28"
The deployment:
  1. Copies llms.txt and llms-full.txt to the target root
  2. Copies all markdown files to docs/ subfolder
  3. Preserves directory structure

API

LlmsDocsGenerator

use Cognesy\Doctor\Docgen\LlmsDocsGenerator;

$generator = new LlmsDocsGenerator(
    projectName: 'My Project',
    projectDescription: 'Project description for headers',
);

// Generate index file
$result = $generator->generateIndex($navigation, '/path/to/llms.txt');

// Generate full concatenated file
$result = $generator->generateFull(
    $navigation,
    '/path/to/source',
    '/path/to/llms-full.txt',
    excludePatterns: ['release-notes/'],
);
// @doctest id="9101"

GenerationResult

Both methods return a GenerationResult with:
$result->isSuccess();        // bool
$result->filesProcessed;     // int
$result->message;            // string (includes file size and token estimate)
$result->errors;             // array
// @doctest id="a8af"

Command Reference

gen:llms

Usage:
  gen:llms [options]

Options:
  -d, --deploy          Deploy generated files to website
  -t, --target=TARGET   Custom deployment target path (overrides config)
  -i, --index-only      Generate only llms.txt index file
  -f, --full-only       Generate only llms-full.txt file
// @doctest id="4f46"

gen:mkdocs —with-llms

Usage:
  gen:mkdocs [options]

Options:
  -p, --packages-only   Generate only package documentation
  -e, --examples-only   Generate only example documentation
  -l, --with-llms       Also generate LLM-friendly documentation
// @doctest id="ae4d"