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
- Astra storyboards plus Minimax H3 per-shot generation boost video success rates — Hailuo_AI · 2026-09-11
- Codex tip: use Sol with Astra and Luna sub-agents to save usage — pvncher · 2026-09-11
- agents-best-practices: a provider-neutral Agent Skill for designing and auditing agentic harnesses — tom_doerr · 2026-09-11
- Cognition's SWE-2 uses a KKT duality argument in RL to shift the effort Pareto curve — YouJiacheng · 2026-09-11
- First-ever Three.js Conference lands in Paris, with a panel on AI-shortened design workflows — OdinLovis · 2026-09-11
- Agile co-author Ron Jeffries publishes 'Resist AI', urging developers to push back — mborch · 2026-09-11