Adding retrieved code to coding agents raises cost under prefix caching
Can adding retrieved code to a coding agent, or deleting old tool output, actually lower the cost of solving problems? Across more than 20,000 runs, the paper priced uncached input, cached input and output tokens separately on SWE-bench Verified, SWE-bench and Loc-Bench using open models. In the main experiments, retrieved code cut read and search commands by 18–34%, but when cached input was billed at one tenth the price, total cost rose 33–42% instead, with no measurable gain in solve rate. Deleting old observations was equally counterintuitive: it saved 19–36% without a cache discount, but cost 38–116% more with one-tenth-price caching. The paper also notes that short prompts are not necessarily cheaper, because the agent may make up for them with more steps, and that concurrent experiments share a cached prefix, which distorts cost comparisons. These results come from open models and specific benchmarks; the paper does not say whether they hold with closed models or different cache pricing.
On every turn, a coding agent resends the conversation history to the model, and the longer the context, the larger the input token bill. Once cached input is billed at a discount, many people assume that sending less content saves money, but the cache discount also changes the relative price of adding content and removing content, so the old intuition no longer holds.
People building coding agents can no longer treat a shorter prompt or fewer searches as a proxy for saving money. They should calculate costs using the actual unit prices of cached and uncached tokens, together with the extra steps the agent takes afterwards.