12. Docs Drift
The docs blade reads every Markdown file in your repository and checks the concrete references in it against the code: file paths, Type::symbol names, CLI flags, npm run / just / make targets and HTTP routes. It reports each reference that no longer matches.
Use it to catch a README or agent instruction file that still names a renamed file, a removed flag or a deleted script.
Quick example
Section titled “Quick example”The demo repository has a Python CLI (mycli, built with argparse), an npm bin (tool, built with commander), a Rust binary (rtool, built with clap), a Go command under cmd/server, two TypeScript routes, a justfile with build and a Makefile with test. Its README.md is out of date:
# Acme
See the [guide](docs/guide) and the [old setup](docs/setup.md).The entry point is `src/main.rs`; the parser lived in `src/parser.rs`.Call `render_report` or `Report::render_report`; the old `Ghost::build_index` is gone.
Run `npm run build`, `npm run lint`, `just build`, `just deploy`, `make test` or `make release`.
Use `mycli --dry-run`, `mycli --force`, `tool --watch`, `rtool --out-dir x`, `rtool --quiet`, `rtool --max-depth=2` and `server --port 9000`.`codeknife check --format json` and `codeknife check --bad-flag`.
The API serves `/api/users`, `/api/orders/`, `/api/users/{id}` and `/api/v0/legacy`.
```text`src/ignored.rs` inside a text fence is skipped```
```sh`src/also_missing.rs` inside a sh fence is still checked, [link](nope.md) is not```AGENTS.md:
Agents: run `just lint` before committing. Config lives in `./config/app.toml`.The Rust CLI declares its flags like this:
#[derive(Parser)]pub struct Args { #[arg(long)] pub out_dir: Option<String>, #[arg(long)] quiet: bool, #[arg(long = "max-depth")] pub depth: Option<u32>,}Run the blade:
codeknife docs --format humanwarning[CK_DOC_STALE_COMMAND]: documented `just lint` recipe missing from justfile --> AGENTS.md:1 (just lint) = fix: Update docs or restore the missing script target.
warning[CK_DOC_DEAD_PATH]: documented file/directory path `./config/app.toml` does not exist --> AGENTS.md:1 (./config/app.toml) = fix: Fix the path to match current repository layout.
warning[CK_DOC_DEAD_PATH]: broken markdown link target `docs/setup.md` --> README.md:3 (docs/setup.md) = fix: Update or remove the broken path reference in documentation.
warning[CK_DOC_DEAD_PATH]: documented file/directory path `src/parser.rs` does not exist --> README.md:4 (src/parser.rs) = fix: Fix the path to match current repository layout.
warning[CK_DOC_DEAD_SYMBOL]: documented symbol `Ghost::build_index` was not found in codebase --> README.md:5 (Ghost::build_index) = fix: Update documentation to match renamed or removed symbol.
warning[CK_DOC_STALE_COMMAND]: documented `npm run lint` script missing from package.json --> README.md:7 (npm run lint) = fix: Update docs or restore the missing script target.
warning[CK_DOC_STALE_COMMAND]: documented `just deploy` recipe missing from justfile --> README.md:7 (just deploy) = fix: Update docs or restore the missing script target.
warning[CK_DOC_STALE_COMMAND]: documented `make release` target missing from Makefile --> README.md:7 (make release) = fix: Update docs or restore the missing script target.
warning[CK_DOC_DEAD_FLAG]: documented CLI flag `--force` is not defined by `mycli` --> README.md:9 (--force) = fix: Update the documented flag to match the current CLI interface.
warning[CK_DOC_DEAD_FLAG]: documented CLI flag `--quiet` is not defined by `rtool` --> README.md:9 (--quiet) = fix: Update the documented flag to match the current CLI interface.
warning[CK_DOC_DEAD_FLAG]: documented CLI flag `--bad-flag` is not defined by `codeknife` --> README.md:10 (--bad-flag) = fix: Update the documented flag to match the current CLI interface.
info[CK_DOC_DEAD_ROUTE]: documented HTTP route `/api/v0/legacy` was not found in registered routes --> README.md:12 (/api/v0/legacy) = fix: Update documentation or verify the route path matches your router handlers.
warning[CK_DOC_DEAD_PATH]: documented file/directory path `src/also_missing.rs` does not exist --> README.md:19 (src/also_missing.rs) = fix: Fix the path to match current repository layout.
codeknife docs: FAIL (5 files, 0 errors, 12 warnings, 1 info, 14ms)What passed and why:
[guide](docs/guide)resolves todocs/guide.md(extensionless link).Report::render_reportpasses because a function namedrender_reportexists. Only the last segment has to exist./api/orders/matches the registered/api/ordersafter the trailing slash is removed./api/users/{id}is skipped as a placeholder.rtool --out-dirandrtool --max-depth=2match the clap definitions.rtool --quietis reported because thequietfield is notpub(see CLI flag discovery).server --portmatches the Goflag.String("port", ...)call.- The
textfence is skipped. Theshfence is not, so its inline code is checked, but its Markdown link is not.
The files count in the summary is the number of source files in the code model, not the number of Markdown files.
Which files are scanned
Section titled “Which files are scanned”Every file with the extension .md under the repository root. The walk:
- respects
.gitignore, - skips hidden files and directories (for example
.github/), - skips directories named
target,node_modules,.git,vendorand.codeknife.
README.md and AGENTS.md get no special treatment; they are scanned like any other .md file. Files ending in .mdx or .markdown are not scanned. In testing, a broken path in .github/CONTRIBUTING.md and in guide.mdx produced no finding.
With --changed, only .md files in the changed set are scanned, and the whole file is checked:
codeknife docs --changed --format agentCODEKNIFE docs status=fail files=5 errors=0 warnings=3 infos=0 elapsed_ms=5[1] WARNING CK_DOC_DEAD_PATH AGENTS.md:1-1 sym=./config/app.toml impact=40 | documented file/directory path `./config/app.toml` does not exist | fix: Fix the path to match current repository layout.[2] WARNING CK_DOC_STALE_COMMAND AGENTS.md:1-1 sym=just lint impact=35 | documented `just lint` recipe missing from justfile | fix: Update docs or restore the missing script target.[3] WARNING CK_DOC_STALE_COMMAND AGENTS.md:2-2 sym=just ship impact=35 | documented `just ship` recipe missing from justfile | fix: Update docs or restore the missing script target.Here only AGENTS.md had uncommitted edits.
How a file is read
Section titled “How a file is read”CodeKnife reads each file line by line.
Code fences. A line whose trimmed text starts with three backticks opens or closes a fence. The fence lines themselves are skipped. If the opening fence has no language or one of text, output, json, mermaid, csv, console, every line inside is skipped. Inside any other fence (for example sh, bash, rust), Markdown links are not checked but inline code spans are. Fences written with ~~~ are not recognised, so their content is checked like normal text.
Markdown links. Outside fences, every [text](target) is checked, including images. The target ends at the first ), # or whitespace. A target is ignored when it contains ://, starts with mailto:, tel:, data: or #, or is an all-caps placeholder (at least 4 characters, only A-Z, 0-9 and _, no / or .). Reference-style links are not checked.
Inline code. Every single-backtick span on a line is trimmed and then routed:
- If it contains a space and does not start with
npm run,justormake, it is treated as a command and only its flags are checked (CK_DOC_DEAD_FLAG). - Otherwise it is tested, in this order, as a path, a symbol, a route and a script reference. The first test that applies decides the finding.
Because of rule 1, a path inside a multi-word span, such as cat src/x.rs, is never checked.
Checks
Section titled “Checks”Paths (CK_DOC_DEAD_PATH)
Section titled “Paths (CK_DOC_DEAD_PATH)”A link target or inline path exists if either of these exists:
- the path relative to the repository root (a leading
/is removed), or - the path relative to the Markdown file’s directory.
A #fragment and a trailing / are removed first. If the path has no extension, CodeKnife also tries path.md, path/index.md and path/README.md, relative to both places.
An inline code span counts as a path only when it:
- starts with
./and has at least two segments after it, or one segment containing a., or - starts with
src/,crates/ortests/.
It is skipped if it contains any placeholder marker: path/to, <, >, {, }, [, $, *, ..., foo or example. Inline paths under other folders, such as docs/missing.md, are not checked. Links have no such restriction.
Symbols (CK_DOC_DEAD_SYMBOL)
Section titled “Symbols (CK_DOC_DEAD_SYMBOL)”An inline span is a symbol when it contains ::, contains no * or <, and does not start with std:: or tokio::. It exists when any of these holds:
- an item has exactly that qualified name,
- any item has the same name as the last
::segment, - an item’s qualified name ends with the span text.
Python and TypeScript qualified names use other separators, so this check is most useful for Rust-style names. See Import Resolution for how qualified names are built.
HTTP routes (CK_DOC_DEAD_ROUTE)
Section titled “HTTP routes (CK_DOC_DEAD_ROUTE)”The route check runs only when the code contains at least two route-like strings. A route-like string is any string literal that starts with /, is longer than 2 characters, has no space and does not start with //. It does not have to be registered with a router.
An inline span is checked as a route when it starts with /api/, /v1/ or /v2/, contains no . or space, and has no placeholder marker. Both sides are normalised by dropping a ?query and a trailing /.
Script names (CK_DOC_STALE_COMMAND)
Section titled “Script names (CK_DOC_STALE_COMMAND)”| Span starts with | Checked against | Only when |
|---|---|---|
npm run X |
keys of scripts in the root package.json |
the root package.json parses as JSON |
just X |
recipe names in the root justfile |
a file named exactly justfile exists at the root |
make X |
target names in the root Makefile |
a file named exactly Makefile exists at the root |
For just and make, a target that starts with - (an option) is not checked.
- justfile recipes: every line that does not start with a space, tab or
#and contains a:. The recipe name is the first word before the:. Lines where that part contains=are ignored. - Makefile targets: every line that does not start with a tab,
#or.and contains a:. The target is the trimmed text before the first:, if it has no space.
Only the root manifests are read. Nested package.json files, Justfile and makefile are not.
CLI flags (CK_DOC_DEAD_FLAG)
Section titled “CLI flags (CK_DOC_DEAD_FLAG)”For a command span, the first word names the binary. Only its last path segment is used, so ./bin/tool --watch looks up tool. If that binary is known and has at least one known flag, every later word that starts with -- (and is longer than 2 characters) is cut at = and looked up. Unknown flags are reported. Short flags such as -v and positional words are not checked. Commands for unknown binaries, for example cargo build --release, are ignored.
CLI flag discovery
Section titled “CLI flag discovery”Binaries
Section titled “Binaries”CodeKnife walks the repository for manifests. The walk respects .gitignore, skips hidden entries, and skips directories named target, node_modules, .git, vendor, .codeknife and fixtures.
| Manifest | Binary names taken |
|---|---|
Cargo.toml |
every name = "..." inside a [bin] or [[bin]] section, plus [package] name when src/main.rs exists next to the manifest |
package.json |
if bin is a string, the package name with any @scope/ prefix removed; if bin is an object, its keys |
pyproject.toml |
the keys under [project.scripts] and [tool.poetry.scripts] |
go.mod |
the name of every directory directly under cmd/ at the repository root |
The codeknife binary is always known. Its flag set is every long flag of every CodeKnife subcommand, plus --help and --version. Flags are not tied to a subcommand, so codeknife docs --strip passes because comments has --strip.
Flags are collected from every non-test source file:
| Language | What is read |
|---|---|
| Rust | Only files that contain clap, #[arg( or Arg::new. Every long = "name" or long("name"). For an #[arg(...)] line that contains long without an explicit name, the next pub name: ... field becomes --name (underscores turned into dashes). |
| Python | Every --name on lines that contain add_argument, click.option or typer.Option. |
| TypeScript, JavaScript | Every --name on lines that contain .option( or .options(. |
| Go | The first string argument of flag.Xxx("name", ...) or Flags().Xxx("name", ...), as --name. |
All flags found anywhere in the repository are pooled. Every discovered binary gets the whole pool, plus --help and --version. If no flags are found at all, discovered binaries have an empty set and their commands are not checked.
| Rule ID | Severity | Trigger | Impact | --strict |
Fixer |
|---|---|---|---|---|---|
CK_DOC_DEAD_PATH |
warning | Link target or inline path does not exist | 45 for links, 40 for inline paths | no change | yes, links only |
CK_DOC_DEAD_SYMBOL |
warning | A::b span with no matching item |
40 | no change | no |
CK_DOC_DEAD_FLAG |
warning | --flag not defined by the named binary |
40 | no change | no |
CK_DOC_DEAD_ROUTE |
info | /api/, /v1/, /v2/ route not in code (needs 2 or more route strings in code) |
35 | no change | no |
CK_DOC_STALE_COMMAND |
warning | npm run, just or make target missing |
35 | no change | no |
No rule has a config key or numeric threshold. The full catalogue is in the Rule Catalogue.
Autofix
Section titled “Autofix”codeknife fix has a safe fixer for CK_DOC_DEAD_PATH. For each dead Markdown link, it takes the file name of the target. If exactly one source file in the code model has that file name, it rewrites the link target to the relative path from the Markdown file to that source file.
codeknife fix (write): applied 1 patch(es) across 1 file(s), 0 reverted (1 pass(es)) [FIX] CK_DOC_DEAD_PATH | Rewrite broken link `lib/routes.ts` -> `../web/routes.ts` in docs/guide.mdThe fixer does not touch inline code paths. It cannot repair links to Markdown, images or other non-source files, because the code model only holds source files. If two source files share the file name, the link is left alone.
Flags and configuration
Section titled “Flags and configuration”codeknife docs has no flags of its own. The global flags --path, --format, --changed, --since, --no-cache and --max-items apply; see the CLI Reference. --strict has no effect on this blade.
There is no [docs] table in codeknife.toml. [blades] docs = false skips this blade inside codeknife check, but codeknife docs still runs all checks. See codeknife.toml.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 |
No warning findings remain after the baseline is applied. CK_DOC_DEAD_ROUTE alone is info and passes. |
1 |
At least one warning. The demo exits 1. |
2 |
CodeKnife failed, for example an invalid codeknife.toml. |
Findings in codeknife.baseline are filtered out first. See Ratchet Baseline and Output Formats & Exit Codes.
Also available via
Section titled “Also available via”codeknife checkruns this blade with the samecodeknifeflag list.- The MCP tool
codeknife_checkruns the same suite, andcodeknife_fixruns the link fixer. See MCP Tools.