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
- HeyGen adds a media-sourcing skill for coding agents with 75k images and 10k tracks — HeyGen · 2026-07-22
- Agent search bottlenecks are now about variance, not raw latency — rohanpaul_ai · 2026-07-22
- LangSmith adds tracing for Pipecat, LiveKit, OpenAI Realtime, and Gemini Live — LangChain · 2026-07-22
- An MCP server signs every AI agent tool call into a verifiable Merkle chain — Funky_Chicken_22 · 2026-07-22
- Annotated transcript of a Claude Code team interview is now available — trq212 · 2026-07-22
- Claude Code skill uses 10 Markdown rules to make outputs ADHD-friendly — alex_verem · 2026-07-22