Local Persistent Code Indexing for AI Agents
_febin_p_ · reddit · 2026-07-19
The author built a local persistent code indexing daemon (mcp-injector) for AI coding agents, aiming to prevent agents from repeatedly reading entire repositories and wasting context.
Core Approach
- Scans repos using language-specific AST parsers, mapping symbols, files, and line numbers into a local SQLite database (WAL mode)
- getprojectmap returns an AST-folded project graph: preserving function signatures, imports, types, and interfaces, while replacing function bodies with compression markers
- This allows the model to know "what exists" first, fetching raw source code on demand
Benchmarks & Engineering Details
- In one repo, the initial project map shrank from 892k tokens to 143k tokens, an 84.9% reduction
- To ensure stable hits on Anthropic's prompt cache, the author normalized volatile factors like file order, timestamps, mtimes, and newlines, guaranteeing byte-level consistent maps for the same repo across multiple generations
- Incremental updates are handled via inotify/FSEvents and a git post-checkout hook, rebuilding only changed files
- Provides higher-level MCP tools like BM25 symbol search, raw file retrieval, dependency/impact traversal, Mermaid graphs, git context, regex search, and DB schema checks
- Payloads are validated before writing back to prevent agents from accidentally writing compressed representations into source code
- Uses entropy heuristics to detect and redact suspected secrets before indexing
More from coding & agent
- Spring AI 2.1.0-RC1 adds tool-call confirmation, pausing agent loops before real-data access — therealdanvega · 2026-10-26
- Morgan Stanley and US banks block third-party AI agents over credentials — thione · 2026-10-26
- METR red-teams OpenAI's agent monitoring, finds bypasses and gaps — thione · 2026-10-26
- OpenAI: coding agents weakened safety monitoring, one lied about it — thione · 2026-10-26
- 250 Builders Hack With Codex at Berlin Community Hackathon Ahead of OpenAI DevDay — paw_lean · 2026-10-26
- Building AI bots on raw APIs? Devs say models are 'dumb without the harness' — madeofAjala · 2026-10-26