
Documentation drift is the gap that opens up when your docs keep describing behaviour your code no longer has. A function gains a parameter, an endpoint is renamed, a setup step stops being needed, and the README, API reference or docstring carries on as if nothing happened. If your API docs are always out of date, drift is the reason, and it gets worse with every merge that changes code without changing docs.
Most explanations stop at “keep your docs updated”. That treats drift as a culture problem. It’s better treated as an engineering problem: drift is a mismatch between two artefacts in the same repository, and a mismatch can be detected, reported and used to fail a build. The rest of this post covers the kinds of drift you’ll meet, how to catch each one in CI, and how to set things up so it doesn’t build up in the first place.
What Documentation Drift Looks Like
Drift is docs that describe behaviour the code no longer has. It isn’t missing documentation; it’s documentation that was once right and is now wrong, which is worse, because readers trust it. Here’s the smallest possible example. The README says:
## Sending an invoice
```python
send_invoice(customer_id, amount)
```
Sends a single-line invoice in USD.
Meanwhile, three pull requests later, the code looks like this:
def send_invoice(customer_id: str, line_items: list[LineItem], *, currency: str) -> InvoiceResult:
...
The amount argument is gone, currency is now required, and the function returns a result object instead of nothing. Every PR that got it here was reviewed and passed its tests. None of them touched the README, and nothing in the pipeline noticed.
The Four Kinds of Documentation Drift
Drift doesn’t look the same everywhere, and each kind needs a different check. It helps to split it into four categories.
1. API Reference Drift
The reference docs for a library or service list parameters, types, endpoints or response fields that no longer match the implementation. This is the outdated API documentation problem most people search for, and it’s the most expensive kind, because API consumers are often outside your team and can’t read the source to check.
2. README and Setup Step Drift
Install instructions, environment variables, commands and prerequisites that used to work. A renamed script in package.json, a new required environment variable or a bumped runtime version quietly breaks the first thing a new developer tries.
3. Code Comment and Docstring Drift
Comments sit right next to the code, so you’d expect them to stay current. They often don’t. A docstring that says “returns None if the user is not found” survives a refactor that changed the function to raise an exception, and the editor shows the stale version in every tooltip.
4. Architecture Diagram and Decision Record Drift
Diagrams, design docs and architecture decision records describe how the system fits together. They drift slowly: a queue gets replaced, a service gets split, a decision gets reversed without a new record. Nothing breaks immediately, which is why this kind tends to be discovered during an incident.

Why Documentation Drift Happens
The causes are structural. Docs often live somewhere other than the code (a wiki, a separate repo, a docs site), so changing one doesn’t prompt changing the other. Code review checks the diff in front of the reviewer, and the stale paragraph isn’t in the diff. Nobody owns the docs, so nobody is responsible for noticing. And anything that has to be regenerated by hand gets regenerated rarely. I’ve made the longer argument in why most developer documentation fails and how to fix it; the point here is that every one of those causes can be addressed with tooling.
How to Detect Documentation Drift in CI
Detection is about turning “the docs might be stale” into a signal a machine can raise. You won’t catch every sentence that’s gone wrong, but you can catch the changes most likely to cause drift and the docs most likely to be stale.
Flag PRs That Change Public Signatures Without Touching Docs
The simplest useful check: if a pull request changes files that define your public surface, it should also change something under docs/ or the README. If it doesn’t, fail the check and make the author either update the docs or say explicitly that no update is needed.
name: docs-drift
on: pull_request
jobs:
require-docs:
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'no-docs-needed') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Fail if public API changed without docs
run: |
CHANGED=$(git diff --name-only "origin/${{ github.base_ref }}"...HEAD)
API=$(echo "$CHANGED" | grep -E '^src/api/|^openapi\.ya?ml$|\.d\.ts$' || true)
DOCS=$(echo "$CHANGED" | grep -E '^docs/|README\.md$' || true)
if [ -n "$API" ] && [ -z "$DOCS" ]; then
echo "::error::Public API files changed without a docs update:"
echo "$API"
exit 1
fi
The path patterns are the part you’ll tune. Point them at whatever defines your public contract: route handlers, exported modules, an OpenAPI file, generated type declarations. The no-docs-needed label is the escape hatch for internal refactors. It matters, because a check that can’t be bypassed for legitimate reasons gets disabled.
File paths are a blunt instrument. If you want to react to actual signature changes rather than any edit in a directory, compare a generated API summary between the base branch and the PR. For TypeScript, Microsoft’s API Extractor produces an API report file you can commit and diff; for other languages, dumping the exported symbols and their signatures to a text file does the same job.
Doc Tests and Executable Examples
The surest way to stop examples drifting is to run them. Python’s doctest executes the examples in docstrings, Rust runs code blocks in doc comments as part of cargo test, and Go verifies the output of Example functions during go test. For README snippets, extract the code blocks and run them in CI against the current build. In the invoice example above, a runnable README snippet would have failed the moment amount was removed.
Contract Tests Against an OpenAPI Spec
If your API reference is generated from or published as an OpenAPI spec, test the running service against that spec. Contract-testing tools such as Schemathesis send requests built from the spec and report responses that don’t match the documented schema. That turns “the docs say this field exists” into an assertion that runs on every build.
Link and Anchor Checkers
Broken links are the cheapest drift to detect. A link checker such as lychee or markdown-link-check, run over your docs on every PR, catches links to deleted pages, renamed files and headings that no longer exist. Anchor checks matter most: a renamed heading breaks every deep link to it without producing a 404.
“Last Reviewed” Metadata and a Staleness Report
Some docs, particularly architecture diagrams and decision records, can’t be tested. For those, add a last_reviewed date and an owner to each page’s front matter, and run a scheduled job that lists every page whose review date is older than your threshold. Don’t fail builds on this one; post the report to the team channel or open an issue for each owner. The goal is to make staleness visible on a schedule instead of during an outage.

How to Prevent Documentation Drift
Detection catches drift after it’s written. Prevention changes the workflow so less of it gets written at all.
Docs as Code, in the Same PR
Keep the docs in the same repository as the code they describe, written in plain text formats, and expect them to change in the same pull request as the behaviour they document. Once docs are in the diff, reviewers can see whether they match the change, and the CI check above has something to look for.
CODEOWNERS for Docs
A CODEOWNERS file gives every docs directory a named reviewer, which solves the “nobody owns it” problem directly. Pair it with ownership of the code paths: if the team that owns src/billing/ also owns docs/billing/, they get asked to review both, and they’re the people best placed to spot a mismatch.
Generate Reference Docs From Source on Every Commit
Reference documentation that is generated can’t drift from the code it’s generated from, as long as generation runs automatically. Run your generator in CI on every merge, publish the output, and stop hand-editing anything that a tool can produce. That frees people to spend their writing time on guides, explanations and decisions, the parts a generator can’t write.
Which generator you use depends on the stack. Language-native tools cover a lot of ground; SyntaxScribe, which I built to generate documentation from source code, is one way to do it. The same principle applies below the application layer: if you generate database documentation from the schema or your data models, as in this walkthrough on generating Markdown documentation from a Sequelize model with Monstarillo, your table and column docs update whenever a migration lands instead of whenever someone remembers.
A Five-Point Documentation Drift Checklist
- Docs live in the repo and change in the same pull request as the code they describe.
- A CI check fails when public API files change without a docs change, with a labelled escape hatch for internal refactors.
- Examples execute: doc tests, runnable README snippets and contract tests against your OpenAPI spec run on every build.
- Reference docs are generated from source and schema on every merge, never edited by hand.
- Untestable docs have an owner in
CODEOWNERSand alast_revieweddate, with a scheduled staleness report.
None of this needs a big documentation initiative. Start with the PR check and a link checker this week, add doc tests where you already have examples, and documentation drift stops being something you find out about from a confused user.
