How to Stop Feeding LLMs and Teach Agents to Understand Your Code
Familiar situation: you connect an AI agent to a project, and it starts "hallucinating" or repeatedly re-reading the same files, burning through your token budget. Even advanced tools like Cursor sometimes lose track of connections between modules when a project grows to thousands of files. I recently came across Memtrace — a project that tries to solve this problem fundamentally by turning a codebase into a living knowledge graph.
Why agents need "structural memory"
Most modern AI assistants work on the RAG (Retrieval-Augmented Generation) principle. They search for code snippets by keywords or vector similarity. The problem is that code is not just text — it's a complex hierarchy of calls, imports, and dependencies. If an agent doesn't see the full picture, it might refactor a function in a way that breaks tests in a neighboring microservice the agent wasn't even aware existed.
Memtrace creates what developers call a "bi-temporal knowledge graph." It doesn't just index text — it understands structure: which function calls what, which interfaces are being implemented, and how all of this has changed over time.
What this tool can do
The main feature of the project is speed and locality. While similar tools spend tens of dollars on API calls and hours on indexing, Memtrace does this in seconds on your machine.
LLM-free indexing
The developers used Rust and Tree-sitter. This makes it possible to parse 15,000 files in about 1.5 seconds. At the same time, API costs are zero because neural networks are not used to build the graph — only deterministic static analysis. The entire process happens locally, so your code doesn't fly off to someone else's servers.
Context understanding via MCP
The tool supports the Model Context Protocol (MCP). This means it can be "plugged in" to Claude Code, Cursor, Windsurf, or VS Code with literally one command. The agent gets access to 25+ tools: from finding "dead" code to blast radius analysis for changes.
Change timeline
Memtrace stores version history for every symbol. An agent can ask: "What changed in the last week?" or "Which functions became too complex after the last merge?" The system uses six evaluation algorithms, including novelty analysis and change intensity, to highlight the most important things to the agent.
Comparison with alternatives
The README has an interesting benchmark table. For example, Mem0 or Graphiti rely on LLM calls for entity extraction during indexing. This is slow and expensive. Memtrace looks like a racing car by comparison:
| Operation | Memtrace | Alternatives (Mem0/GitNexus) | |---|---|---| | Indexing 15,000 files | 1.5 sec | 30 min to 2 hours | | API costs | $0 | $10–50 | | Memory consumption | 26 MB | ~1 GB |
Of course, it's worth noting that Memtrace is narrowly focused on code, while other systems can work with arbitrary conversations. But for development tasks, such specialization is a huge plus.
Technical internals
Under the hood, the project has a pretty serious stack. Besides Rust, it uses Tantivy for full-text search (BM25) and vector embeddings for semantic search. All of this is combined through Reciprocal Rank Fusion (RRF) to deliver the most relevant results.
Language support is implemented interestingly. Besides the standard set (TypeScript, Python, Go, Rust), Memtrace understands infrastructure code: Terraform, GitHub Actions, and even RLS policies in PostgreSQL. It sees connections between the database schema and ORM code in the application.
How to use this in practice
Imagine you need to make changes to a base class in a huge monorepo. Usually, you run a search across the entire project and hope you didn't miss anything.
With Memtrace, the agent can execute the command get_impact and immediately see the dependency tree. It will say: "If you change this field, these three endpoints and one worker in another module will break." This eliminates "blind" refactoring.
To get started, just install the package globally:
npm install -g memtrace
After that, the tool will automatically set up the necessary settings for Claude or Cursor. If you're privacy-paranoid, you can disable telemetry with one environment variable MEMTRACE_TELEMETRY=off.
Who should try it
The project is currently in private beta, but access is gradually opening in groups. In my opinion, Memtrace will be most useful for those who:
- Work with large codebases where it's hard to keep all connections in your head.
- Actively use AI agents and want to reduce token spending.
- Are hesitant about sending source code to cloud services for indexing.
The only caveat is that the license is proprietary (EULA), although they promise to keep free access for individual developers. If you can't wait to get your hands on "structural memory" for your agents, it's worth checking out their Discord or submitting a request on the website.
So far, the project looks like a very energetic attempt to make AI-assisted development more predictable and cheaper. At the very least, 1.5-second indexing speed is something we've been lacking for a long time.
Projets similaires