Context Has a Price: Adding and Removing Context for LLM Coding Agents under Prefix Caching
On the map: LLM agents and tool use → Agent memory systems
Abstract (arXiv)
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. 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.
Key facts. No citing papers in the map yet (data through 24 Nov 2026). Placed in Agent memory systems, one of 16 directions in LLM agents and tool use. Builds on 21 of its 28 references that are in the map. Submitted 17 Nov 2026, announced 18 Nov 2026.
Builds on
21 of 28 references.
Closest ancestors · 4
Same direction, newest first
- 2026FOCUS: Training-Free Decision-Preserving Context Compression for LLM Agents29 Sep
- 2026When Can Agents Forget Their Reasoning? ICLR for Long-Horizon Agent Context Compression24 Sep
- 2026Token Reduction Is Not Cost Reduction13 Jul
- 2026How Do AI Agents Spend Your Money? Analyzing and Predicting Token Consumption in Agentic Coding Tasks24 Apr
Other references · 17
- 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,871
- 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,765
- 2024SWE-agent: Agent-Computer Interfaces Enable Automated Software Engineeringcited by 2,069
- 2024OpenHands: An Open Platform for AI Software Developers as Generalist Agentscited by 1,155
- 2023Large Language Models Can Be Easily Distracted by Irrelevant Contextcited by 909
- 2024RepoGraph: Enhancing AI Software Engineering with Repository-level Code Graphcited by 104
- 2025LocAgent: Graph-Guided LLM Agents for Code Localizationcited by 99
- 2025The Complexity Trap: Simple Observation Masking Is as Efficient as LLM Summarization for Agent Context Managementcited by 73
- 2025Reducing Cost of LLM Agents with Trajectory Reductioncited by 66
- 2026SWE-Pruner: Self-Adaptive Context Pruning for Coding Agentscited by 52
- 2026Failure as a Process: An Anatomy of CLI Coding Agent Trajectoriescited by 22
- 2026CodeTracer: Towards Traceable Agent Statescited by 20
5 more
- 2026The Missing Memory Hierarchy: Demand Paging for LLM Context Windowscited by 12
- 2026FastContext: Training Efficient Repository Explorer for Coding Agentscited by 6
- 2026Code Isn't Memory: A Structural Codebase Index Inside a Coding Agentcited by 4
- 2026Scrouting: Cost-Aware Routing of Coding Agents by Scouting the Repository Firstcited by 4
- 2026Continuous Context Managementcited by 2
Built on by
Not cited yet.
Similar, not cited
Close in wording, no citation either way
- 2026The Physical Cost of Context: Quality-Constrained Resource Accounting for Coding Agents
- 2026Don't Break the Cache: An Evaluation of Prompt Caching for Long-Horizon Agentic Tasks
- 2026Prompt-Induced Waste in Coding Agents: Reasoning, Effort, Harness Design, and End-to-End Cost
- 2026What Does Context Compression Cost an Agent? Interaction Costs Unrevealed by Task-Completion Metrics
- 2026Beyond Token Savings: A Systematic Study of Context Compression in LLM Agents
- 2026Cache Engineering for Agents
- 2026An Empirical Cost Attribution of Context-Compression Gateways in Multi-Turn Coding Agents
- 2026CTXAgent - Self-Controlled Context Management of LLM Agents