Updated
How do I stop my AI coding agent from rereading the same files every session?
Give the agent a single canonical answer per query instead of raw files to sift. Index your repo's markdown once, then serve the one current doc that answers a question, a path:line pointer with a freshness marker, rather than letting it reread files to guess which is canonical. That cuts the cost to about 60% fewer tokens per lookup.
Why does the agent reread files in the first place?
Because nothing tells it which doc is authoritative. When several markdown files mention the same topic, say a runbook, an ADR, an old wiki page, the agent has no signal for which is current, so it opens them and reasons over the pile. It does this every session, for every agent, paying the same tokens to re-answer "which file is the source of truth?" each time.
What actually fixes it?
Three things, together:
- Route the query to one doc. Return the single canonical file that answers, not a candidate list — so the agent stops sifting.
- Mark freshness. Tag each result canonical, stale, or duplicate, so the stale and duplicate copies never reach the agent's context.
- Read at the section level. Serve the paragraph that answers, not the whole file, so a short answer costs short-answer tokens.
How trovex does it
trovex is an open-source, local-first MCP server that does exactly this. It indexes your repo's markdown, answers a query with the one canonical doc (down to the section, with a freshness marker), and lets agents write back what they learn so the next agent reads it instead of re-deriving it. It runs on your machine (vectors in SQLite, ONNX embeddings, no cloud or API keys) and shows you the tokens it saved. trovex is open source and in public beta; install it and setup takes about a minute:
FAQ
Won't a bigger context window stop the rereading?
No. A bigger window only lets the agent hold more at once; it still has no signal for which doc is current, so it keeps reopening candidate files and paying for them. What stops the rereading is serving one canonical doc per query with a freshness marker, not more context to sift.
Does this work across my whole team's agents?
Yes. trovex serves the same canonical answer to any MCP client (Claude Code, Cursor, Windsurf, Cline), so every developer's agent reads one shared source of truth instead of each rebuilding context from a different slice of the repo. The savings compound with team size.
How much does it actually save?
On our own repo it measured a median of 69% fewer tokens per lookup at equal task-success across 26 pre-registered queries (range 41 to 81%, LLM-judged); we publish a conservative about 60% as the headline. Run it on your repo for your own number; the full method is at trovex.dev/measure.
Stop paying to reread the repo.
Point trovex at your docs and serve your agents one current answer per query.
uv tool install trovex
Open source. No cloud, no API keys. Your docs never leave your machine.