Code intelligence — codebase-memory-mcp + codegraph
Index your repo into a knowledge graph so Claude can answer 'who calls this function' and 'what breaks if I delete it' in one tool call instead of grepping.
Code intelligence
Two MCP servers turn Claude from "smart grep" into "engineer who knows your codebase":
- codebase-memory-mcp — indexes your repo into a Postgres-backed knowledge graph. Symbols, files, edges (calls, imports, defines).
- codegraph — runs deep analysis on top: complexity, find_cycles, fn_impact, audit, communities.
Together they replace 80% of grep + ad-hoc code reading with O(1) graph queries.
The graph runs locally — your code never leaves your machine. The Postgres index sits in .codebase-memory/graph.db.zst next to your repo.
Step 1: Install codebase-memory-mcp
claude mcp add codebase-memory -s user -- npx -y codebase-memory-mcp
For Codex:
[mcp_servers.codebase-memory]
command = "npx"
args = ["-y", "codebase-memory-mcp"]
Step 2: Install codegraph (optional but recommended)
claude mcp add codegraph -s user -- codegraph mcp
If codegraph is not on PATH, install with:
npm install -g codegraph
Codegraph is the "deep analysis" layer. You can skip it and just use codebase-memory-mcp's basic search; you lose fn_impact and find_cycles etc.
Step 3: Index your first repo
In a fresh Claude Code session inside your repo:
"index this repository"
Claude calls index_repository on codebase-memory-mcp. First index is ~1-2 minutes for a 50k-line repo. Subsequent indexes are incremental (content-hashed) — sub-second.
Then ask:
"what's the architecture overview of this repo?"
Claude calls get_architecture — you get module hierarchy, dependency graph, and entry points. This single call replaces 30 minutes of click-around.
Step 4: Verify
Run aiguide_validate_step. The validator looks for any of codebase|codegraph|archtracker in claude mcp list, OR a .codebase-memory/ directory in the cwd. Either path passes.
Step 5: Useful queries to try
Once indexed, your AI can answer:
- "Who calls handleStartRecipe?" →
search_graphreturns all callers in O(1). - "What breaks if I rename this function?" →
codegraph fn_impactreturns transitive callers. - "Are there circular dependencies?" →
codegraph find_cyclesreturns SCCs. - "What are the most complex files?" →
codegraph complexityreturns hotspots. - "Show me the call chain from POST /upgrade to Stripe" →
trace_call_path.
Add a CLAUDE.md hint so Claude reaches for the graph instead of grep:
## Codebase intelligence
When working in this repo, prefer search_graph / codegraph context / fn_impact
over grep + reading whole files. Re-index after structural changes
(new files, renamed functions). The graph is faster and more accurate
than text search for "who calls X" and "what depends on Y" questions.
(claude mcp list 2>&1 | grep -iE "codebase|codegraph|archtracker") || ls -d ./.codebase-memory 2>/dev/null || echo "neither code-intel MCP nor local index"
Step 6: Optional — archtracker for drift detection
claude mcp add archtracker -s user -- archtracker-mcp
archtracker takes architecture snapshots and tells you when the codebase drifts (orphan modules, coupling hotspots, circular deps that didn't exist last week). Mostly useful for repos with multiple contributors — solo projects don't drift fast enough to need it.
After this recipe Claude understands your code structure as well as you do. The next recipe wires up GitHub so it can read PRs and issues too.