Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP
Martin Vogel, Falk Meyer-Eschenbach, Severin Kohler, Elias Grünewald, Felix Balzer · 2026
Read Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP by Martin Vogel, Falk Meyer-Eschenbach, Severin Kohler, Elias Grünewald, Felix Balzer (2026) in the Tower of Babel, a free online library of public-domain works preserved in clean, searchable text. No sign-up. The full text is served as a plain-text file at a predictable URL, where text is present: https://antarctic-labs.com/tower-of-babel/arxiv-2603-27277.txt.
Introduction
Vogel and co-authors present Codebase-Memory, a knowledge graph system that helps language models explore code. Coding agents usually reread files and grep repeatedly, burning thousands of tokens per query. Codebase-Memory builds a persistent Tree-Sitter graph over the repository instead. It parses 66 languages with parallel workers and call-graph traversal. Impact analysis and community discovery enrich the graph further. Across 31 real repositories, answer quality reached 83 percent versus 92 for file exploration. The graph route used ten times fewer tokens. Graph-native queries matched or beat the explorer outright.
Catalog record
| CREATOR | Martin Vogel, Falk Meyer-Eschenbach, Severin Kohler, Elias Grünewald, Felix Balzer |
|---|---|
| YEAR | 2026 |
| COLLECTION | PAPERS |
| FORMAT | TXT |
| FILE SIZE | 36520 |
| LICENSE | http://creativecommons.org/licenses/by/4.0/ |
| RIGHTS | CC BY |
| SOURCE | arXiv |
Source: https://arxiv.org/abs/2603.27277
Browse the full library · About the Tower of Babel
Full text
The opening of the work, from the library's hosted text:
Codebase-Memory: Tree-Sitter-Based Knowledge Graphs for LLM Code Exploration via MCP Martin Vogel, Falk Meyer-Eschenbach, Severin Kohler, Elias Grünewald, Felix Balzer Abstract Large Language Model (LLM) coding agents typically explore codebases through repeated file-reading and grep-searching, consuming thousands of tokens per query without structural understanding. We present Codebase-Memory , an open-source system that constructs a persistent, Tree-Sitter-based knowledge graph via the Model Context Protocol (MCP), parsing 66 languages through a multi-phase pipeline with parallel worker pools, call-graph traversal, impact analysis, and community discovery [ 1 ] . Evaluated across 31 real-world repositories, Codebase-Memory achieves 83% answer quality versus 92% for a file-exploration agent, at ten times fewer tokens and 2.1 times fewer tool calls. For graph-native queries such as hub detection and caller ranking, it matches or exceeds the explorer on 19 of 31 languages. 1 Introduction The emergence of LLM-based coding agents, such as Claude Code [ 2 ] , Cursor, and Aider [ 3 ] , has transformed software development by enabling natural-language-driven code exploration, bug fixing, and refactoring. These agents interact with codebases through tool calls, reading files, searching for patterns, and listing directory contents. While effective for small-scale tasks, this text-based exploration strategy scales poorly. A typical codebase exploration session requires dozens of tool calls, consuming hundreds of thousands of tokens before the agent develops sufficient understanding to answer a structural question such as “What breaks if I change this function?” [ 4 ] . This inefficiency stems from a fundamental mismatch: LLM agents operate on unstructured text, yet the questions developers ask are inherently structural—call graphs, dependency chains, module boundaries, and impact analysis. Text-based search cannot capture transitive relationships without iteratively following references, each iteration consuming additional tokens and increasing the risk of lost context [ 5 ] . Recent empirical analyses confirm that input tokens dominate the cost of agentic coding tasks, even with caching [ 6 ] . Recent work on coding agents [ 7 , 8 , 9 ] has focused on improving agent strategies, better prompting, hierarchical localization, or fault-localization heuristics, while leaving the underlying code retrieval mechanism largely unchanged. Concurrently, graph-based code representations such as Code Property Graphs [ 10 ] and CodeQL [ 11 ] have proven powerful for static analysis but remain heavyweight, requiring specialized databases and query languages not optimized for LLM consumption. Emerging work on repository-aware knowledge graphs [ 12 ] and graph-enhanced retrieval agents [ 13 ] demonstrates the growing interest in structural code representations for LLM agents, though these systems typically require complex infrastructure. The cost of this inefficiency is concrete: production agentic workloads report per-task LLM API costs of several dollars on non-trivial repositories [ 6 , 7 ] . The recent emergence of the Model Context Protocol (MCP) [ 2 ] as an open standard for connecting LLM agents to external tools presents an opportunity to expose structural code queries as lightweight, agent-native tools—yet no existing solution exploits this to combine structural query capability with zero-infrastructure deployment. To bridge this gap, we propose treating codebase structure as a first-class, queryable knowledge graph exposed directly to LLM agents via lightweight structural tools rather than raw file content. We instantiate this in our implementation Codebase-Memory , which parses codebases using Tree-Sitter [ 14 ] , stores the resulting graph in SQLite across 66 languages, and exposes 14 structural query tools via MCP [ 2 ] , maintained incrementally through file-watching and content-hash-based re-indexing. The system ships as a single statically linked C binary with zero runtime dependencies. Our contributions are: • A knowledge-graph architecture for code that combines Tree-Sitter parsing across 66 languages, a multi-phase build pipeline with parallel extraction, 6-strategy call resolution, and Louvain community detection, stored in a single SQLite file with zero external dependencies. • An MCP-based tool interface exposing 14 typed structural queries (call-path tracing, impact analysis, hub detection) to any MCP-compatible LLM agent, with sub-millisecond query latency. • A head-to-head evaluation across 31 languages showing ten times lower token cost and 2.1 times fewer tool calls at competitive quality (83% vs. 92%), with a systematic analysis of where graph-based retrieval excels and where file-based exploration remains necessary. The remainder of this paper is structured as follows: Section 2 surveys related work in structural code analysis, code retrieval for LLMs, and token efficiency. Section 3 describes the system architecture, graph schema, pipeline, and security hardening. Section 4 presents the benchmark evaluation, performance measurements, and adoption metrics. Section 5 discusses trade-offs, threats to validity, and future work. Section 6 concludes. 2 Related Work 2.1 Structural Code Analysis Structural code representations have a long history in software engineering. Program Dependence Graphs [ 15 ] unify data and control dependencies. Code Property Graphs [ 10 ] merge Abstract Syntax Trees (ASTs), control flow graphs, and PDGs into a single queryable structure. CodeQL [ 11 ] provides a declarative query language over relational code databases. While powerful, these systems are heavyweight, requiring specialized databases and domain-specific query languages, and are not designed for LLM consumption. Tree-Sitter [ 14 ] provides fast, incremental, error-tolerant parsing with grammars for more than 100 languages. It has become the de facto standard for editor-integrated code analysis and has been adopted by tools like Aider [ 3 ] for repository mapping. Recent work on AST-based chunking [ 16 ] demonstrates that preserving syntactic structure during code retrieval improves both recall and downstream task performance compared to naive text chunking. 2.2 Code Retrieval for LLMs Repository-level code understanding remains challenging for LLMs. RepoCoder [ 17 ] employs iterative BM25 retrieval for code completion. DocPrompting [ 18 ] retrieves documentation as generation context. A recent survey [ 19 ] identifies structural retrieval as a key frontier. Several recent systems construct code graphs for LLM-based retrieval. GraphCoder [ 20 ] built Code Context Graphs for repository-level code completion (ASE 2024). CodexGraph [ 21 ] exposed code graphs to LLM agents via graph database interfaces (NAACL 2025). KGCompass [ 12 ] linked issues and code entities in repository-aware knowledge graphs, achieving 58.3% on SWE-bench Lite. RepoGraph [ 22 ] constructed repository-level code graphs that boost existing agents by 32.8% relative improvement on SWE-bench (ICLR 2025). A second line of work focuses on graph-guided agent navigation. LocAgent [ 23 ] parsed codebases into directed heterogeneous graphs for multi-hop code localization (ACL 2025). GraphCodeAgent [ 24 ] constructed dual requirement-structural graphs for retrieval-augmented code generation. RANGER [ 13 ] used graph-enhanced retrieval for repository-level queries. Prometheus [ 25 ] combined Tree-Sitter-based knowledge graphs with unified memory for multilingual issue resolution. The Repository Intelligence Graph [ 26 ] provided a deterministic architectural map for LLM code assistants. More fundamentally, SemanticForge [ 27 ] employed dual static-dynamic knowledge graphs with neural graph query generation, and the Code Graph Model [ 28 ] integrated graph representations directly into LLM attention mechanisms. Our work differs from prior approaches by using MCP as a standardized interface compatible with any MCP-capable agent, SQLite for zero-dependency deployment, incremental synchronization for live workflows, and support for 66 languages via a single binary. 2.3 LLM Coding Agents SWE-bench [ 29 ] established the gold-standard benchmark for coding agents. SWE-Agent [ 7 ] introduced Agent-Computer Interfaces (ACIs) optimized for LLM interaction. AutoCodeRover [ 8 ] combines