A repository with two files named `config.ts` will send an agent to the wrong one roughly half the time. Nothing about that is mysterious: the search tool returned both, the ranking was arbitrary, and the model picked the first plausible path. The model did what it was asked. The context was ambiguous.
Three ways context goes wrong
Ambiguous names are the obvious one. Stale files are the sneaky one — a build artifact or an old copy inside `dist/` that still matches the query. Truncation is the expensive one: the tool returned the first four thousand characters of a file whose relevant section is at the bottom.
Each has a different fix, and none of them is a better prompt.
Fix ambiguity with paths, not ranking
Give the agent a way to disambiguate: full paths in results, and a rule that says `src/config.ts` beats `dist/config.ts` without asking. Semantic code tools do this well: they build symbol-level indexes instead of returning text matches, which is why they cost more setup than a grep wrapper. The MCP directory lists several.
Fix staleness by excluding before searching
The Filesystem server takes allowed roots at startup, so you can point it at `src/` and never expose `dist/`. That single decision removes a whole class of wrong-file edits, and it is a one-line change in the client config.
Fix truncation by measuring
If a tool returns the first N characters, you are reading a summary whether you meant to or not. Our context budget checker exists because people consistently underestimate how quickly a file fills a window — a thousand lines of TypeScript is already tens of thousands of tokens.
The uncomfortable conclusion
An agent that reads the wrong file is usually working exactly as designed with bad inputs. Before buying a bigger model or a longer context window, check what the tools actually handed it. In our experience the fix is a path rule, an exclusion, or a chunking change — all of which cost nothing and work immediately.