Sanoj

Blog

Your dead-code detector cries wolf — I measured how often on three repos

Title card reading "Your dead-code detector cries wolf — I measured how often on three repos." Below it, three bars: knip flagged 81 things and 0 were dead, vulture flagged 27 and 2 were dead, vulture flagged 36 and 7 were dead — 144 flagged out of the box, 9 dead. A final line reads: Configuring knip and re-running vulture found 2 more: 11 dead, 26 lines, in total.

Every codebase has dead code in it. Functions nobody calls, settings nobody reads, whole files that stopped mattering three refactors ago. The tools that find it — knip for JavaScript and TypeScript, vulture for Python — are good tools, and I have run both of them on my own repos expecting a tidy list of things to delete. What I got instead was a lesson in what "unused" means to a static analyser, and how far that is from what it means to a human.

I ran the two tools on three of my own repositories, counted every finding, and then checked every single one by hand — grepping for real uses, reading the code around each flag, and deleting the survivors in a scratch copy and running the test suite to prove the deletion was safe. The headline number: 144 things flagged out of the box, 9 actually dead. Ninety-four percent of what the tools reported was code that is alive. And the story does not end there: configuring knip properly surfaced one more dead item the raw run had missed entirely, and re-running vulture after the first deletions surfaced another — 11 dead in total, 26 lines of code. The tools are not broken. They are answering a different question than the one I asked, and the gap between the two questions is the whole story.

What I ran

Three repos, two tools, no configuration at first — I wanted the out-of-the-box experience, the one most people actually get:

RepoLanguageToolVersion
sine-portfolio (this site)JavaScriptknip5.88.1
retriever-doc-answer (my retrieval API)Pythonvulture2.16
jokeGPT (my tiny joke model)Pythonvulture2.16

The commands were the ones from each tool's own docs:

Shell

npx knip
vulture app tests --min-confidence 60
vulture app experiments --min-confidence 60

Vulture assigns every finding a confidence — 100% for unused function arguments and unreachable code, 90% for imports, 60% for everything else — and its own docs call the 60% figure a "very rough estimate". I ran it with --min-confidence 60, which reports everything it finds, since 60 is the lowest confidence it assigns. Knip has no confidence score; it reports what its module graph says is unreferenced. Both tools exit non-zero when they find something, which is how you would wire them into CI — and, as it turns out, how you would wire a 94% false-positive rate into CI.

One definition before the numbers: a finding is a false positive if the code it flags actually runs — called, read, imported, serialized, or executed through some mechanism the tool cannot see. A finding is genuinely dead only if nothing in the repo uses it in any way. I am measuring precision on the flagged items, not recall: code the tools never flagged is outside this experiment.

Knip on sine-portfolio: 81 findings, 0 dead

Knip's first run, with no configuration file at all, reported 63 unused files, 17 unused exports, and 1 unused devDependency. Eighty-one findings. I checked all of them, and not one was dead code.

Start with the 63 "unused files." They were not dead. They were the dev-only apps — the letter designer, the page measurer, the portrait tracer — plus the scripts that build and check the site. Knip traces a module graph from entry points, and with no configuration it guesses the entries from package.json. My site's real entries are not files in package.json: the site loads from index.html script tags, the dev tools are served by a dev server, and the build scripts are invoked by npm commands. Knip could not see any of that, so it concluded that most of the repo is unreachable. The files are not unused. The graph is incomplete, and knip reported the incompleteness as findings. So I configured it — a knip.json with entry (where execution starts) and project (what counts as the codebase), declaring the four app mains, the scripts, the dev server, and the loader main:

JSON

{
  "entry": [
    "apps/site/app/main.js",
    "apps/designer/app/main.js",
    "apps/measure/app/main.js",
    "apps/portraits/app/main.js",
    "scripts/*.js",
    "server/dev-server.js",
    "src/widgets/loader/main.js"
  ],
  "project": ["apps/**/app/**/*.js", "scripts/**/*.js", "server/**/*.js", "src/**/*.js"]
}

The unused files dropped from 63 to 0. But the unused exports went up, from 17 to 30, and 16 imports showed up as unresolved. The site imports its own core modules with root-relative paths — import { PageCanvas } from '/core/index.js' — which the dev server and the build resolve to src/core/, but knip could not resolve at all. Sixteen imports severed, and everything downstream of one looks unused. The export count did not go up because there was more dead code. It went up because the graph got bigger while staying broken.

One more line — a path mapping, the same idea as TypeScript's paths — fixed that too:

JSON

"paths": {
  "/core/*": ["./src/core/*"],
  "/widgets/*": ["./src/widgets/*"]
}

Now: 0 files, 24 exports, 0 unresolved imports. Three runs, same repo, same code:

Knip runUnused filesUnused exportsUnresolved imports
No config63170
Entries declared03016
Entries + path mapping0240

The number of findings is a function of the configuration, not of the code. Nothing in the repo changed between these runs. If you take one lesson from this post, take this one: never quote a dead-code tool's count before you have configured its entries and its module resolution, because the count measures your configuration.

But 24 unused exports remained, and one unused devDependency. Were any of those real? I grepped every one. Twenty-three of the 24 exports are used — inside their own file. findChrome is called by launchChrome in the same file. decodeGif is called by gifFirstFrame, and pngSize, gifSize, and jpegSize by imageSize, all in the same file. parseFrontMatter and parseBlocks are called by parseMarkdown in the same file. The designer config's UPPER, DIGITS, PUNCT, and SYMBOLS are combined into SETS just below where they are defined. Knip flags the export, not the code: the function runs, but nothing outside its file imports it, so the export keyword is unnecessary. The honest fix for most of these is not deletion — it is un-exporting. Deleting the function would break the file that uses it. The tool said "unused export" and it was right about the export and wrong about everything a reader would infer from it.

The devDependency was the same shape of story. Knip flagged axe-core as unused — no file imports it. But scripts/check-a11y.js loads it by file path and injects it into the checked pages. A dependency consumed by path instead of by import is invisible to an import graph, and it is the accessibility check this site runs on every push.

That left one export out of 24. The loader's config exports BACKGROUND = '#181818', and nothing imports it — not the loader, not the site, not anything. The colour lives as a literal in apps/site/index.html, where #sine-loader and body both set background: #181818. The config value is a duplicate that nothing reads. One genuinely dead export, one line — and the raw run never found it at all: it had flagged the file that contains it as "unused" and never looked at the export. Configuring the tool did not just cut the noise from 81 findings to 25. It found the one real item.

Three knip runs on the same unchanged repo: with no config, 63 unused files and 17 unused exports; with entries declared, 0 files, 30 exports, 16 unresolved imports; with entries and a path mapping, 0 files, 24 exports, 0 unresolved imports. Only 1 of the 24 exports is actually dead.
Text description of this diagram

Bar chart of knip's three runs on sine-portfolio. Run 1, no config: 63 unused files, 17 unused exports. Run 2, entries declared: 0 unused files, 30 unused exports, 16 unresolved imports. Run 3, entries plus a path mapping for /core/* and /widgets/*: 0 unused files, 24 unused exports, 0 unresolved imports. Of the 24 exports in run 3, 23 are used inside their own file and 1 — BACKGROUND in the loader config — is genuinely dead.

Vulture on the Python repos: 63 findings, 9 dead out of the box

Vulture's story is different from knip's but rhymes with it. It found 27 things in retriever-doc-answer and 36 in jokeGPT. Nine of the 63 were actually dead on the first pass, and a tenth surfaced when I re-ran after deleting — the mechanism for that is below. The other 54 fall into three buckets, and the buckets are the interesting part, because they are the same in every FastAPI + Pydantic codebase.

Bucket one: route handlers. Seven functions in jokeGPT and four in retriever-doc-answer are FastAPI endpoints — get_corpus_stats, run_experiment, list_experiments, health, start_training. Vulture flags them because no Python code calls them by name. No Python code ever calls them by name: they are called by HTTP requests, through a decorator. If you delete a flagged route handler, your API loses an endpoint — and the tests, which call it over HTTP, would catch it, which is the point of the verification step below.

Bucket two: model fields. Pydantic models are the other big source. recall_at_1, mrr, gold_ranks, posts_detail, preview, status, version — fields of response models, never read by attribute name in the code. They are read by serialization: FastAPI turns the model into JSON, and the field names (or their aliases, like recall@1) appear as keys in the response. Vulture sees a name that is defined but never referenced as a name, and reports it. The field is the API contract. Deleting it changes what clients receive.

Bucket three: code outside the scanned tree. quality_signals, generate_batch, and save_runs in jokeGPT are called from scripts/run_experiments.py and run_v2.py — experiment scripts I did not include in the vulture command. pad_id is used in a test. The tool can only judge what you point it at: my scan covered app/ and experiments/, not scripts/ or tests/. A configuration gap, not a finding.

What was actually dead, then? In retriever-doc-answer, two settings in config.py that nothing reads: default_chunk_size and min_chunk_words. In jokeGPT, seven items on the first pass: the TERMINAL_PUNCT constant (defined, never referenced), the train_val_split and sample methods on the corpus repository (never called), both from_file classmethods on the tokenizers (never called — the only other mention is a line in the module docstring listing the API, which is documentation, not a use), and two more unread settings, visuals_dir and grad_clip.

And then the eighth. After deleting the first seven in a scratch copy and re-running vulture, a new finding appeared: train_split, another setting in config.py, never read by any code. It had not been flagged the first time, because the train_val_split method I had just deleted had a parameter also named train_split — and vulture's analysis is name-based, not scope-aware. Vulture's docs say to re-run after each deletion because it "may discover more dead code." Here is the mechanism, measured: the name train_split was defined in exactly two places, one of them dead, and the dead one was hiding behind the other.

Funnel: 144 raw findings across the three repos narrow to 9 genuinely dead items out of the box — 0 in sine-portfolio, 2 in retriever-doc-answer, 7 in jokeGPT. Configuring knip and re-running vulture found 2 more, for 11 dead in total and 26 lines of code.
Text description of this diagram

Funnel diagram. Top: 144 raw findings — knip on sine-portfolio 81, vulture on retriever-doc-answer 27, vulture on jokeGPT 36. Middle: after triage, 135 false positives and 9 genuinely dead out of the box — 0 in sine-portfolio, 2 in retriever-doc-answer, 7 in jokeGPT. Bottom: configuring knip found 1 more dead export and re-running vulture found 1 more dead setting, for 11 dead in total, 26 lines of code.

Verification: delete it in a scratch copy, run the tests

A grep is evidence, not proof. The proof is deleting the code and watching the tests. For each repo I copied it to a scratch directory, deleted only the items triage had marked dead, and ran the full test suite — before and after, so the baseline is measured, not assumed:

RepoDeletedTests beforeTests afterFindings after
sine-portfolioBACKGROUND (1 line)check:blog, build:dist, check:a11y all passall pass, 0 a11y violationsknip 25 → 24
retriever-doc-answer2 settings66 pass66 passvulture 27 → 25
jokeGPT8 items, two passes26 pass26 passvulture 36 → 30 → 29

The test suites passed unchanged, which is exactly what "dead" means: nothing in the repo depended on that code. Note one asymmetry: the Python suites are real tests — 66 and 26 tests that exercise the API, the services, and the tokenizers. The sine-portfolio checks are the build and the accessibility audit: they prove the site still builds and the blog still renders, but the designer and portrait apps that hold most of the flagged exports have no test suite at all. Deleting BACKGROUND is safe because nothing imports it, which is a graph fact, not a test fact. For code with no tests, the verification step is weaker, and the honest thing is to say so rather than claim the tests proved it. I have not deleted any of it in the real repos, by the way — that goes through a pull request like everything else.

Five ways "unused" is alive

Every false positive in this experiment is one of five mechanisms. If you run a dead-code tool and get a long list, check these five first — they account for 135 of my 144 raw findings:

MechanismHow it hidesExample
Same-file useExport used only inside its own file; the tool flags the exportfindChrome, called by launchChrome in chrome.js
Framework plumbingCalled by the framework, not by your codeFastAPI route handlers; Pydantic model_config and model fields
Loaded by pathConsumed by file path, not by importaxe-core, read from node_modules by check-a11y.js
Name shadowingA shared name elsewhere shields a dead definitiontrain_split, hidden behind a dead method's parameter
Undeclared entriesDev tools, scripts, and HTML-loaded code outside the tool's graphAll 63 "unused files" in knip's first run
Five boxes, one per mechanism, each with its real example from the experiment: same-file use (findChrome), framework plumbing (FastAPI routes), loaded by path (axe-core), name shadowing (train_split), undeclared entries (63 files).
Text description of this diagram

Five labelled boxes in a row. Same-file use: the export is used inside its own file — findChrome is called by launchChrome in chrome.js. Framework plumbing: the framework calls it, not your code — FastAPI route handlers and Pydantic model fields. Loaded by path: consumed by file path, not import — axe-core, read from node_modules by check-a11y.js. Name shadowing: a shared name elsewhere shields a dead definition — the train_split setting, hidden behind a dead method's parameter. Undeclared entries: code outside the tool's graph — all 63 "unused files" in knip's first run.

The pattern across all five is the same: the tool sees the code, not the system the code runs in. The program includes the framework, the build, the dev server, the HTML, the HTTP requests from outside, and the JSON that leaves. "Unused" means "unreferenced in the graph I built" — and the graph is always smaller than the program.

What dead code actually looks like

The 11 genuinely dead items have a shape, and it is not the shape of the false positives. They are small, boring, and old: settings wired up for a feature that never used them (default_chunk_size, min_chunk_words, grad_clip, visuals_dir, train_split), two convenience methods written for an experiment that moved on (train_val_split, sample), two loaders for a format nobody loads (from_file twice), a constant from an earlier version of a check (TERMINAL_PUNCT), and a duplicated colour (BACKGROUND). Dead code is not the function you are afraid to delete. It is the setting you added "just in case" and the helper you wrote for a script you rewrote — the boring-looking code, not the scary-looking code. The fear runs the wrong way: the route handlers look deletable, small functions with no callers in the code, and deleting one takes down an API endpoint. The settings look trivial, and deleting them changes nothing.

There is a coda to this from other people's measurements. Google's Sensenmann system, which deletes dead C++ at Google, submits over a thousand deletion changelists a week and had removed nearly 5% of all C++ at Google when its team wrote it up — and the team that deleted a monolith's endpoints by traffic logs was warned, in the top-voted comment, that three months of logs is "an eye blink": the code you delete may only run at year-end, during audits, or for one special customer. The same warning applies at my scale: the tools tell you what is unreferenced, and only you know what is unreferenced and unneeded.

The skill: dead-code-hunt

I turned the workflow from this experiment into a skill, dead-code-hunt, in the skills repo. It does the mechanical part deterministically and leaves the judgement to you:

Shell

python3 scripts/dead-code-hunt.py audit . --tool vulture --vulture-paths app --min-confidence 60 --json report.json
python3 scripts/dead-code-hunt.py audit . --tool vulture --vulture-paths app --min-confidence 60 --json report2.json --baseline report.json

The audit runs knip and/or vulture — installed separately; the script only shells out to them — classifies every finding with the five mechanisms above — same-file use, framework plumbing, path loading, name shadowing, undeclared entries — and prints a triage table with the evidence for each verdict. It exits 1 while anything is still marked DEAD and 0 when the triage is clean. The --baseline run diffs against a previous report and highlights newly revealed findings, which is how the train_split case surfaces instead of hiding. The skill never deletes anything itself: the verify step is yours — delete in a scratch copy or a branch, run the test suite, re-run the audit, and only then delete for real. The full workflow and the test fixtures are in the skill folder.

Four-step workflow diagram: detect (144 findings), configure (entries and paths; knip 81 to 25), triage (135 alive, 9 dead out of the box), verify (delete in a scratch copy, tests green, re-run). Each step shows the count that survives it.

The workflow, step by step: detect — 144 raw findings; configure — entries and path mapping take knip from 81 to 25; triage — 135 alive, 9 dead out of the box; verify — delete in a scratch copy, tests green, re-run and catch what the first pass missed.

Three frames: pass 1 finds 36 items and 7 are dead; deleting those 7 reveals train_split, which the first pass missed; pass 2 finds 30 items and train_split is the 8th dead item — deleting it leaves 29. Vulture's name-based matching hid it behind a dead method's parameter of the same name.

The second pass: vulture's first run on jokeGPT found 36 items, 7 dead. Deleting those 7 revealed an eighth — the train_split setting, which the first run missed because a dead method's parameter shared its name. Pass 2 found 30 items; deleting train_split leaves 29. Re-running after each deletion is not hygiene; it is how the tool's blind spot gets corrected.

The catch

Two limits, stated plainly. First, everything in this post is precision, not recall. I measured how often the tools are right about the things they flag. I did not measure how much dead code they never flag, and in a dynamic language that number is not small: a function imported but never called at runtime, a branch that can never be true, a plugin registered by string name — none of those appear in either tool's output. A clean audit is not a clean codebase; it is a codebase with no flagged dead code.

Second, the numbers are mine: three small repos, two tools, one afternoon. A large TypeScript monorepo with proper knip plugins, or a Python codebase without a framework, would give different rates — one published measurement found 12 of 16 flagged exports alive on repomix, the same shape of result at a different scale. Your rate will differ. The way to know it is the way I did it here: run the tool, check every finding by hand once, and count. An afternoon of triage buys you a calibrated tool instead of a noisy one.

Sources

  • Knip documentation — knip.dev (configuration: entry and project, path mapping, and the guide to handling issues, which recommends working through unused files, unresolved imports, unused exports, and unused dependencies in that order).

  • Vulture documentation — pypi.org/project/vulture (confidence levels, whitelists, --ignore-decorators, and the advice to re-run after each deletion).

  • Google Testing Blog, "Sensenmann: Code Deletion at Scale" — testing.googleblog.com (April 28, 2023; over 1,000 deletion changelists a week, nearly 5% of all C++ at Google).

  • Repowise, "TypeScript unused exports: what 52 popular TS repos carry" — dev.to (November 2026; knip on repomix at one commit: 113 "unused" files, none actually dead, and 16 unused exports, 12 of which were actually used).

  • The experiment data behind this post — the raw knip and vulture outputs and the triage script — is attached to the post as downloads: knip-sine-raw.txt, knip-sine-configured.txt, knip-sine-paths.txt, vulture-retriever.txt, vulture-jokeGPT.txt, dead-code-triage.py. The skill is dead-code-hunt.

All notes