Skip to content
jthegunner_

← All projects

doc-drift-checker

Find the README sections that went stale when the code changed. Single Go binary, git-based, few false positives.

ActiveCI passing

★ 0 · Last push 23 Nov 2026

Open on GitHub

Installation

go install github.com/JtheGunner/doc-drift-checker/cmd/doc-drift-checker@latest

Releases

  1. v0.3.0

    Show changes

    Changelog

    • 6acfe53917499106e3bd05cf7c47932be65a392d Merge pull request #45 from JtheGunner/chore/DDC-40-fix-mappings-example
    • 18f523b734afb11397bbff80f0d79b8b8d68b881 Merge pull request #46 from JtheGunner/chore/DDC-42-ignore-release-docs-by-default

    See CHANGELOG.md for the curated release notes.

  2. v0.2.3

    Show changes

    Changelog

    • 0b49441c2c4422e7bdffa25e4e08b6aeb369efcf Merge pull request #42 from JtheGunner/chore/DDC-38-report-unmatched-mapping-keys
    • 59aad74690396f208b19fdac4b2aa7e14676a0c9 Merge pull request #43 from JtheGunner/chore/DDC-39-mapping-guide
    • 77ca12a7995ee54c3b27f618c2ae619958a9c668 Merge pull request #44 from JtheGunner/chore/changelog-0-2-3
    • fab106e785d3900cd7446827dfd5dcc8dd7019f0 feat: report mappings keys that match no section in links

    See CHANGELOG.md for the curated release notes.

  3. v0.2.2

    Show changes

    Changelog

    • b4a64b851e794e8810159092e2880427d8265e50 Merge pull request #35 from JtheGunner/fix/DDC-32-release-skip-moving-tag
    • e905e40b3960ef60408c96ed93d7cbdcbd2f5a30 Merge pull request #36 from JtheGunner/fix/DDC-33-skip-doc-to-doc-implicit-links
    • 7b8d14c1d0a719d89d77d6e8986f701daf9742f2 Merge pull request #37 from JtheGunner/chore/DDC-34-ci-macos-and-race-detector
    • 2fbc4d1613e251c3fe482b24fc010ba5e9588ab7 Merge pull request #38 from JtheGunner/chore/DDC-35-lower-minimal-go-version
    • 0593ce7b0e7b44c987c2e2733ef6a867e8442b1a Merge pull request #39 from JtheGunner/chore/DDC-36-security-policy-and-ci-badge
    • ed2d495c4b325943734bece18a04ceb265d81acc Merge pull request #40 from JtheGunner/chore/DDC-37-dogfood-config-and-ci-check
    • 07bddb75c06851e8175b79989e5494c6d0d76283 Merge pull request #41 from JtheGunner/chore/changelog-0-2-2
    • 602e8bf273e8984745611a00776e3efe43442c7b fix: skip implicit doc-to-doc references when resolving links
    • d28fe119416157cdc930e4caca8b9586c3d6a9bc fix: skip release workflow for the moving major tag

    See CHANGELOG.md for the curated release notes.

  4. v0.2.1

    Show changes

    Changelog

    • 1b26ddb0a65e2379f1ca89a53617048f67a1cbe0 Merge pull request #32 from JtheGunner/chore/DDC-28-shared-clean-helper-for-text-output
    • 519ea3083e02c476842f16a37b12eca54df378e8 Merge pull request #33 from JtheGunner/chore/DDC-29-make-init-fifo-test-portable
    • 44435b20e888cb17ec8ed1ef596b544b29eaf7d5 Merge pull request #34 from JtheGunner/chore/changelog-0-2-1
    • 07bccbb2b009ffea3498f8a6dd6f777108f9f91f refactor: share text neutralisation in internal/textsafe

    See CHANGELOG.md for the curated release notes.

  5. v0.2.0

    Show changes

    Changelog

    • 36cb5cee87c5156281f2db6c723ef98592a63261 Merge pull request #25 from JtheGunner/chore/DDC-23-sanitize-text-reporter-control-chars
    • 5fe47ea3ca90a9150fe63a8a71fb92568709554e Merge pull request #26 from JtheGunner/chore/DDC-25-report-sections-over-10-files-in-init
    • 2b8a42c7fed95d6ce809a1ff7b83d42e01659a12 Merge pull request #27 from JtheGunner/chore/DDC-26-writelock-uses-write-file-atomic
    • a6f0a0bd7cbc827d8845072ee0beac579cfeebe1 Merge pull request #28 from JtheGunner/chore/DDC-22-wire-mode-default-into-check
    • d0c04b61a335db5e0a6c1e2683717dd289a46609 Merge pull request #29 from JtheGunner/chore/DDC-24-test-init-symlink-and-special-docs
    • a3a37bbd56b86af58dde80e401d4edf945b17209 Merge pull request #30 from JtheGunner/chore/DDC-27-add-missing-changelog-entries
    • 61c64d0ea672924196a411002c2a8088ca94742a Merge pull request #31 from JtheGunner/chore/DDC-30-set-v0-2-0-changelog-version
    • d0a5465cb34cc9f2f7ac9b65adf1a4e93aa43d36 Merge remote-tracking branch 'origin/main' into chore/DDC-26-writelock-uses-write-file-atomic
    • fa55b59b0147b28afd2a759bde9aad1f3185af35 feat: apply mode.default in check and explain when --base is absent
    • 454f9894dbe73259c672d9b20b7b3501fcde8b73 feat: list init sections with more than 10 files as skipped
    • a188c56e897e1107897f1c8e0c3717acb7f24d89 fix: neutralise repository text in check and links text output
    • 50d80c518deefdb627264ad75eeb263c097cef12 refactor: write the lockfile through the shared writeFileAtomic

    See CHANGELOG.md for the curated release notes.

  6. v0.1.0

    Show changes

    Changelog

    • 4a01bf613b63b094528008e3e118042bbed79ffb DDC-10: Add Go symbol relevance via SymbolAnalyzer (#11)
    • 73e807048d41c7f63a8e5465664ef3fcc156d915 DDC-11: Add severity and broken-reference detection (#12)
    • 7731b859e43ba09c0c66fb9897aa13ae12c5efd5 DDC-12: Add ack command and lockfile (#13)
    • 7a0a73d7a8cb684bddd00e806fd8c31ad3a7a5e5 DDC-13: Add explain command (#14)
    • dc81f812006075453f1f0329c46b73461eee0313 DDC-15: Add CI integrations (SARIF, GitHub annotations, Action, pre-commit) (#16)
    • bdd39c64c28dd7d9b0bfe08d418407ebfdd8d6ae DDC-16: Add README, license, changelog and release automation (#17)
    • d6065fd723b81534d1d8b68accf9926f498181af DDC-17: Harden glob matching and symlink reads (#7)
    • b37238a90c8a7cca6f019f841dfefb15033b4ebb DDC-2: Load and validate .docdrift.yaml (#2)
    • 8c2c0ad00c4062d83dd0a9ba0b0e4dfb91f078d0 DDC-4: Extract code references from sections (#5)
    • 7de54dd39040508de7bc0cdc5ba311806c628076 DDC-6: Map sections to code and add the links command (#6)
    • 57de53a8cdadfe568c63908bf8b47738a894288b DDC-7: Add diff-mode drift detection with reporters and exit codes (#8)
    • 9a37b80dadebfac3cffbbf2a4336fd2d0b18487c DDC-8: Add path-based relevance filters (#9)
    • eb3d3f5251b01976b6f690bc9c12e4a1a5323bac DDC-9: Add history mode via git blame (#10)
    • 1501519a91e2ca5ca633ab1b815cabc4ae0ba14c Initial commit
    • c521ac040a56244a0b2de1ceff8d553bd9ce8327 feat: add git CLI wrapper and test repo builder (#4)
    • 8b33ed8968acddc6fd191ae725c7a122bda2494e feat: add init command for a starter config and annotation suggestions (#15)
    • 78605508eb34022ecfc7c171b70236d904674dbc feat: split markdown into sections with exact line ranges (#3)

    See CHANGELOG.md for the curated release notes.

README

🧭 doc-drift-checker

Find the README passages that went stale when the code changed.

code changes  →  linked README section did not  →  drift report


🎯 What it is

Documentation rots quietly. Someone renames a flag, changes a function signature or moves a file, and the README paragraph that describes it keeps saying the old thing. Nobody notices, because nothing fails.

doc-drift-checker links each section of your Markdown documentation to the code files it describes. It then reports every section whose linked code changed while the section's own text did not. It is a single Go binary that reads your git history; it needs no server and no network access.

The main design goal is few false positives. Changes that cannot affect documentation (tests, generated code, formatting, unexported Go code) are filtered out before anything is reported.

  README section ──links──▶ code files
        │                       │
   unchanged?              changed?
        └──────── both ─────────┘
                   ▼
             drift report

⚙️ How it works

Diff mode (check --base <ref>) compares base...HEAD. A section drifts when a linked file changed and no line of the section itself changed. This is the mode for pull requests: it needs the merge base, so a full clone (not a shallow one) is required.

History mode (check without --base) needs no base branch, which suits a local check. A section drifts when the newest commit of a linked file is strictly newer than the newest commit that touched the section's own lines (via git blame). Dates are committer times.

Sections are linked to code in three ways, see Linking sections to code. Whatever the mode, you can silence a reviewed section with ack.

Note
History mode is date based and has limits: squash merges stamp all touched lines with the merge time, rewritten history changes dates, and formatting-only commits distort them. See Known limits.


📦 Installation

Pick one.

With Go (Go 1.25 or newer is required):

go install github.com/JtheGunner/doc-drift-checker/cmd/doc-drift-checker@latest

From a release: download the archive for your platform (macOS or Linux, amd64 or arm64) from the GitHub Releases page, verify it against the published checksums.txt, unpack it and put doc-drift-checker on your PATH.

From source:

git clone https://github.com/JtheGunner/doc-drift-checker.git
cd doc-drift-checker
go build -o doc-drift-checker ./cmd/doc-drift-checker

doc-drift-checker --version prints the installed version (dev for a plain source build).

git must be installed and available on the PATH; the tool shells out to it.

Note
A Homebrew tap is planned but does not exist yet. Until it does, use go install or the release archives.


🚀 Quick start

Run these inside a git repository that has a README.md:

doc-drift-checker init            # write a starter .docdrift.yaml and suggest annotations
doc-drift-checker links           # see which code each section is linked to
doc-drift-checker check --base origin/main

Example links output, for a README whose "Usage" section mentions cmd/main.go:

README.md
  Demo (lines 1-9)
    unmapped
  Usage (lines 3-5)
    cmd/main.go [implicit]
  License (lines 7-9)
    unmapped

After a branch changed the exported API of cmd/main.go and renamed the --verbose flag that the section mentions, check reports:

[high] Usage
  README.md:3
  changed code:
    cmd/main.go
  broken references:
    flag --verbose (README.md:5)

and exits with code 1.


🧰 Commands

Command Purpose
🔗 links Show which code files each section describes
🔍 check Report sections whose code changed while the section did not
✅ ack Confirm that a section is still correct
💬 explain Explain why a section is, or is not, reported
✨ init Create a starter config and suggest annotations

Global flags: -h, --help and -v, --version. Run doc-drift-checker <command> --help for the full text of each command. The commands operate on the git repository that contains the current directory and give the same result from any subdirectory.

doc-drift-checker links [--json]

Prints every section of the configured documentation files with its linked code files and the origin of each link (annotation, config, implicit), plus references that match no tracked file and sections without links. --json prints the mapping as JSON. Exit code 0 on success, 2 on error.

check

doc-drift-checker check [--base <ref>] [--format text|json|sarif|github] \
  [--min-severity low|high] [--warn-only] [--ignore-revs-file <path>]
Flag Meaning
--base <ref> Diff mode: compare <ref>...HEAD. Wins over mode.default. Without it, mode.default decides (history mode unless it is set to diff, which is a usage error).
--format text (default), json, sarif (SARIF 2.1.0 for code scanning) or github (workflow annotations).
--min-severity Lowest severity that exits 1: low or high. Default: severity.fail-on from the config, else low. All drifts are printed regardless.
--warn-only Exit 0 even when drift is found. Errors still exit 2.
--ignore-revs-file <path> History mode only: file of commit hashes to skip when dating, in git's blame.ignoreRevsFile format. Combined with --base it is a usage error.

Exit codes: 0 no drift (or none at or above the minimum severity), 1 drift, 2 usage or runtime error. They are identical for every format.

# pull request check against the target branch
doc-drift-checker check --base origin/main

# local check without a base branch, ignoring a formatting commit
doc-drift-checker check --ignore-revs-file .git-blame-ignore-revs

# only fail on drift with broken references, annotate a pull request
doc-drift-checker check --base origin/main --min-severity high --format github

ack

doc-drift-checker ack <section>

Confirms that a section still matches its code and records it in doc-drift.lock. <section> is <doc path>#<anchor> (for example README.md#installation) or just the anchor when it is unique across all configured documents. Matching is exact. Exit code 0 on success, 2 on error (unknown or ambiguous section, a mapped file with uncommitted changes, a mapped file above 4 MiB, a section without mapped files, a malformed lockfile).

doc-drift-checker ack usage
acknowledged README.md#usage (1 file)

explain

doc-drift-checker explain <section> [--base <ref>] [--ignore-revs-file <path>] [--format text|json]

Shows how check arrives at its result for one section: the resolved links, every mapped file with the rule that kept or dropped it, the commits touching it, whether the section's own lines changed, the lockfile state and the verdict with its reason. It uses the same evaluation as check, so the answer always agrees. Mode selection works like check. Only paths, hashes, commit subjects and dates are printed, never file contents. Exit code 0 whenever the explanation was written (drift or not), 2 on error.

doc-drift-checker explain usage --base origin/main
Section:  Usage
Key:      README.md#usage
Mode:     diff (base origin/main)

Verdict:  no drift
Reason:   all changes to mapped files are dropped by the relevance rules
...
Files:
  cmd/main.go (implicit)
    status: modified
    relevance: dropped, exported API unchanged (analyzer .go)
    triggers drift: no

init

doc-drift-checker init [--write] [--force]

Writes a starter .docdrift.yaml (all values are the built-in defaults, examples are commented out) and suggests <!-- drift: ... --> annotations for sections whose implicit links are strong: all links are implicit and the section links 1 to 10 tracked files. Sections with more files, or with file names that cannot be written safely, are listed as skipped with the reason. Suggestions are only printed unless --write is given; --write inserts each one as its own line directly after the section's heading and refuses a documentation file with uncommitted changes. An existing .docdrift.yaml is not replaced unless --force is given. A documentation file that is a symlink or not a regular file aborts init (exit 2) before anything is written, with or without --write; replace it with a regular file first. Exit code 0 on success, 2 on error.

wrote .docdrift.yaml
README.md
  line 3  Usage
    <!-- drift: cmd/main.go -->
1 annotation suggestion(s), not written (run init --write to insert them)

🔗 Linking sections to code

Each Markdown heading starts a section. A section's own text does not include its child sections. Links are resolved against tracked files only.

Annotation. Put an HTML comment in the section, for example right below the heading. Globs are comma separated and ** matches across directories:

## Configuration

<!-- drift: internal/config/**, cmd/app/flags.go -->

Config mapping. The same link can live in .docdrift.yaml, keyed by the complete heading text (emoji included) or by # plus the anchor:

mappings:
  "🛠️ Configuration":
    - "internal/config/config.go"
  "#-flags":
    - "cmd/app/flags.go"

See Choosing good mappings for how narrow a mapping should be.

Implicit. Without an annotation or mapping, file paths in the section text (such as `cmd/main.go`) and relative Markdown links to tracked files link the section to those files.

References to the section's own documentation file or to any other file matching the docs globs never create an implicit link, because they describe documentation, not code. Annotations and mappings may still point at documentation files.

Explicit links (annotation or mapping) replace implicit ones for that section. Run doc-drift-checker links to see the result and where each link comes from.


🛠️ Configuration

The optional .docdrift.yaml in the repository root configures the tool. Unknown keys and invalid globs are errors (exit 2). doc-drift-checker init writes a commented starter file.

# Documentation files to check (globs, relative to the repository root).
docs:
  - "README.md"
  - "docs/**/*.md"

# Paths whose changes never cause drift.
ignore:
  - "**/*_test.go"
  - "**/testdata/**"
  - "**/vendor/**"

# Explicit section-to-code links, keyed by the complete heading text or "#anchor".
# Map the file that defines a section, not a whole package.
mappings:
  "🚩 Flags":
    - "cmd/app/flags.go"

mode:
  default: history     # mode without --base: history, or diff (needs --base)

severity:
  fail-on: low         # low (default) or high
Key Default Meaning
docs ["README.md"] Documentation files to check.
ignore tests, generated code, lockfiles, vendored code and release documents (CHANGELOG.md, LICENSE, LICENSE.md, LICENSE.txt, CONTRIBUTING.md, at any depth) Globs of paths whose changes never cause drift. A present ignore key replaces the defaults.
mappings none Section-to-code links. A key is the complete heading text, emoji included (🚩 Flags, not Flags), or #anchor. doc-drift-checker links lists keys that match no section as unmatched mapping; check and explain ignore them.
mode.default diff (see below) diff or history: the mode of check and explain when --base is not given. --base always selects diff mode. Left unset, a run without --base uses history mode. Set to diff, a run without --base is a usage error (exit 2).
severity.fail-on low Lowest severity that makes check exit 1. The --min-severity flag wins.

Important
A present ignore key replaces the built-in list entirely; repeat every default you still want. ignore: [] turns path ignoring off. The built-in list is what init writes into the starter file.


🎯 Choosing good mappings

A section without links is unmapped: nothing ties it to code, so it can never drift. Map each section to the file that defines what it describes, not to a whole package. A broad mapping reports drift on every unrelated edit, and a frequently changed file (a central run.go, say) does the same.

  • Key mappings by the full heading text, emoji included ("🚩 Flags"), or by # plus the anchor ("#-flags"). Flags alone matches nothing; doc-drift-checker links shows such keys as unmatched mapping.
  • Map the flag section to the file that registers the flags, not to cmd/**.
  • Start gently: run check --warn-only (exit 0 on drift), then --min-severity high (only broken references fail), then tighten.
  • Add CHANGELOG.md and LICENSE to ignore. A present ignore replaces the built-in list, so repeat the defaults (doc-drift-checker init writes them) or drop them knowingly.
# .docdrift.yaml for a CLI called "mytool"
docs: ["README.md"]
ignore:
  - "**/*_test.go"
  - "**/testdata/**"
  - "**/vendor/**"
  - "CHANGELOG.md"
  - "LICENSE"
mappings:
  "🚩 Flags":
    - "cmd/mytool/flags.go"
  "#-exit-codes":
    - "cmd/mytool/exit.go"

🚦 Severity and broken references

Every drift is low or high. Severity never adds or removes a drift; it only controls which drifts fail the run (--min-severity, severity.fail-on).

A drift is high when the section's own text mentions a flag (--name), an environment variable or an identifier that existed in the section's linked code at the merge base and exists in none of it now. Such a reference is listed as a broken reference with its line in the document. Paths, links and commands are not checked, since the link itself already covers files. Identifiers shorter than three characters and common words are never checked. In history mode there is no base version, so every drift is low.


🧹 Relevance filters

To keep the report quiet, a change is dropped before drift is decided when:

  1. Path: every path of the change matches an ignore glob (tests, generated code, lockfiles, vendored code and release documents by default).
  2. Whitespace: a modified file differs only in whitespace or blank lines.
  3. Go API (diff mode): a changed .go file has the same exported API on both sides. Function bodies, comments, imports and unexported code do not count; exported functions, methods, types, struct fields, constants and variables, the package name and build constraints do. A file that fails to parse counts as changed.

Additions, deletions and renames are never dropped as whitespace-only, and edits to documentation are never filtered. Files in other languages fall back to path-based relevance: any change not ignored by path or whitespace counts.


✅ Lockfile and ack

Sometimes the code changed but the section is still right. Run doc-drift-checker ack <section> and commit the resulting doc-drift.lock. It stores a sha256 hash of every mapped code file of the section:

{
  "version": 1,
  "sections": {
    "README.md#usage": {
      "files": {
        "cmd/main.go": "sha256:0b18…"
      }
    }
  }
}

In diff mode the drift of an acknowledged section is suppressed while its mapped files equal the locked state. In history mode the entry takes precedence over dates: the section drifts exactly when the mapped files differ from the locked state, so run ack again after updating the documentation. Only path ignore rules apply to this comparison, so any content change of a non-ignored mapped file (including a rename) reopens the section. Entries of sections that no longer exist are ignored.


🤖 CI integration

doc-drift-checker ships a composite GitHub Action, SARIF output for code scanning and a pre-commit hook. A minimal pull request check:

jobs:
  doc-drift:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: JtheGunner/doc-drift-checker@v0

Important
v0 is a moving tag that follows the latest 0.x release; use a full version such as v0.1.0 or a commit SHA for reproducible runs. The checkout must have full history (fetch-depth: 0).

Details, inputs, the SARIF upload and the pre-commit hook are in docs/ci-integration.md.


⚠️ Known limits

  • History mode relies on commit dates. A squash merge stamps every touched line with the merge time, so code and docs changed in one squash look equal and are not reported. Rewritten history (rebase, amend) changes dates. Formatting-only commits distort dates; list them with --ignore-revs-file. Deleted section lines are invisible, only HEAD is read (not the working tree), deleted files cannot be dated, and shallow clones are rejected (git fetch --unshallow).
  • Symbol analysis exists for Go only, and only in diff mode. It does not type-check: a change of an unexported declaration that an exported constant, variable or type refers to is not detected. Very long constant chains and files above 8 MiB are always reported as changed.
  • Broken references are matched literally on whole tokens. A removed flag that is still mentioned in a code comment is not detected, a flag moved to a file the section is not linked to reads as broken, and mapped files above 4 MiB are never claimed to be broken.
  • Lockfile comparison cannot apply whitespace or symbol relevance; the mapped files must match exactly.
  • init suggests annotations only for sections with 1 to 10 implicitly linked files and only for the default docs glob (README.md).

🤝 Contributing

Issues and pull requests are welcome. Please open an issue first for larger changes. Report security vulnerabilities privately as described in SECURITY.md, not as public issues.

go build ./...
go test ./...
golangci-lint run

Tests that involve git build real temporary repositories; git must be installed. Every change to relevance or link resolution needs a test for the case that must not be reported.

Releases are built by GoReleaser when a version tag such as v0.2.1 is pushed (the moving v0 tag does not trigger a release), see .goreleaser.yaml.


📄 License

MIT, see LICENSE.

📝 Changelog

See CHANGELOG.md.


Keep your docs as current as your code.