CodeGraph is a scout: it indexes a structural map, narrows the search, and explains relationships. It produces suspects, not proof. It does not validate behavior. codegraph build . means “the graph rebuilt,” not “the code passed.” codegraph check and diff-impact are structural checks, not substitutes for tests, typecheck, lint, or runtime verification.
Scout before reading broadly: find exact files/symbols, trace relationships, then read the narrowed source. For absence claims, scout first, then corroborate with exact search, source reads, and the project’s package/export boundaries.
Report in three ledgers: CodeGraph evidence, source-read interpretation, and proof commands/manual checks. Do not merge them.
CodeGraph sees static structure, not every live dependency. Watch for:
When one is in play, say so. Use CodeGraph to narrow the target, then use exact targeted search and source reads for the blind spot. Keep generated/schema-heavy results as a hint, not the report backbone: generated protocol files often prove a method/schema exists but not which app path handles it.
The CLI is the source of truth. Before using a flag not shown here, run codegraph help <command>.
-
Index and inspect graph health.
codegraph build .
codegraph stats -T
build is incremental by default. It records structure for later queries; it is not a lint/test/typecheck gate. Completion criterion: the graph exists, stats shows language/quality/cycle/hotspot data, and you know whether tests are excluded (-T) or included. Do not report this step as validation.
-
Orient before choosing files.
codegraph map -T
codegraph structure --depth 2 -T
codegraph triage -T --limit 20
To narrow a large repo, pass the directory positionally:
codegraph structure apps/server/src --depth 2 -T --limit 80
codegraph structure packages --depth 2 -T --limit 80
Completion criterion: you can name the likely modules, hotspots, and candidate files instead of guessing from filenames.
-
Pin exact targets.
codegraph where <symbol> -T
codegraph where --file <path> -T
codegraph brief <file> -T
If names are ambiguous, rerun with --file, --kind, or a file-level query. If where misses a local closure or property method after CodeGraph has named the file, use brief <file> plus a targeted exact search inside the narrowed area; record that the symbol edge was not visible. Completion criterion: every candidate has an exact path/line or a named CodeGraph blind spot with the narrowed file path.
-
Trace the relevant structure.
codegraph context <symbol> -T --file <path>
codegraph deps <file> -T --brief
codegraph deps <file> -T --json
codegraph exports <file> -T
codegraph path <symbol-from> <symbol-to> -T
codegraph dataflow <symbol> -T --file <path>
For concise dependency summaries, prefer deps --json and extract results[0].imports / results[0].importedBy instead of dumping every symbol consumer. For cycles, this is the primary way to prove which imports create each file edge.
For contract work, trace the spine as separate evidence: schema/type definition, method string or RPC tag, protocol/group assembly, server handler, client runtime wrapper, and app-surface adapters. If CodeGraph loses an edge at any spine segment, use a targeted exact search for that segment only, then read the narrowed files. Record the spine in the three ledgers.
Completion criterion: you know the real call/import/data path and have read the narrowed source needed to support any claim you will make.
-
Check blast radius before editing shared code.
codegraph fn-impact <symbol> -T
codegraph impact <file> -T
codegraph implementations <interface-or-trait> -T
codegraph interfaces <type> -T
Completion criterion: every shared function/API/model you plan to touch has its callers, dependents, implementors, and transitive risk accounted for.
-
After edits, refresh the map and inspect structural impact.
codegraph build .
codegraph diff-impact -T
codegraph diff-impact --staged -T
codegraph cycles -T
codegraph check --staged --cycles --signatures
Completion criterion: the structural diff matches the intended change, with no surprise blast radius, cycles, or signature changes. Then run the project’s real validation commands.
-
Repo explanation: run the scout loop, then read package manifests and narrowed entrypoints. Use codegraph deps <entrypoint> -T --json, codegraph cycles -T | head, and codegraph complexity -T --above-threshold --limit 20. Explain the repo as layers: workspaces, runtime entrypoints, shared contracts/runtime, main flows, hotspots, and caveats. Completion criterion: every major workspace and cross-workspace dependency path is accounted for with CodeGraph output or source reads.
-
Targeted navigation: use where, brief, deps, and narrowed source reads to answer “where is this?” or “who owns this?” Completion criterion: every named target has an exact path/line and the owning module is identified.
-
Diagnosis: start from the reported symbol/file/entrypoint, trace with context, deps, path, and source reads; use flow, sequence, or cfg only when control flow matters. If the report is scenario-led rather than symbol-led, first scout the likely layer directories with structure, then pin candidates with brief/deps before any exact search. Completion criterion: the suspected path from symptom to responsible code is explicit, unresolved forks and CodeGraph blind spots are named, and the three ledgers are complete.
-
Blast radius and migration: for shared functions, types, interfaces, schemas, or RPC methods, combine where, exports, fn-impact, impact, interfaces, and implementations. Completion criterion: callers, dependents, implementors, and transitive risks are accounted for before editing.
-
Contract/RPC migration: first scout the contract package with structure, exports, deps, and where; pick one concrete method/schema, not a whole surface. Then trace the spine: backing schema/type → method constant/string → RPC/schema registration → protocol/client factory → client-runtime state/RPC wrapper → server handler/service → app imports/call sites. Run impact once with -T for application blast radius and once including tests for test candidates. Use targeted exact search only where CodeGraph cannot see dynamic keys, interface properties, generated protocol types, or string dispatch; exclude generated files until you need to confirm schema/method existence. Completion criterion: the report names the chosen contract, server handler/service, client-runtime dependency, affected app surfaces, highest-risk files/functions, validation commands, and dynamic risks CodeGraph may miss.
-
Refactor or architecture review: combine triage, complexity --above-threshold, cycles, roles --role dead, communities --drift, and structure --modules. Completion criterion: proposed seams or risks are tied to coupling, cohesion, cycle, complexity, or role evidence.
-
Cycle seam review: first find the cycle structurally, then read only the files on the cycle before proposing a seam. Use the three ledgers.
-
Rebuild/inspect, then capture both file and function cycles:
codegraph build .
codegraph stats -T
codegraph structure <focused-dir> --depth 3 -T --limit 120
codegraph cycles -T
codegraph cycles -T --json
codegraph cycles -T --functions --json
Pick the cycle by matching the user's focus to its files; do not rely on text cycle numbering matching JSON order. Completion criterion: one exact file set is selected, and you know whether any function-level cycle overlaps it.
-
For every file in the chosen cycle, collect dependency and symbol evidence:
codegraph deps <file> -T --json
codegraph brief <file> -T
Build an edge table from deps --json: A imports B, including typeOnly. Use brief/where for symbol inventories; do not infer symbol participation or ownership from filenames. Completion criterion: every edge around the loop is accounted for exactly once.
-
Read narrowed source only after the cycle files and imports are known. For each edge, verify the import line and the narrowed use that makes the dependency real; targeted exact search is allowed after CodeGraph has named the files. Identify each file's responsibility from code, not CodeGraph risk labels. Completion criterion: structural evidence, import/use evidence, and responsibility interpretation are separately available.
-
Pick the seam by removing the least-owned edge: prefer extracting pure/shared logic out of UI/store modules over making lower-level model/state code import React components. Check blast radius with:
codegraph fn-impact <candidate-symbol> -T
codegraph impact <candidate-file> -T
codegraph fn-impact <candidate-symbol> --include-tests --depth 3
codegraph impact <candidate-file> --include-tests
Completion criterion: the proposed seam names the edge to remove, the symbol or module to extract/invert, the direct callers/importers, and the likely tests affected.
Final report criterion: name the exact file-level cycle; say whether a matching function-level cycle exists; list every cycle edge with CodeGraph import evidence and source-read import/use evidence; separate structural facts from responsibility interpretation; propose one smallest-blast seam as a plan, not proof; name affected files/functions; state CodeGraph blind spots; give the real test/typecheck commands that would prove the refactor.
-
Dead-code cleanup: run the suspect funnel below. Completion criterion: every proposed removal has CodeGraph absence evidence, exact-search absence evidence across first-party consumers, source-read confirmation of what the symbol does, package/export-boundary risk named, tests considered with --include-tests where available, and rejected false positives listed separately.
-
Build the suspect set with structural queries, not grep:
codegraph roles -T --role dead --json
codegraph exports <file> -T --unused
codegraph exports <file> --include-tests --unused
codegraph where <symbol> -T
If collecting many files, parse both results and reexportedSymbols from exports --unused --json. For a directory, loop files or post-filter JSON; do not pass the directory to roles positionally.
-
Demote every “No uses found” result to a suspect until corroborated. For each suspect, run exact fixed-string search for the exported identifier across the repo, excluding generated/vendor/build output, then read the defining file and any hits.
-
Classify hits: real runtime/type consumer, test-only consumer, re-export wrapper, declaration-only/self-reference, generated/config/dynamic/string-key risk. A wrapper re-export is not a runtime use, but it may still be a public API commitment.
-
Report candidates and rejects in separate lists. Put CodeGraph evidence and follow-up search/source evidence in separate columns or sentences; do not let one imply the other.
-
Code review after edits: rebuild, then use diff-impact, diff-impact --staged, cycles, and check --staged --cycles --signatures. Completion criterion: structural diff matches the intended change and surprises are listed before real tests/typecheck run.
-
Test targeting: run impact/dependency queries with --include-tests when supported, then inspect likely test files. Completion criterion: the recommended test set covers touched code, direct callers, and changed contracts; gaps are explicit.
-
Runtime/reconnect flow: use this for session restore, warm cache, live process recovery, reconnect, or restart scenarios. Scout server transport, persistence, runtime service, client-runtime state, and UI route/component directories before searching. Trace two paths when both exist: read-model restoration (persisted projection/cache → HTTP/WS snapshot/subscription → client state → UI) and live runtime recovery (persisted binding/cursor → service routing → adapter resume/start → provider-native RPC). Treat method strings, cache afterSequence cursors, generated protocol schemas, Effect layers, and object-literal handlers as blind spots requiring targeted search and source reads. Completion criterion: persistence tables/services, RPC/HTTP contracts, client state subscribers, UI renderers, blind spots, follow-up reads/searches, and proof commands/manual flows are all present in the three ledgers.
-
Semantic search: only use codegraph search "query" after codegraph embed .; otherwise there are no embeddings. Use --file and --kind to narrow noisy results.
-
Automation: use batch, JSON/NDJSON output, export, plot, and snapshot when results need to be compared, visualized, or scripted.