What breaks if I change this file?

Grep tells you where a name appears. It does not tell you what depends on this file. A bounded static source graph answers the question, names the path, and reports what it could not resolve.

The question

You are about to change a function signature. Before you do, you want to know what breaks.

The instinct is to grep for the function name. That gives you occurrences, not dependencies. It misses re-exports, aliased imports, dynamic imports, and every consumer that imports the module rather than the symbol.

The useful answer is a source graph: a bounded model of "this file references that file," good enough to scope a change and honest about what it cannot resolve.

A changed file is not a bug. The graph reports the path; it does not prove the dependant is broken.

Diagram: a changed src/db/schema.ts reaches src/repositories/user.ts, src/api/users/[id]/route.ts, src/app/dashboard/page.tsx, and tests/integration/user.test.ts through resolved imports. A cross-package edge from packages/billing/src/charge.ts and a dynamic boundary in src/plugins/loader.ts are also shown.
One changed root, five dependants. The graph names the path; it does not prove a bug.

Why grep lies

Consider a small TypeScript module with a barrel file:

// src/payments/index.ts
export { charge } from './charge.js';
export type { ChargeResult } from './types.js';

// src/api/checkout.ts
import { charge } from '../payments/index.js';
checkout.ts never names charge.ts. It names the barrel.

A grep for `charge` finds both files and every unrelated use of the word. It does not tell you that changing `charge.ts` breaks `checkout.ts` through the barrel. A source graph does, because it records edges between resolved files, not between strings.

Dynamic imports make it worse. `import('./plugins/${name}.js')` is not a single edge; it is a pattern that may resolve to many files or none. The honest response is to record a dynamic boundary and say so, not to guess.

The graph

Building the graph is four bounded steps.

1. Inventory

Walk the repository under the ignore rules: .gitignore, .npmignore, default noise. Produce a file list with paths and kinds. Nothing is analyzed yet. This step answers "what exists," not "what it means."

2. Workspaces and project boundaries

A monorepo is not one project. package.json files, pnpm-workspace.yaml, go.work, Cargo.toml, and pyproject.toml mark ownership boundaries. Imports that cross a boundary are still edges, but they are labeled. A change that fans out across five packages is a different risk from one that stays inside a single package.

3. Resolution

For each source file, extract its references and resolve each one to a concrete file, or record why it could not be resolved. This is the step that differs per language. It is also the step where most tools silently give up.

4. Impact

Given a changed set, walk the graph to its reverse-reachable set. That set is the blast radius. Report it with the edges that got you there, so a human can check the walk. The report preserves the full impacted-file count while serializing only bounded impact records.

Changed: src/payments/charge.ts
Blast radius (3 files, 2 boundaries):
  src/payments/index.ts          via  export { charge } from './charge.js'
  src/api/checkout.ts            via  import { charge } from '../payments/index.js'
  packages/billing/src/charge.ts via  cross-package: @app/payments
Unresolved: 1 dynamic boundary in src/plugins/loader.ts
A useful impact report names the path, not just the file count.

The disposable demo prints the same shape:

src/config.ts → src/db.ts
src/config.ts → src/db.ts → src/jobs.ts
src/api/route.ts → src/server.ts
Codebase Doctor demo. The fixture is removed afterward.

The path proves only the static edge chain. It does not prove the dependant is broken. That distinction is the whole product.

What it refuses to guess

A graph that guesses is worse than a graph that says "unknown." The graph module is finding-free by design. A separate source-integrity doctor reports one rule, `source/import-target-missing`, and only for four proof classes:

  • An explicit relative target with a supported source extension.
  • A single deterministic alias whose configured target explicitly names a supported source file.
  • A unique workspace package whose explicit entry names a supported source file.
  • An internal Go package under a module path without a replace directive.

Extensionless, JSON, custom-loader, conditional, ambiguous, external, and dynamic references are not findings. Cycles are valid topology. It does not check named exports or validate that a referenced export name exists.

Raw import specifiers and source text are withheld; findings expose normalized paths, import kind, proof class, and a safe location. At most 1,000 findings per audit, with partial coverage whenever that ceiling or any graph limitation applies.

[high] source/import-target-missing src/api/route.ts:2
  proof: explicit relative target
  target: src/server.ts — not present in the inventory
A proof class, a normalized path, and a safe location. No guessed import specifier.

That is the difference between a scanner and a reviewer: a scanner can report a clean result on a file it never parsed. This one cannot.

The receipts

The graph is only useful if it is measured. The repository ships three independent checks:

  • Benchmark: 17 seeded single-defect fixtures, 16/16 expected rule matches (100% recall), zero medium+ false positives, 2/2 review verdicts, 1/1 suppression honesty.
  • Red team: 18 adversarial cases, 11/11 mutants caught, 7/7 controls clean.
  • Field study: 100 agent-configured public repositories, 23% with at least one high-severity finding, 10% with a broken import target.
check                         result
cases passed                  17/17
expected rule matches         16/16 (100%)
medium+ false positives       0
review verdicts               2/2
suppression honesty           1/1
red-team mutants caught       11/11
red-team controls clean       7/7
Measured, not asserted. The harness is deterministic: no network, no model, no database.
Bar chart of 100 agent-configured repositories: 23% had at least one high-severity finding, 11% risky agent configuration, 10% a broken import target, 4% private key material, 1% a committed provider token.
The field study is a convenience sample, not a census. Shallow clones mean the history number is a floor.

The differential scoreboard is the honesty check: two independently written offline analyzers over the same SQL corpus, 10 findings matched, 0 severity mismatches, 1 documented coverage difference, safe schema clean under both.

What the graph cannot see

The value of the tool is bounded by its honesty about limits.

  • Reflection and runtime wiring. A dependency-injection container that resolves a type by name is not a static edge. The graph says dynamic boundary and stops.
  • Generated sources. Code emitted at build time is not in the inventory unless you point the tool at the output directory.
  • Cross-language edges. A TypeScript file that shells out to a Python script is a process boundary, not a source edge.
  • Semantic impact. Knowing that A imports B does not mean a change to B is safe for A. A signature-preserving refactor and a behavior change look identical to the graph.
  • Partial coverage. A bounded scan says so with exact total, emitted, and omitted counts. A clean run means the scope was checked, not that the code is bug-free.

Any report that claims a clean blast radius without listing unresolved boundaries is reporting confidence it has not earned.

Where this fits

This is not a type-checker, a linter, or a runtime dependency graph. TypeScript catches type errors; ESLint catches style and correctness patterns; tests catch behavior. The source graph answers a narrower question: which files can reach this one through static imports?

That question is cheap to answer before a merge and expensive to answer after an incident. It is also the question a coding agent should ask before editing a file it did not write.

tool              question
grep              where does this string appear?
linter            does this pattern match a rule?
type-checker      does this program type-check?
test suite        does this behavior hold for these fixtures?
source graph      which files can reach this change?
Different layers, different answers. None of them is a proof of correctness.

Reproduce this

The reproduce block uses commit `d56638a`; the benchmark and field-study snapshots are dated 2026-10-09.

git clone https://github.com/subhajitlucky/codebase-doctor
cd codebase-doctor
git checkout d56638a
npm ci
npm run build
node dist/cli.js demo
node dist/cli.js audit . --changed --format brief
The demo builds a disposable fixture, proves a broken import and a secret, prints the blast radius, and exits 1.
codebase-doctor brief
scope=changed findings=3 shown=3 coverage=incomplete score=70
[high] source/import-target-missing src/api/route.ts:2 — ...
[high] security/secrets/provider-token src/config.ts:6 — ...
[info] repository/no-visible-tests (repository) — ...
coverage-limitations: repository: partial, backend: not-selected, database: skipped, performance: partial
The coverage line is part of the result, not an afterthought.

The benchmark harness is `node scripts/benchmark.mjs`; the red-team corpus is `node scripts/red-team.mjs`; the field study is `node scripts/study-agent-repos.mjs` with a GitHub token.

Codebase Doctor on GitHubSource, architecture, benchmark harness, red-team corpus, and the field-study script.npm packageInstall-free usage: npx -y codebase-doctor audit . --changed --format brief.

What to do with this

The architecture contractThe full source-graph, coverage, precision, and bounded-report contract.