Build a documentation freshness sweep with Claude Code
Docs rot. This workflow finds the rot — pages that reference deleted files, wrong API signatures, outdated screenshots. Runs weekly, produces a PR with fixes.
Prerequisites
- Documentation in markdown or similar (docs/, README.md, wiki repo)
- A codebase whose changes should be reflected in docs
- Ability to run scheduled workflows (GitHub Actions, cron)
- A team that will actually review the resulting PRs
What you'll learn
- The categories of doc rot and how to detect each
- What to auto-fix vs what to flag for human attention
- How to run the sweep without hammering source systems
- How to prevent false positives that train teams to ignore results
- When to give up on a doc (retirement is often the right answer)
Every team has documentation that's slowly drifting from reality. The endpoints in the docs got renamed. The example code doesn't compile anymore. Screenshots show UI that changed six months ago. The links point to deleted files. This drift is invisible until someone follows the docs and gets confused, at which point the docs actively hurt.
The fix is boring but effective: sweep the docs regularly, detect what's stale, fix what can be auto-fixed, flag what needs human attention. This tutorial builds the workflow — weekly cadence, PR-per-sweep, with categories of drift the tool actually catches.
Not all doc rot is equal. Some can be detected mechanically; some needs judgment; some can be auto-fixed; some can't.
Mechanically detectable + auto-fixable:
- Broken internal links (link to file that no longer exists)
- Broken external links (404s on referenced URLs)
- Code blocks referencing renamed identifiers
- Version numbers that don't match package.json
Mechanically detectable + needs human fix:
- API endpoint mismatches (docs describe endpoint that doesn't exist in code)
- Function signatures out of sync
- Examples that don't compile against current code
- Screenshots from a UI version that no longer matches
Requires judgment:
- Docs describing a feature that's been deprecated but still works
- Sections about "how it used to work" — historically correct but confusing
- Contradictions between docs (one says X, another says Y)
- Docs at wrong altitude — too detailed for their audience or too abstract
The workflow should handle all three categories: auto-fix what it can, flag what needs human attention, differentiate confidently between them.
Start with the auto-fixable category only. Get that reliable before extending to the harder cases. A sweep that produces reliable simple fixes builds trust; one that produces false positives on complex cases destroys it.
---
description: Sweep docs for drift; fix what can be fixed, flag what can't
model: claude-sonnet-4-6
allowed-tools:
- Read
- Write
- Edit
- Grep
- Glob
- Bash(git:*)
---
# Docs Freshness Sweeper
You sweep documentation for drift between docs and code. You produce
concrete fixes for what can be fixed mechanically and a report of
what needs human attention.
## Sweep categories
### 1. Broken links (auto-fix if source moved, flag if deleted)
- Find all internal links in docs
- Check target exists
- If target moved (git shows rename), update the link
- If target deleted, flag: `[FIX: link to deleted file X]`
### 2. Code identifier mismatches (auto-fix if unambiguous)
- Find code blocks with function names, class names, module paths
- Check if identifier still exists in code
- If renamed (git blame shows rename): update
- If deleted: flag with suggested alternative if grep finds similar
### 3. Version drift (auto-fix)
- Find version strings in docs (e.g., "v1.2.0")
- Compare against package.json / equivalent
- Update to current version if mismatch
### 4. API endpoint mismatches (flag only)
- Find URL patterns in docs (e.g., `POST /api/orders/:id/refund`)
- Search for that route in code
- If not found: flag `[REVIEW: docs describe endpoint not in code]`
- Don't try to fix — humans decide if docs are wrong or endpoint
was removed
### 5. Example code compilation (flag only)
- Find fenced code blocks with language tag matching project
- Try to compile/parse the example
- If fails: flag `[REVIEW: example doesn't compile]`
## What you DON'T do
- Don't rewrite docs beyond mechanical fixes
- Don't reorganize doc structure
- Don't "improve" prose (grammar, tone)
- Don't remove sections that seem outdated (unless deleted target)
- Don't infer intent when uncertain — flag instead of fixing
## Output
Two files:
### docs-freshness-fixes.diff
A diff of fixes you've made. Each hunk has a comment explaining what
was fixed and why.
### docs-freshness-report.md
Markdown report of things flagged for human attention. Structured as:
```
## Broken links (needs human fix)
- docs/api.md:47 → `../services/OldService.md` (file was deleted,
not renamed. Was this section supposed to describe OldService?)
## API mismatches
- docs/api.md:82 describes `POST /api/orders/:id/cancel` but no
matching route in code. Was this endpoint removed?
## Broken examples
- docs/quickstart.md:35 example fails to compile — likely uses old
import path `from '@app/legacy'`.
```
Notice the split between fixes (auto-applied via diff) and flags (require human decision). This is the key architectural choice — never auto-fix in areas where you'd be guessing.
---
description: Run a documentation freshness sweep and open a PR
allowed-tools:
- Read
- Write
- Bash(git:*)
- Bash(gh:*)
---
# /docs-freshness-sweep
Run the full docs freshness sweep. Produce a PR with fixes and a
report of flagged items.
## Process
1. Create a branch: `docs-sweep-YYYY-MM-DD`
2. Invoke @docs-freshness against `docs/` and `README.md`
3. Apply the fixes diff to the branch
4. Commit with descriptive message
5. Save flags report to `docs-freshness-report.md`
6. Commit the report
7. Push branch and open PR:
- Title: "docs: freshness sweep for YYYY-MM-DD"
- Body: summary of fixes + copy of flags report
- Labels: `docs`, `automated`
## When to skip
- If no changes result: don't create empty PR, just log "no drift found"
- If the sweep fails partway: don't create partial PR, report failure
The command doesn't merge the PR — it opens it for review. Human reviewers verify the auto-fixes look right, address the flags, and merge when satisfied.
name: Weekly docs freshness sweep
on:
schedule:
- cron: '0 4 * * 1' # 4am UTC every Monday
workflow_dispatch: # Allow manual trigger
jobs:
sweep:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
- name: Install cctk
run: npm install -g @claude-code-toolkit/cli
- name: Run sweep
run: cctk run docs-freshness-sweep
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Notify on failure
if: failure()
uses: slackapi/slack-github-action@v1
with:
webhook: ${{ secrets.SLACK_WEBHOOK }}
payload: |
{"text": "Docs freshness sweep failed — check workflow logs"}Weekly cadence usually works. More frequent and PRs pile up; less frequent and drift accumulates. Adjust based on how much your docs actually change.
A full docs sweep costs tokens proportional to your doc size. For small doc sets (under 200 pages), weekly is fine. For huge doc sets, consider monthly full-sweep + incremental sweep on PRs that touch docs.
Some flags won't get fixed. The endpoint mentioned in docs really was removed six months ago; nobody's decided whether to remove the doc section or restore the endpoint. Left unattended, this becomes a stale flags backlog that grows every week.
The pattern that works: expire unaddressed flags. If a flag has appeared in three consecutive sweeps without human resolution, the subagent should:
- Auto-close the doc section describing the removed endpoint, replacing with a note "This section was removed on YYYY-MM-DD because the described endpoint no longer exists."
- Or auto-file a GitHub issue with the specific flag and let it enter your normal work queue
- Or explicitly annotate the doc: "This section may be out of date; last verified YYYY-MM-DD."
The choice depends on your team's culture. But leaving flags unaddressed forever is worse than any of these options — the sweep becomes noise if flags never get resolved.
The sweep will have false positives — flagging things that aren't actually stale. Common cases:
- Historical sections — docs describing "how it used to work" get flagged as mismatches with current code
- Example code with intentional simplifications — doesn't match production patterns but is fine
- Legacy API references — deprecated but intentionally documented for migration
When you find false positives, update the subagent to skip them. Add markers to docs like <!-- freshness-skip: historical --> that the sweep respects. Or teach the subagent about specific patterns to leave alone.
The first few weeks of running the sweep are calibration. After that, false positives should drop below 10% — low enough that people trust the results.
Run the sweep manually the first time (workflow_dispatch trigger). Review the output carefully. What did it catch that's correct? What did it catch that's a false positive? Update the subagent based on the false positives before letting it run automatically.
Recap
You built a documentation freshness sweep — weekly cadence, auto-fixes for mechanical drift, flagged report for things needing human decision, PR-per-sweep for review.
The pattern that works: separate what can be auto-fixed from what needs human judgment, run on a cadence that matches your rate of change, iterate to keep false positives low, don't let flags backlog forever.
This workflow prevents the "docs are useless" outcome. Small maintenance investment weekly beats a big documentation-rewrite project every two years.
Common gotchas
- PRs pile up because nobody reviews them: Assign a rotating "docs review" duty. One engineer per week is responsible for reviewing the sweep PR. Without ownership, PRs accumulate and the workflow stops helping.
- Auto-fixes break something: That's why fixes go through PR review, not auto-merge. If a specific auto-fix keeps causing issues, tighten the subagent's conditions for auto-applying that class of fix.
- False positives train reviewers to rubber-stamp: Existential threat. Investigate every false positive, update the subagent to prevent recurrence. If you can't get false positive rate below ~10%, the sweep is doing more harm than good.
- Sweep runs but produces no useful output: Docs might be well-maintained already, or the sweep is too permissive. Manually check some pages that "feel stale" — if the sweep didn't flag them, sharpen its checks.
- Cost is higher than expected: Trim scope. Sweep only the most-viewed docs (from analytics if you have them). Or reduce cadence to monthly. Or narrow to specific categories of drift most valuable to catch.
Get cctk to skip the boilerplate
Everything in this tutorial is already scaffolded in cctk — commands, subagents, hooks, MCP configs. Install and customize instead of starting from scratch.