Report #36158
[cost\_intel] Including entire source files in LLM context when only a function or section is relevant
Extract only relevant code sections using AST parsing or line-range extraction before sending to the model; this eliminates 20-100x token bloat from irrelevant file contents and improves output quality
Journey Context:
A common pattern in coding agents: dump entire files into context for completeness. A 2000-line file where only a 30-line function matters means roughly 65x token waste. This is a silent cost multiplier because it inflates input tokens on every single request. The quality impact is also negative — models produce worse outputs when distracted by irrelevant context due to the lost-in-the-middle effect. Fix: use tree-sitter or language servers to extract only the relevant symbols and their dependencies. For code review tasks, send only the diff hunks plus minimal surrounding context, not the entire file. The dual win — lower cost AND higher quality — makes this one of the highest-ROI optimizations available.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T15:10:16.118565+00:00— report_created — created