Context Has a Price: Adding and Removing Context for LLM Coding Agents under Prefix Caching

Zerui Yang, Miaomiao Dong, Quan Xue, Chaorui Zhang, Xuanyu Zheng +7 more
11/17/2026
cs.AI

No confident code implementation found for this paper.

Abstract

Coding agents repeatedly send their conversation history to a language model. Adding useful code may reduce search, while removing old tool outputs may shorten later prompts.

Show full abstract

But do these changes reduce the cost of solving a task? We study this as a measurement problem in more than 20,000 runs of open models on SWE-bench Verified, SWE-bench and Loc-Bench. We account separately for uncached input, cached input and output tokens. Three findings emerge. First, in our main evidence-package experiments, retrieved code reduces read and search commands by 18--34%, but increases cost by 33--42% when cached input costs one tenth of uncached input, without a measurable improvement in resolution. Second, removing old observations can either save money or increase cost: the same approach saves 19--36% without a cache discount but increases cost by 38--116% with a tenth-price cache. Third, shorter prompts do not guarantee cheaper runs because agents may respond by taking more steps. We also find that concurrent experiments can share cached prefixes and distort cost comparisons. These results show why context-management methods should be evaluated using both token prices and the agent's subsequent behavior.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{yang2026context,
  title  = {Context Has a Price: Adding and Removing Context for LLM Coding Agents under Prefix Caching},
  author = {Zerui Yang and Miaomiao Dong and Quan Xue and Chaorui Zhang and Xuanyu Zheng and Xiyuan Wang and Haolin Ruan and Xueyan Niu and Guangcheng Song and Weixi Zhang and Wei Han and Bo Bai},
  year   = {2026},
  eprint = {2611.22238},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2611.22238v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2611.22238.svg)](https://codeofpaper.com/paper/2611.22238)

Discussion