Standards for writing documentation that AI coding agents can efficiently navigate without overloading their context windows.
Documentation must be modular. Large monolithic documents waste AI context on irrelevant sections. Instead, structure docs as:
- Table of Contents (TOC) - Brief index pointing to topic files (~10-15 lines)
- Topic Files - Focused documents on single subjects (<500 lines)
- Deep Dives - Detailed reference material loaded only when needed
AI coding agents have finite context windows. Every line loaded consumes tokens that could be used for reasoning about your actual task. Poor documentation structure leads to:
- Context pollution - Loading 5000 tokens when 500 would suffice
- Reduced accuracy - Important details buried in irrelevant content
- Slower responses - Processing unnecessary information
Goal: Load only what's relevant to the current task.
1. Load AGENTS.md → find reference to topic area
2. Load topic TOC (e.g., docs/dev/testing/README.md)
3. Identify 1-3 relevant docs from TOC
4. Load only those specific docs
5. Optionally scan with `grep '^#'` before full read
Before loading a full document, scan its structure:
# See all headings in a file
grep '^#' docs/dev/testing/cli-integration-tests.md
# Find specific section
grep -n '## Prerequisites' docs/dev/testing/cli-integration-tests.mdThis helps identify whether a document contains what you need before committing context to it.
Task: "Add integration tests for new deployment list command"
Efficient approach:
- Load
AGENTS.md→ find testing reference - Load
docs/dev/testing/README.md(TOC, ~15 lines) - Identify relevant docs:
cli-integration-tests.md,crud-lifecycle-pattern.md - Load only those 2 docs (~400 lines total)
Inefficient approach:
- Load all 8 testing docs (~2000 lines)
- 75% of content irrelevant to CLI testing
When creating or updating docs, follow these principles:
| Document Type | Target Size | Maximum |
|---|---|---|
| TOC/Index | 10-15 lines | 20 lines |
| Standard doc | 200-300 lines | 500 lines |
| Reference | 300-500 lines | 800 lines |
Use clear, descriptive headings that enable grep scanning:
# Document Title
## Overview <- What this doc covers
## Prerequisites <- What you need first
## Quick Reference <- TL;DR for experienced users
## Detailed Guide <- Step-by-step instructions
## Troubleshooting <- Common problems and solutions
## References <- Links to related docsEach document should cover one specific topic. If you find yourself writing "see also" sections that are essential to understanding the content, consider:
- Consolidating into a single document
- Creating a parent document that loads children
- Adding explicit "load this next" guidance
Never repeat content across files. Instead:
## Prerequisites
See `docs/dev/testing/test-fixtures.md` for test deployment setup.Not:
## Prerequisites
To set up test fixtures, first ensure you have LANGSMITH_API_KEY...
[100 lines of duplicated setup instructions]docs/dev/testing/
├── README.md # TOC only (~15 lines)
├── HIGH_LEVEL_TESTING_GUIDELINES.md # Principles, PR requirements
├── crud-lifecycle-pattern.md # CLI → SDK verification pattern
├── sdk-integration-tests.md # SDK-specific test standards
├── cli-integration-tests.md # CLI-specific test standards
├── devcontainer-feature-tests.md # Infrastructure testing
├── test-fixtures.md # Test deployment management
├── mocking-patterns.md # When/how to use httpmock
├── debugging-tests.md # Common failures, debugging
└── post-mortems/ # Historical case studies
└── NNN-issue-description.md # Format: issue number + description
┌─────────────────────────────────────────────────────────┐
│ AGENTS.md │
│ "For testing docs, see @docs/dev/testing/README.md" │
└─────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────┐
│ docs/dev/testing/README.md │
│ - HIGH_LEVEL_TESTING_GUIDELINES.md - principles │
│ - crud-lifecycle-pattern.md - CLI verification │
│ - sdk-integration-tests.md - SDK tests │
│ - cli-integration-tests.md - CLI tests │
│ ... │
└─────────────────────────────────────────────────────────┘
│
(load 1-3 relevant docs)
│
┌───────────┴───────────┐
▼ ▼
┌───────────────────────┐ ┌───────────────────────┐
│ cli-integration- │ │ crud-lifecycle- │
│ tests.md │ │ pattern.md │
│ (~200 lines) │ │ (~200 lines) │
└───────────────────────┘ └───────────────────────┘
# Testing Guide
[2000 lines covering SDK, CLI, infrastructure, mocking,
debugging, and historical lessons all in one file]Problem: Forces loading irrelevant content. Agent working on CLI tests must load SDK and infrastructure sections.
# File: sdk-integration-tests.md
## Prerequisites
Set LANGSMITH_API_KEY and ensure test deployment exists...
# File: cli-integration-tests.md
## Prerequisites
Set LANGSMITH_API_KEY and ensure test deployment exists...Problem: Updates must happen in multiple places. Content drift creates inconsistency.
Solution: Reference shared prerequisites from a single source:
## Prerequisites
See `test-fixtures.md` for required environment setup.- testing.md - Testing stuff
- utils.md - UtilitiesProblem: Agent cannot determine relevance without loading each file.
Solution: Descriptive one-liners:
- sdk-integration-tests.md - SDK integration test standards and patterns
- mocking-patterns.md - When and how to use httpmock for API mockingHidden Prerequisites
# CLI Integration Tests
Run this command to test:
cargo test --features integration-testsProblem: Missing context about required environment variables causes test failures.
Solution: Always start with prerequisites:
# CLI Integration Tests
## Prerequisites
- `LANGSMITH_API_KEY` environment variable set
- Test deployment created (see `test-fixtures.md`)
## Running Tests
...- TOC files: ≤15 lines
- Standard docs: <500 lines
- Context per task: <3000 tokens (vs >5000 without progressive disclosure)
- Relevance ratio: >80% of loaded content should be relevant to task
When creating documentation:
- TOC exists and is ≤15 lines
- Each doc covers exactly one topic
- No content is duplicated across files
- Headings support
grep '^#'scanning - Prerequisites are explicit, not assumed
- File sizes are within limits
- Clear "when to load" guidance in TOC
- Nielsen Norman Group: Progressive Disclosure - UX principles that inform this approach
- Anthropic Claude Documentation - Context window management
- LangChain llms.txt Pattern - Documentation index for AI consumption