Dead Code Definition: The Essential Guide for Engineers
Part of the Dead Code guide. Start with The function passed its test. The application never called it.
Dead code is code whose removal preserves the program's observable behavior for the inputs and configurations you support, including its outputs, state changes, exceptions, and external interactions. Code after an unconditional return is one example. Code that runs can be dead too.
The difficult word is observable. A calculation's result might go unread while the call that produced it still rejects a request, writes an audit record, registers a handler, or changes shared state.
I wouldn't approve a deletion from a missing-reference result alone. First I'd want to know what the search covered.
Dead, unreachable, and unused mean different things
| Term | What it tells you | What still needs checking |
|---|---|---|
| Unreachable code | Execution cannot reach it under the conditions being considered. | Whether those conditions cover the supported configurations. |
| Unused value | Nothing reads that value. | Whether evaluating its initializer has effects. |
| Unused function candidate | An analysis found no relevant caller. | Entry points and consumers outside the analysis. |
| Dead code | Removing it preserves observable behavior within the stated scope. | Whether the evidence supports that conclusion. |
This distinction also exists in compiler work. LLVM's dead-instruction check considers both use and side effects, while its global elimination pass works on unreachable internal globals, a scope that matters when you're reviewing an exported library function, a public endpoint, or anything with consumers beyond one repository.
A deprecated function can still have callers. A recovery command can still be needed even if nobody ran it recently. Neither label settles the deletion question.
Five examples, with different deletion checks
These are illustrative TypeScript snippets, not captures from a production repository.
A statement after return
function status() {
return "ok";
const debug = "never runs";
}
The ECMAScript return rules explain why this function exits before reaching the declaration.
tsc can report this with allowUnreachableCode set to false (TypeScript option reference).
The check is syntactic: it flags statements that can't run inside a function, not a function that nothing in the application calls.
A value that nobody reads
function invoiceTotal(subtotal: number, tax: number) {
const debugTotal = subtotal + tax;
return subtotal + tax;
}
For numeric arguments, the first addition contributes nothing to the returned total, changes no state, and has no other observable effect, so the declaration can go. The second addition supplies the return value and stays.
tsc flags unread local variables with noUnusedLocals. Check initializer effects separately.
A call whose return value is ignored
function validateUserOrThrow(active: boolean) {
if (!active) {
throw new Error("Inactive user");
}
}
function handler(active: boolean) {
validateUserOrThrow(active);
return "accepted";
}
Deleting validation accepts an inactive user. Ignoring a return value doesn't erase a call's exception.
A branch behind a constant
const DEBUG = false;
if (DEBUG) {
console.log("Debug tracing enabled");
}
In this snippet, the body cannot run because the condition is false. When reviewing an actual feature flag, check its value in every supported configuration, including deployment overrides, before deciding the branch is dead.
A helper with a caller, inside an unused feature
function oldLabel() {
return oldPrefix() + " invoice";
}
function oldPrefix() {
return "legacy";
}
Suppose these are private helpers, no entry point reaches oldLabel, and neither name is loaded dynamically. Both are dead within that application, even though oldPrefix has a caller, because that caller is itself unreachable, which is why counting references alone won't resolve the example.
rg can find the names. It can't determine whether the callers it finds are reachable.
Start with a check you can inspect
With your project's TypeScript compiler available on your shell's PATH, run this from the directory containing its configuration:
tsc --noEmit --noUnusedLocals --allowUnreachableCode false
tsc uses the project's configuration when you supply no input files, so the command checks that project, including its existing settings, without emitting JavaScript, as the CLI reference describes. It doesn't prove repository-wide disuse.
For a suspicious function, a literal name search is another small check:
rg --fixed-strings --word-regexp 'oldLabel' .
rg treats the pattern literally and requires word boundaries with these flags, according to its own guide, but its default search skips ignored files and hidden paths, so qualify an empty result, even before considering callers that construct a name dynamically.
The TypeScript cleanup guide covers the larger repository workflow.
What Dead and Possibly unused look like in a real result
I build Pharaoh. Its get_unused_code tool reports Dead and Possibly unused separately. It also identifies exported functions Used only by tests.
This is a trimmed excerpt from get_unused_code, for the features/auth module in the public Pharaoh-so/cal.diy fork, revision 54343aa6, captured on October 26, 2026. Only whole lines were removed; the retained lines are unchanged.
# Unused code in cal.diy / features/auth: 3 dead, 4 possibly unused, 1 used only by tests
## Dead (3): unreached, named in no other file, file not imported
- PermissionContainer — packages/features/auth/PermissionContainer.tsx (14 LOC)
## Possibly unused (4): unreached, but named elsewhere or imported. Check before deleting.
### Named in `packages/features/auth/lib/next-auth-options.test.ts`, `packages/features/auth/lib/next-auth-options.ts` (1)
- signJwt — packages/features/auth/lib/signJwt.ts
## Used only by tests (1)
- deriveNameFromOrgUsername — packages/features/auth/signup/utils/getOrgUsernameFromEmail.ts
The counts describe the full result, not the three retained functions.
For Dead, every signal must agree. No modeled entry point reaches the function, no other file names it, and no production file imports its file, which is a stronger statement than finding no direct caller.
For Possibly unused, the function is unreached, but another file names it or imports its file. Here the result points to files naming signJwt, including a production file, so I'd open those files, inspect how the name is used, and resolve the loading path before removing it.
Pharaoh maps TypeScript, JavaScript, Python, C and C++ repositories, using the default branch, so uncommitted changes and other branches aren't included, and the result doesn't establish what an external consumer does. C and C++ functions are never labeled Dead or Possibly unused.
What I'd put in the deletion review
Pick one candidate and write down the scope of the claim. For an internal helper, identify the application's entry points, trace the possible paths, check the initializer or body for effects, and explain any remaining references in the review.

For a library export or public endpoint, establish who consumes the interface before removing it. A repository search doesn't cover somebody else's application.
Check the blast radius of the change when callers remain. If a feature has tests but no production path, the next question is whether to connect it or delete it; see code that passes tests but is never called. Then remove the smallest justified unit and run the relevant checks. Record what you verified, which consumers you checked, and any configuration assumptions, so the reviewer can assess the deletion rather than take the detector's label on trust.
To inspect that evidence on your own repository, set up Pharaoh, install the GitHub App for the account that owns it, connect your AI client, and ask for unused code in one module.