Finds documentation that no longer matches the code: git-history drift, a heuristic staleness score, Python API docs checked against the AST, and broken links/anchors, each finding quoted with a fix. Use when docs may be out of sync with code, before a release, in a CI doc gate, or after a refactor that renamed or moved files.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Doc Drift Detector?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/borghei-doc-drift-detector)
---
name: doc-drift-detector
description: >
Finds documentation that no longer matches the code: git-history drift, a heuristic staleness
score, Python API docs checked against the AST, and broken links/anchors, each finding quoted with
a fix. Use when docs may be out of sync with code, before a release, in a CI doc gate, or after a
refactor that renamed or moved files.
license: MIT + Commons Clause
metadata:
version: 2.2.0
author: borghei
category: engineering
domain: documentation
updated: 2026-12-03
tags: [documentation, staleness, api-docs, drift-analysis]
python-tools: drift_analyzer.py, doc_staleness_scorer.py, api_doc_validator.py, link_checker.py
tech-stack: python, git, markdown, documentation
---
# Documentation Drift Detector
The agent detects documentation drift by mapping code directories to their docs, comparing git modification histories, extracting Python function signatures via AST, validating every markdown link and anchor, and scoring freshness on a heuristic 0-100 scale. All four CLI tools use the Python standard library only.
## Core Capabilities
- **Full drift analysis** — map docs to code, compare git histories, detect renamed files, version drift, broken references, and structural gaps; classify each issue by category, severity, and fix type.
- **API doc validation** — AST-based extraction of Python signatures/classes compared against markdown API docs (undocumented items, phantom docs, parameter mismatches, deprecations).
- **Staleness scoring** — heuristic 0-100 freshness score across five dimensions (unmeasurable ones excluded) with CI threshold gates and README-focused mode.
- **Link integrity audit** — validate local files, anchors, cross-document anchors, images, case-sensitivity, and duplicate anchors; optional external URL checks.
- **Drift classification** — structural, factual, referential, temporal, semantic categories, each tagged `[AUTO]`/`[SEMI]`/`[MANUAL]` for fix routing.
- **CI/CD integration** — non-zero exit codes, JSON output, GitHub Actions and pre-commit recipes for ongoing monitoring.
## When to Use
- Docs have fallen out of sync with code — run full drift analysis.
- Preparing a release — gate on aggregate staleness score.
- Running CI doc gates — fail PRs on high/critical drift or broken links.
- Auditing API doc accuracy against Python source.
- Checking README health and link integrity after refactors.
## Clarify First
Before running detection, settle the inputs below. When one is missing or vague and would change the result, ask about it; when it wouldn't, use a sensible default and say which one you used.
- **Which check:** full drift analysis, staleness score, API doc validation, or link audit (selects `drift_analyzer.py` vs `doc_staleness_scorer.py` vs `api_doc_validator.py` vs `link_checker.py`).
- **Repo & doc/source paths:** the repository and which code and docs directories to compare (the input the tools scan).
- **Threshold & gate:** minimum severity or staleness threshold for CI failure (sets `--min-severity`/`--threshold` and the exit-code gate).
Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, produce it and state your assumptions at the top.
## Workflow
1. **Links first** (fast, no git needed): `link_checker.py <docs-dir> --broken-only`. Fix broken files and anchors.
2. **API docs** (Python): `api_doc_validator.py <src> <docs> --recursive` lists documented-but-missing and undocumented functions and classes, and signature mismatches.
3. **Drift against history**: `drift_analyzer.py <repo>` compares doc and code change history (needs a git checkout; on very large repositories use `--scope` to limit it).
4. **Score freshness**: `doc_staleness_scorer.py <repo> --threshold 60` for a 0-100 score per document and an aggregate gate.
5. **Fix** in order: broken links and wrong API signatures (readers act on them), then stale how-tos, then completeness.
6. **Verify** that all four tools exit 0 at the gates you chose before merging.
## Quick Start
```bash
python3 scripts/link_checker.py assets/links_flawed # exit 1, each broken link with a fix
python3 scripts/api_doc_validator.py assets/api_flawed/src assets/api_flawed/docs # exit 1
python3 scripts/drift_analyzer.py assets/flawed_repo.bundle --as-of 2026-12-01 # exit 1
python3 scripts/doc_staleness_scorer.py assets/flawed_repo.bundle --as-of 2026-12-01 --format json
```
Real output (`doc_staleness_scorer.py assets/flawed_repo.bundle --as-of 2026-12-01`, excerpt):
```text
Aggregate: 0.0/100 (abandoned), gate 60
FINDINGS (worst file first):
README.md [code_doc_alignment]
Input: references missing: docs/setup.md, lib/old_parser.py, src/missing.py
Fix: Point each reference at the file's current path, or delete the sentence that mentions it
FIX aggregate 0.0 is below 60 across 1 doc(s)
```
On your own repo use a checkout path instead of the `.bundle` file. `assets/sound_repo.bundle` and
`assets/flawed_repo.bundle` are frozen git histories (`git bundle create`); the tools clone a bundle into a
temporary directory, so no history is needed on disk. `--as-of` pins "today" so results are reproducible.
## Tools Overview
| Tool | What it does | Key flags |
|------|--------------|-----------|
| `link_checker.py <dir-or-file>` | Local files, anchors (GitHub slug rules), cross-doc anchors, images, duplicate anchors; ignores fenced and inline code. External URLs are "not checked" unless asked | `--broken-only`, `--check-external`, `--format text\|json` |
| `api_doc_validator.py <src> <docs>` | Python AST vs markdown docs: documented-but-missing, undocumented, parameter mismatches; builtins and third-party names in docs are ignored | `--recursive`, `--include-private`, `--format` |
| `drift_analyzer.py <repo\|.bundle>` | Structural, factual, referential, temporal, semantic drift from git history; quotes the doc line and gives a fix | `--min-severity`, `--fail-on`, `--scope`, `--doc-patterns`, `--as-of`, `--format` |
| `doc_staleness_scorer.py <repo\|.bundle>` | Heuristic 0-100 score per doc from five dimensions; unmeasurable dimensions are excluded, not defaulted | `--threshold` (default 60), `--readme-focus`, `--required-sections`, `--weight-*`, `--as-of`, `--format` |
`--json` still works as an alias of `--format json`. Standard library only; the git tools call the `git` command.
`scripts/_repo_input.py` is a helper module, not a command.
## Exit Codes
| Code | Meaning |
|------|---------|
| 0 | Clean: no broken links; no high/medium API issue; no drift at or above `--fail-on` (default high); aggregate score at or above the threshold |
| 1 | Findings to act on (each prints the quoted input and a fix); for the scorer, aggregate below the threshold or nothing measurable |
| 2 | Unusable input, one `BLOCKED:` line on stderr: missing path, not a git repo or valid bundle, no commits, no docs, no Python functions or classes, bad `--as-of` |
The scorer's weights, the age curve, the 60 gate and the drift tool's severity cut-offs (more than 5 or 20 changed
files, 180 or 365 days) are internal heuristics, not published benchmarks; the report says so.
## Anti-Patterns
**Mistake:** Gating CI on every low-severity drift finding.
**Why it happens:** Strict gates look rigorous.
**Instead:** Fail on high (the default) and report the rest; a gate that fails on cosmetic drift gets disabled.
**Mistake:** Treating "recently edited" as "accurate".
**Why it happens:** Age is the easiest signal to compute.
**Instead:** Check alignment with the code that changed (drift analyzer, API validator); a doc edited yesterday can still describe last year's API.
**Mistake:** Writing example links in docs as real links.
**Why it happens:** It is the natural way to show syntax.
**Instead:** Put examples in inline code or fenced blocks; the checker ignores them there and reports only real links.
## Reference Documentation
Load the reference that matches the task — keep this file lean and pull detail on demand:
- **[references/workflows-and-tool-reference.md](references/workflows-and-tool-reference.md)** — quick start, the 5 core workflows (full analysis, API validation, README health, link audit, CI monitoring) with output examples, GitHub Actions + pre-commit recipes, and the complete per-tool parameter/output/exit-code reference. Read when running tools or wiring CI.
- **[references/scoring-categories-and-troubleshooting.md](references/scoring-categories-and-troubleshooting.md)** — the staleness scoring model and weights, the five drift categories, auto-fix vs manual-fix classification, detailed integration points, anti-patterns, troubleshooting table, and success criteria. Read when interpreting results or triaging drift.
- **[references/documentation_standards.md](references/documentation_standards.md)** — README structure, API docs, changelogs, ADRs, docs-as-code standards.
- **[references/drift_prevention_guide.md](references/drift_prevention_guide.md)** — coupling strategies, CI gates, review checklists, and prevention patterns.
## Files
- `scripts/link_checker.py`, `scripts/api_doc_validator.py`, `scripts/drift_analyzer.py`, `scripts/doc_staleness_scorer.py` — the tools above.
- [assets/drift_report_template.md](assets/drift_report_template.md) — report template; [assets/sample_drift_data.json](assets/sample_drift_data.json) — example of a combined report's shape (illustrative data, not tool input); `assets/*_repo.bundle`, `assets/api_*`, `assets/links_*` — sound / flawed / malformed samples listed in `assets/contract.json`.
## Scope & Limitations
**Covers:**
- Detection of documentation drift against git history for any git repository
- AST-based validation of Python API documentation (function signatures, class definitions, parameters, return types)
- Internal link validation including local files, markdown anchors, cross-document anchors, images, and case-sensitivity checks
- Multi-dimensional staleness scoring with configurable weights and CI/CD threshold enforcement
**Does NOT cover:**
- Non-Python source code API validation -- the AST-based validator only parses Python; for TypeScript, Go, Rust, or Java APIs, use language-specific doc generators and pair with the link checker
- External URL uptime monitoring -- `--check-external` performs one-shot HEAD requests but does not provide continuous monitoring; use the **senior-devops** skill for uptime dashboards
- Automatic documentation rewriting -- tools classify issues as `[AUTO]`, `[SEMI]`, or `[MANUAL]` but do not generate replacement text; use the **code-reviewer** skill for AI-assisted doc suggestions
- Content quality or readability assessment -- staleness scoring measures freshness and structural completeness, not prose quality; see the **standards/communication** library for writing guidelines
Related skills: `engineering/code-reviewer` (attach the drift report to PR review), `engineering/senior-devops` (CI gates).