Codebase Memory MCP: Give Your AI Coding Agent a Photographic Memory of Your Entire Codebase
Codebase Memory MCP indexes your entire codebase into a persistent knowledge graph in milliseconds, giving AI coding agents instant structural awareness with 120x fewer tokens than file-by-file exploration.
Why AI Coding Agents Still Struggle With Large Codebases
AI coding assistants have transformed how developers write software. But there's a persistent problem that no amount of model scaling has fully solved: context blindness.
When you ask Claude Code or Codex CLI to refactor a function, it needs to understand not just that function — but every file that imports it, every test that exercises it, every API route that calls it, and every class that inherits from it. Today, most agents discover this context by reading files one at a time, burning through hundreds of thousands of tokens in grep-and-read cycles that still miss critical dependencies.
The result? AI agents that are brilliant at isolated tasks but stumble when real-world codebases demand systemic understanding. They rename a function and break three tests. They add a feature without knowing the existing pattern. They hallucinate APIs that don't exist.
Codebase Memory MCP was built to solve exactly this problem — and it's trending on GitHub for good reason.
What Is Codebase Memory MCP?
Codebase Memory MCP is a high-performance code intelligence engine that indexes your entire repository into a persistent knowledge graph and exposes it through 14 MCP (Model Context Protocol) tools. Think of it as giving your AI coding agent a photographic memory of your codebase's structure.
Built by DeusData and backed by a peer-reviewed research paper, it uses tree-sitter AST analysis across 158 programming languages, enhanced with Hybrid LSP semantic type resolution for the most popular languages including Python, TypeScript, Go, Rust, Java, and C++.
The performance numbers are striking:
- Average repository: indexed in milliseconds
- Linux kernel (28 million lines of code, 75,000 files): indexed in 3 minutes
- Structural queries: answered in under 1 millisecond
- Token efficiency: 120× fewer tokens than file-by-file exploration
It ships as a single static binary for macOS, Linux, and Windows — no Docker, no runtime dependencies, no API keys. Download, install, restart your agent, and you're done.
How It Works: From Source Code to Knowledge Graph
Understanding how Codebase Memory MCP works helps explain why it's so much more effective than traditional code search.
Step 1: Tree-Sitter AST Parsing
The indexer uses tree-sitter — the same incremental parsing library used by GitHub, Neovim, and Helix — to build abstract syntax trees for every file in your repository. Tree-sitter grammars for all 158 languages are vendored and compiled directly into the binary, so there's nothing to install and nothing that breaks between updates.
Step 2: Knowledge Graph Construction
Parsed ASTs are transformed into a rich knowledge graph where:
- Nodes represent functions, classes, modules, HTTP routes, Dockerfiles, Kubernetes resources, and more
- Edges represent relationships: CALLS, IMPORTS, DEFINES, IMPLEMENTS, INHERITS, HTTP_CALLS, DATA_FLOWS, and others
This graph persists to a local SQLite database at ~/.cache/codebase-memory-mcp/, meaning subsequent sessions start with full awareness — no re-indexing required.
Step 3: Hybrid LSP Type Resolution
For languages where static type information matters (TypeScript, Python, Go, Rust, Java, C#, C++, Kotlin, PHP), Codebase Memory MCP includes a lightweight C implementation of type-resolution algorithms inspired by major language servers like tsserver, pyright, gopls, and rust-analyzer. This enables:
- Parameter binding and return-type inference
- Generic substitution
- JSX component dispatch
- Class-hierarchy and overload resolution
Step 4: MCP Tool Interface
Your AI coding agent interacts with the knowledge graph through 14 purpose-built MCP tools. When Claude Code needs to understand a function's impact, it calls trace_call_chain. When it needs the big picture, it calls get_architecture. Each query returns structured, token-efficient results — not raw file dumps.
# Install in one command (macOS/Linux)
curl -fsSL https://raw.githubusercontent.com/DeusData/codebase-memory-mcp/main/install.sh | bash
# Restart your coding agent and say:
"Index this project"
The 14 MCP Tools Explained
Here's what your AI agent can do once Codebase Memory MCP is connected:
| Tool | What It Does |
|---|---|
index_repository | Full or incremental indexing of your codebase |
get_architecture | Languages, packages, entry points, routes, hotspots, layers |
search_graph | Regex patterns, label filters, degree constraints |
search_code | Graph-augmented grep over indexed files |
semantic_query | Vector search with 11-signal scoring (no API key needed) |
trace_call_chain | Follow function calls across files and packages |
detect_changes | Git diff impact mapping with risk classification |
find_dead_code | Functions with zero callers (excluding entry points) |
query_cypher | Cypher-like graph queries |
manage_adr | Persist architectural decisions across sessions |
match_routes | HTTP route ↔ call-site matching |
detect_services | gRPC, GraphQL, tRPC service detection |
cross_repo_query | Query across multiple indexed repositories |
detect_channels | Socket.IO, EventEmitter pub-sub pattern detection |
Real-World Example: Refactoring a Payment Module
Let's see how Codebase Memory MCP changes the game in practice. Imagine you need to refactor processPayment() in a Node.js e-commerce app — a function called from 12 different places across 8 files.
Without Codebase Memory MCP
Your AI agent reads files one by one, grep-searching for "processPayment" across the codebase. It might find direct calls but miss:
- The dynamic call via
paymentHandlers[type](order) - The test file that mocks the function signature
- The Express route handler that wraps it in error middleware
- The event emitter that triggers it asynchronously
Total tokens consumed: ~400,000+. Missed dependencies: probably 2–3.
With Codebase Memory MCP
// Agent calls trace_call_chain with one MCP tool call
// Result: complete caller and callee graph in ~3,400 tokens
{
"callers": [
{ "function": "checkoutHandler", "file": "routes/checkout.ts", "type": "direct" },
{ "function": "retryPayment", "file": "services/payment-retry.ts", "type": "direct" },
{ "function": "paymentHandlers", "file": "handlers/payment-map.ts", "type": "dynamic" },
{ "function": "onOrderCreated", "file": "events/order-events.ts", "type": "async" }
],
"callees": [
{ "function": "validateOrder", "file": "services/validation.ts" },
{ "function": "chargeStripe", "file": "integrations/stripe.ts" },
{ "function": "updateOrderStatus", "file": "repositories/order-repo.ts" }
],
"affected_tests": [
"tests/payment/process-payment.test.ts",
"tests/integration/checkout-flow.test.ts"
],
"http_routes": ["POST /api/checkout", "POST /api/orders/:id/retry-payment"]
}
Total tokens consumed: ~3,400. Missed dependencies: zero. The agent now has complete structural awareness and can refactor confidently.
Key Benefits
- 🚀 Instant codebase awareness — Your AI agent understands the full structure of your project from the first query, not after reading dozens of files
- 💰 120× fewer tokens — Structural queries cost ~3,400 tokens vs ~412,000 via file-by-file search, dramatically reducing API costs
- ⚡ Sub-millisecond queries — Every structural question is answered in under 1ms thanks to the persistent knowledge graph
- 🌐 158 languages, zero setup — Tree-sitter grammars are compiled into the binary; no language servers or plugins to configure
- 🔒 100% local processing — Your code never leaves your machine; no API keys, no cloud dependencies
- 🔄 Auto-sync — Background watcher detects file changes via git and re-indexes incrementally
- 🏗️ Infrastructure awareness — Dockerfiles, Kubernetes manifests, and Kustomize overlays are indexed as graph nodes with cross-references
- 📊 3D graph visualization — Optional UI variant provides interactive exploration of your codebase's knowledge graph at localhost:9749
Supported Agents
Codebase Memory MCP auto-detects and configures itself for:
- Claude Code
- Codex CLI
- Gemini CLI
- Zed
- OpenCode
- Antigravity
- Aider
- KiloCode
- VS Code (via MCP extensions)
- OpenClaw
- Kiro
One install command configures MCP entries, instruction files, and pre-tool hooks for every agent you have installed.
FAQ
1. Is Codebase Memory MCP free and open source?
Yes. Codebase Memory MCP is fully open source and free to use. The source code is available on GitHub under an open license. The binary is distributed freely for macOS, Linux, and Windows.
2. Does it send my code to the cloud?
No. All processing happens 100% locally on your machine. The knowledge graph is stored in a local SQLite database at ~/.cache/codebase-memory-mcp/. No API keys, no telemetry, no cloud services are required or used.
3. How large of a codebase can it handle?
It has been benchmarked on the Linux kernel — 28 million lines of code across 75,000 files — and indexed it in 3 minutes. Most application repositories are indexed in milliseconds. The configurable file limit (auto_index_limit) defaults to 50,000 files.
4. What's the difference between Codebase Memory MCP and regular code search?
Regular code search (grep, ripgrep, find) operates on raw text and returns matching lines. Codebase Memory MCP understands your code's structure — it knows which function calls which, which class inherits from which, which HTTP route triggers which handler, and which test covers which function. This structural awareness is what makes AI agents dramatically more effective.
5. Do I need to re-index every time I open my editor?
No. The knowledge graph persists between sessions. A background watcher monitors git changes and performs incremental re-indexing automatically. Only changed files are re-processed, so updates take milliseconds.
6. Can I share the index with my team?
Yes. You can commit a compressed snapshot (.codebase-memory/graph.db.zst) to your repository. When teammates clone the repo and run Codebase Memory MCP for the first time, it decompresses the artifact and performs only incremental indexing — avoiding the full reindex cost.
7. Does it work with monorepos?
Absolutely. Codebase Memory MCP handles monorepos natively. Its cross-repo query capabilities let you trace dependencies across multiple services indexed under the same store, making it ideal for microservice architectures and large monorepos.