Graph Guided Code Reading
Save tokens by reading the codebase as a dependency graph, not as a pile of files.
Core Principle
Most repo-reading waste comes from opening too many files too early. Build a small relevance graph first, then read only the nodes that matter.
Minimal Relevance Graph
For each task, identify only:
- the user-visible entrypoint or changed surface;
- the owning module or service;
- the direct dependencies and dependents that shape behavior;
- the nearest tests, config, or contracts that constrain the change.
Stop expanding once the next action is clear.
Reading Workflow
- Start from the highest-signal anchor:
- changed files;
- failing test;
- route, command, job, or entry function;
- exact symbol or error text.
- Build a compact focus set:
- entrypoint;
- implementation module;
- adjacent callers/callees or imports;
- validating tests.
- Read narrow slices around the relevant symbols first.
- Expand one edge at a time only if the current node does not answer the question.
- Maintain a short checked-location ledger so files are not reopened without a reason.
Preferred Tools
- If a repo graph, repomap, AST, or change-impact tool exists, use it first.
- If not, emulate graph reading with:
rg for symbol ownership;
git diff --name-only or failing-test paths for anchors;
- imports, call sites, and config references for edges;
- nearby tests for behavior contracts.
Task Patterns
PR Review
- Start with changed files and public interfaces.
- Trace immediate blast radius: callers, consumers, schemas, tests.
- Review the impact set before reading unrelated modules.
Debugging
- Start from the failing surface and walk inward.
- Prefer one causal path over opening every suspected file.
- Keep hypotheses tied to specific nodes in the focus set.
Architecture Questions
- Start from entrypoints and major seams, not internal helpers.
- Build a compact service/module map before diving into implementation details.
Long Audits
- Partition the codebase into focused subgraphs.
- Finish one subgraph with evidence before opening the next.
Guardrails
- Do not force graph formalism on tiny repos where two files answer the question.
- Do not skip critical config, generated interfaces, or migration boundaries when they affect behavior.
- Do not keep expanding the graph after the winning path is already clear.
Final Report
Include the focus set, the decisive nodes, what was not read, and any remaining uncertainty at the edges.
1---2name: graph-guided-code-reading3description: Reduce repository-reading token waste by navigating code through symbols, entrypoints, dependencies, changed files, and blast radius instead of broad whole-tree or whole-file reading. Use on medium-to-large repos, PR reviews, architecture questions, onboarding, debugging across modules, or long-running audits.4license: MIT5---67# Graph Guided Code Reading89Save tokens by reading the codebase as a dependency graph, not as a pile of files.1011## Core Principle1213Most repo-reading waste comes from opening too many files too early. Build a small relevance graph first, then read only the nodes that matter.1415## Minimal Relevance Graph1617For each task, identify only:1819- the user-visible entrypoint or changed surface;20- the owning module or service;21- the direct dependencies and dependents that shape behavior;22- the nearest tests, config, or contracts that constrain the change.2324Stop expanding once the next action is clear.2526## Reading Workflow27281. Start from the highest-signal anchor:29 - changed files;30 - failing test;31 - route, command, job, or entry function;32 - exact symbol or error text.332. Build a compact focus set:34 - entrypoint;35 - implementation module;36 - adjacent callers/callees or imports;37 - validating tests.383. Read narrow slices around the relevant symbols first.394. Expand one edge at a time only if the current node does not answer the question.405. Maintain a short checked-location ledger so files are not reopened without a reason.4142## Preferred Tools4344- If a repo graph, repomap, AST, or change-impact tool exists, use it first.45- If not, emulate graph reading with:46 - `rg` for symbol ownership;47 - `git diff --name-only` or failing-test paths for anchors;48 - imports, call sites, and config references for edges;49 - nearby tests for behavior contracts.5051## Task Patterns5253### PR Review5455- Start with changed files and public interfaces.56- Trace immediate blast radius: callers, consumers, schemas, tests.57- Review the impact set before reading unrelated modules.5859### Debugging6061- Start from the failing surface and walk inward.62- Prefer one causal path over opening every suspected file.63- Keep hypotheses tied to specific nodes in the focus set.6465### Architecture Questions6667- Start from entrypoints and major seams, not internal helpers.68- Build a compact service/module map before diving into implementation details.6970### Long Audits7172- Partition the codebase into focused subgraphs.73- Finish one subgraph with evidence before opening the next.7475## Guardrails7677- Do not force graph formalism on tiny repos where two files answer the question.78- Do not skip critical config, generated interfaces, or migration boundaries when they affect behavior.79- Do not keep expanding the graph after the winning path is already clear.8081## Final Report8283Include the focus set, the decisive nodes, what was not read, and any remaining uncertainty at the edges.