Skip to main content

Detect stale README references after code changes — for pre-commit and CI.

Project description

readme-drift

Detect stale README references after code changes — for pre-commit and CI.

When you rename a function, change a method signature, remove a class, or rename a key in a config file, readme-drift warns you if those names are still referenced in your README — before the commit lands.


How it works

flowchart LR
    A["git diff"] --> B["Changed .py files\nAST diff"]
    A --> C["Changed config files\nKey-path diff"]
    B --> D["Scan README\nbacktick + word-boundary"]
    C --> D
    D --> E{"Match?"}
    E -->|Yes| F["❌ Fail"]
    E -->|No| G["✅ Pass"]

Installation

pip install readme-drift

Usage

As a pre-commit hook (recommended)

Add to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/sachn1/readme-drift
    rev: v0.2.0
    hooks:
      - id: readme-drift

Then install the hook:

pre-commit install

Every git commit that changes .py, .yml, .yaml, .json, or .toml files will now check if the README needs updating.

As a CLI tool

# Check staged changes (same as pre-commit)
readme-drift --staged

# Check against a specific branch (for CI / PRs)
readme-drift --base-ref origin/main

# Warn only — don't fail the build
readme-drift --base-ref origin/main --warn-only

In CI (GitHub Actions)

- name: Check README staleness
  run: readme-drift --base-ref origin/${{ github.base_ref }}

Configuration

All CLI flags can be set permanently in pyproject.toml under [tool.readme-drift]. CLI flags always take precedence over the file.

[tool.readme-drift]
# Git ref to diff against. Default: "HEAD"
base-ref = "origin/main"

# Print warnings but never fail the build. Default: false
warn-only = false

# Track private (underscore-prefixed) symbols. Default: false
include-private = false

# Skip files or directories matching these glob patterns.
# Each entry is equivalent to one --exclude flag on the CLI.
# Default: []
exclude = [
    "generated/",
    "tests/",
    "docs/",
]

# Match symbols as plain text (word-boundary) in addition to backtick spans.
# Default: true. Set to false to restrict matching to backtick spans only.
plain-text-search = true

Supported keys

Key Type CLI equivalent Default
base-ref string --base-ref "HEAD"
warn-only bool --warn-only=true/false false
include-private bool --include-private=true/false false
exclude list of strings --exclude (repeatable) []
plain-text-search bool --plain-text-search=true/false true

pyproject.toml is discovered by walking up from the current directory (or --repo-root if set). If no [tool.readme-drift] section is present, all defaults apply.


Developer reference

A fully annotated Jupyter notebook walks through each module in depth — AST parsing, signature extraction, config diffing, the README scanner, and the complete end-to-end pipeline without git. Useful for understanding the internals or experimenting with edge cases.


Example output

readme-drift: ❌ README.md may be stale:

  • `Client.connect` signature changed: connect(host, port) → connect(url)
    in src/client.py
    referenced in README.md line 42: …call `Client.connect(host, port)` to connect…

  • `build` was removed
    in package.json
    referenced in README.md line 18: …run `npm run build` to compile…

  → Please update the README or run with --no-verify to skip.

What it catches

Python files (.py)

Change Detected?
Function renamed ✅ old name flagged as removed
Function removed
Method signature changed
Class removed
Private symbol changed (_name) ➖ ignored by design
README updated alongside code ✅ passes silently
No Python files changed ✅ skipped

Config files (.yml, .yaml, .json, .toml)

Change Detected?
Script key removed ("build" → gone)
Job name removed (build: → gone)
Tool section removed ([tool.black] → gone)
Key renamed at same level ✅ (reported as remove + add)
Value changed, key unchanged ➖ not tracked

What it doesn't catch

  • Behavioral changes that don't affect the public API or config surface
  • Symbols not mentioned in the README

Supported README formats

Any file named readme (case-insensitive) with the extension .md, .markdown, .rst, .txt, or no extension is scanned. All README files in the repository are discovered recursively, including per-package READMEs in monorepos.

The following directories are never searched:

.git · node_modules · venv · .venv · .tox · __pycache__ · .pytest_cache · dist · build · .mypy_cache


License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

readme_drift-1.0.0.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

readme_drift-1.0.0-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file readme_drift-1.0.0.tar.gz.

File metadata

  • Download URL: readme_drift-1.0.0.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.17.0-23-generic

File hashes

Hashes for readme_drift-1.0.0.tar.gz
Algorithm Hash digest
SHA256 80dccd4bd8163c057b78ae621c55821871bc96c3651f50c65c68a0d74cc39438
MD5 ac2fdfde594bbe968ec51e7733a5d053
BLAKE2b-256 94b82b968eaa759a1ea58d9dccfbf8743643583a820a375125749b6cd321a51b

See more details on using hashes here.

File details

Details for the file readme_drift-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: readme_drift-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.17.0-23-generic

File hashes

Hashes for readme_drift-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a3b9caa9cc07395373453ea68febace87ee4fced758d856eea0460a080b1c8c4
MD5 eee4233b0b971ee957fccb239e4a790e
BLAKE2b-256 56162e9b1e31fd914a0c3259da200eea434690ce20b96c38733d4bd86d64cd6f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page