What is a Knowledge Graph
A knowledge graph is a structured map of relationships in your codebase. Instead of treating files as isolated text, it understands that UserCard.tsx imports from types.ts, calls getUser() from db.ts, and is rendered by ProfilePage.tsx.
Without a knowledge graph, Claude searches for files by name and guesses at relationships. With one, it can answer questions like "what breaks if I change this interface?" or "which components depend on this utility function?" This is the difference between a text editor and an IDE.
Installing code-review-graph
The code-review-graph MCP server is the most practical way to add knowledge graph capabilities to Claude Code. Installation takes three steps:
- Install the package globally with npm
- Add it to your
.mcp.jsonconfiguration file so Claude loads it automatically - Run the initial indexing command to scan your codebase and build the graph
The indexing process parses your source files, extracts imports, exports, function calls, and type references, then stores them as nodes and edges in a local database.
Mapping Your Codebase
Once installed, the graph builder walks your project tree and creates nodes for every file, function, class, type, and export. Edges represent relationships: imports, calls, extends, implements, and renders. A typical Next.js project with 50 files generates thousands of edges.
Configure which directories to include and exclude. You want src/ indexed but not node_modules/ or .next/. Keep the graph focused on code you actually maintain.
Querying Relationships
The real power is in queries. Ask the graph "what depends on User type?" and get every file that imports or references it. Ask "what does auth.ts export?" and get a complete list of its public API. These queries replace manual grep searches with structured, relationship-aware lookups.
Claude can use these queries automatically during code review to check whether a proposed change affects downstream consumers. This catches breaking changes before they ship.
Impact Analysis
Impact analysis is the killer feature. Before modifying a function signature, query the graph to find every caller. Before renaming a type, find every file that references it. Before deleting a component, confirm nothing renders it.
Without impact analysis, refactoring is guesswork. You rename a function, deploy, and discover three pages broke because they were calling the old name. With a knowledge graph, Claude shows you every affected file before you make the change.
Practical Exercise
Build Your Codebase Map
Set up a knowledge graph for your project and run your first queries:
- Install: Add
code-review-graphto your.mcp.jsonand verify it loads in your next Claude session - Index: Run the graph builder against your
src/directory and check the node and edge counts - Query: Find all files that depend on your most-imported module (usually
types.tsorutils.ts) - Impact test: Pick a type definition and ask Claude what would break if you renamed it, using the graph for analysis
Want automated graph updates? The AI Brain Pro package includes hooks that re-index your knowledge graph on every commit so it never goes stale. View pricing →