stale-claims
A section of tracked Markdown that names a file, beside a history in which that file has changed since the section was last edited. The check finds the code each section names, counts the commits each of those files has seen since the section’s own last touch, and ranks the sections by the largest share of any named file’s history that falls after that point. The output is a ranked list of candidates, never a verdict: a section high on the list names code that has moved a great deal since the section was written, and someone should read the two together, but nothing here has found the section false. A busy file makes an accurate sentence look suspicious, and a sentence can be wrong about a file that has not changed at all.
What it checks
A section is a heading and everything below it to the next heading,
at any level, or the whole file when it has no heading. A line inside a
fenced code block is never a heading, so a # comment in a shell example
stays part of the section it sits in. In a file with
headings, lines above the first belong to no section and are not
ranked. The section is the unit because a claim about a file is rarely
one sentence, and the heading is what the finding names.
A subject is a tracked file the section names, in one of two shapes.
An explicit relative path, a directory and a file name with an
extension, counts when a tracked file has exactly that path, or the
diff range deleted or renamed away a file at that path, read from the
repository root or, failing that, from the directory of the file that
cites it: .github/workflows/ci.yml names that file, and so does
./.github/workflows/ci.yml. A path starting with ../ is read from
the citing file’s directory only. A path starting with / or ~/ names
no subject, because it points outside the repository. A
backticked bare name, with or without an extension, counts when exactly
one tracked file outside exclude has that stem: cache.py and cache
both name the one file whose name without its extension is cache. A
written extension must match that file’s own, letter case included, so
cache.yaml names nothing when the one file with that stem is
cache.py. A stem that two such files share names no single file and
is dropped rather than guessed at. The repository’s own claims.toml is
never named this way: claims names the tool, and a page about the
configuration format does not go stale because the project tuned its
own configuration. Neither shape takes a space, so a file whose path
contains one is never a subject. A section naming no subject is not
ranked.
The bare form is ambiguous in a way the path form is not, because a
word such as cache or config is as often ordinary prose or a
configuration key as it is a module. The module_reference_scope key
narrows where a bare name counts as a subject; by default it counts
everywhere.
The stem lookup does not distinguish written code from generated
output. In a project that commits a terminal capture of its doctor
subcommand as docs/captures/doctor.ansi, and has no other file with
that stem, a section mentioning doctor in backticks names the capture,
and every regeneration of the capture counts against it. Listing the
generated tree under exclude keeps a bare name from reaching it:
[stale-claims]
exclude = ["docs/captures/*"]
A section that cites the capture by its path, in prose or in a link, still names it, because a path is a deliberate choice of file where a bare name is a guess. Since only Markdown files are ranked, excluding a tree of non-Markdown output removes nothing from the ranking itself.
The section’s last touch is the newest commit git blame attributes
to any of its lines, by committer time. For each subject, the check
reads the file’s full commit history and counts the commits strictly
after that time. The section’s score is the largest fraction, across
its subjects, of that subject’s history that lies after the touch, so a
claim older than most of a quiet file’s life outranks one older than a
sliver of a busy file’s. The finding names up to three subjects, most
changed first, each with its commit count and its share of history.
Sections are reported in descending score, and a section none of whose
subjects has changed since its last touch is not reported.
A section is ranked only when the diff range changes one of its subjects: adds, modifies or deletes it, or renames it, counted by both its old and its new path. A section whose subjects the range leaves alone is not reported, however stale its score would be, and an edit to the section itself is not a change to a subject. The score is the same whichever range brings a section in, since it is read from the whole history of each subject, not from the range.
When the range reaches the working tree, as the commit hook’s does, the
uncommitted change counts as one more commit after the section’s last
touch to each subject it changes: in the count, and in the subject’s
history. A run before committing therefore reports each section with the
score a run over that commit will give it once it is made. A range
ending at a commit, A..B or A...B, leaves the working tree out, and
so leaves the uncommitted change out of the score too. The uncommitted
change counts on the same tests as a commit: for a subject scoped to one
section, only when it touches that section’s lines, and for an
append-only subject, only when it removes a line. A section with
uncommitted edits of its own has the uncommitted change as its last
touch, so the same-commit rule below applies to it before the commit is
made, and it scores zero for every subject.
A path to a Markdown file followed directly by # and an anchor, in a
link such as [text](page.md#anchor) or bare in prose, names one
section of that file rather than the whole of it, when the anchor is the
slug of one of its headings. That section runs from the heading to the
next heading of the same or a higher level, so its subsections belong to
it, and its history is only the commits that touched the lines it spans
in the latest commit. An anchor that matches no heading, or one on a file that is not
Markdown, names the whole file. The finding names such a subject with
its anchor, and a section linking the same file with and without an
anchor, or with two anchors, keeps each as its own subject.
A navigation page named without an anchor is not a subject of the section: its history is not counted and the finding does not name it. A link with an anchor into one names its section as above.
An append-only subject, which
CHANGELOG.md is by default, does not count a commit whose diff for the
file removes no lines, wherever the lines it adds are: such a commit is
left out of both the commits after the section’s last touch and the
file’s history. A commit that changes or removes a line counts, cutting
a release by renaming its heading included. The commit that created the
file removed nothing either, so it is no part of that history. For a
subject scoped to one section, a commit is left out on the same test
over the whole file’s diff.
The same test decides whether such a subject brings its section into the range: it does only when a commit in the range, or the uncommitted change, removes a line from the file. Growth alone brings nothing in, a newly created file included, while a deletion, a rename, a binary change or a rewritten line still does, even a line added earlier in the same range. A merge in the range is not tested itself, only the commits it brings in, so bringing a branch up to date with a base that rewrote the file brings nothing in. A section is still ranked when another of its subjects changed, with the same score.
A section and its subject changed in the same commit score zero for that subject, because the commit that touched both is the section’s own last touch and not a change after it. Two separate commits that share a committer timestamp to the second fall into the same gap. A rewrite of a claim to match a change to its subject, landed together, is therefore invisible here, and nothing else in the check compensates for it.
A subject scoped to one section does not see a change beside it. An edit
to the paragraph just above the linked heading is not counted, even when
it changes what the linked section means. A renamed heading is not lost
the same way: the anchor then names no heading, check-links reports the
link as broken, and fixing that link brings a reader back to the section
that holds it.
The check is diff-scoped: it reads every tracked .md file on every
run, and reports only the sections the range brings in. It runs no
command. A file named CHANGELOG.md, in any letter case and
any directory, is skipped, because a changelog entry describes a release as it shipped and its
subjects moving afterwards is expected.
Why it exists
Most prose about code is true when written and stops being true later, and nothing reports the moment it stops. A rename is caught by a citation check; a default that moved is caught by a defaults check; but a paragraph that describes how a module works has no single fact to test, and the only signal that it might have rotted is that the module kept changing while the paragraph did not. That signal is weak, which is why the check ranks rather than decides, and it is still the one signal available for a claim no narrower check can reach.
Example
The example is history alone, because a section can only be older than its subject’s changes once those changes have been committed after it. The capture commits three steps an hour apart. The first writes the design note and the three files it names:
examples/stale-claims/history/01-writes/docs/design.md:
# Caching
Reads go through `cache.py`, which keeps one entry per path and evicts
nothing until the process exits.
# Storage
Entries are written by src/store.py as one file per key, named for the
key's hash.
# Logging
Every write is logged through `log.py` at debug level.
examples/stale-claims/history/01-writes/src/cache.py:
entries = {}
def get(path):
return entries.setdefault(path, open(path).read())
examples/stale-claims/history/01-writes/src/store.py:
import hashlib
def put(key, value):
open(hashlib.sha1(key).hexdigest(), "w").write(value)
examples/stale-claims/history/01-writes/src/log.py:
import logging
def debug(message):
logging.getLogger("store").debug(message)
The second step changes the cache to evict:
examples/stale-claims/history/02-evicts/src/cache.py:
LIMIT = 64
entries = {}
def get(path):
if len(entries) >= LIMIT:
entries.pop(next(iter(entries)))
return entries.setdefault(path, open(path).read())
The third rewrites the cache again and changes the store’s layout on disk:
examples/stale-claims/history/03-rewrites/src/cache.py:
from functools import lru_cache
@lru_cache(maxsize=64)
def get(path):
return open(path).read()
examples/stale-claims/history/03-rewrites/src/store.py:
import hashlib
import os
def put(key, value):
name = hashlib.sha1(key).hexdigest()
os.makedirs(name[:2], exist_ok=True)
open(os.path.join(name[:2], name[2:]), "w").write(value)
The design note is never edited after the first step. Run against that
repository over the range HEAD~1, the third step’s own change, the
check reports:
# python3 scripts/capture.py: stale-claims, run against a throwaway git repository seeded from examples/stale-claims over the diff range HEAD~1
[advisory] docs/design.md:1 (stale-claims) 'Caching' names code 67% changed since last touched — cache.py 2 commits (67% of its history)
[advisory] docs/design.md:6 (stale-claims) 'Storage' names code 50% changed since last touched — store.py 1 commit (50% of its history)
The Caching section is first because its subject changed most: of the three commits in the cache file’s history, two came after the section was written. The Storage section names its subject as a path rather than a bare name, and ranks second, with one of the store file’s two commits after the section. The Logging section names a file that has not changed since the section was written and is outside the range, and is not reported at all. The capture is the same on every run because the commits carry fixed timestamps; the score depends on commit times, not on the clock.
Both findings are candidates. The Caching section is in fact false now, since the cache evicts, and the Storage section is still true, since entries are still one file per key. The check cannot tell those apart, and does not claim to. The fix for a candidate is to read the section against the code and either correct it or leave it, and a section that is read and left alone comes back on any range that changes one of its subjects again, until its lines are next touched.
Auditing the whole tree
A section whose subjects nothing touches is never ranked at commit time, so a stale claim about a quiet file stays silent until a range reaches it. To rank every section whose subjects have changed at all, run the command line over a wide range: since a release tag,
python3 -m claims.cli --diff-range v1.0.0..HEAD
or since the first commit:
python3 -m claims.cli --diff-range "$(git rev-list --max-parents=0 HEAD)..HEAD"
Every check runs over that range, so the other diff-scoped checks report on everything the range changed too.
Configuration
[stale-claims]
module_reference_scope = ["decisions/*.md", "AGENTS.md"]
exclude = ["docs/legacy/*.md"]
exclude_sections = ["decisions/*.md#context"]
| Key | Shape | Default | Reach for this when |
|---|---|---|---|
module_reference_scope | list of glob strings; a bare string is a one-element list | absent: a bare backticked name counts as a subject in every file | Common file stems double as ordinary words or configuration keys in the tree, so a bare cache or config in a tutorial names a module the sentence is not about. With the key set, a bare name counts only in a matching file; a name with its file’s extension, and an explicit path, count everywhere regardless. |
exclude | list of glob strings; a bare string is a one-element list | []: nothing excluded beyond the built-in CHANGELOG.md | A file’s sections should not be ranked at all: prior-art notes about another project, or a directory of inputs written to be broken, like this site’s own examples. An excluded file is skipped whole, and a bare backticked name never resolves to it, so a stem it shares with one other file names that other file. An explicit path to it still counts as a subject. |
exclude_sections | list of <path glob>#<slug> strings; a bare string is a one-element list | []: every section of a ranked file is ranked | One kind of section can’t go stale, though the rest of its file can: an architecture decision record’s Context describes the world before the decision, and stays true of that world however far the code moves. A section is skipped when its file matches the glob, matched as exclude matches, and its heading’s slug equals the slug exactly, under the slug rule an anchored link uses; the headings nested under it are skipped with it. The slug takes no glob. An entry with no slug after its #, or with one no heading could have, such as Context or prior art for context or prior-art, is reported as invalid configuration. A skipped section still counts as a subject when another section links to it. |
enabled, which takes this check out of the commit gate while leaving it
in the on-demand skill and the CLI, is shared by every check and covered
on Configuring claims.
Which files are append-only is set once for the project, under
[subjects] rather than this check’s own section, and is covered there
too, in Append-only files, as are
the pages that are no subject when named whole, in Navigation
pages.
Retirement markers
None. A section is ranked by the age of its lines and the history of
its subjects, and a blockquote, an italicised sentence or a paragraph
opening “Previously said:” inside it is read like any other line. The
retired-quote exemption
skips a sentence quoted in order to retire it; this check’s unit is a
section rather than a sentence, and a section that is deliberately
about the past belongs in a file listed under exclude.
Next
restatement, which finds a sentence a diff retracted that is still asserted, word for word, somewhere else.