<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Evgenii Arsentev</title>
    <description>The latest articles on DEV Community by Evgenii Arsentev (@arsentev).</description>
    <link>https://dev.to/arsentev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4106171%2Fe4a438a3-4658-4364-9c9a-6a8c5b396ad4.jpg</url>
      <title>DEV Community: Evgenii Arsentev</title>
      <link>https://dev.to/arsentev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/arsentev"/>
    <language>en</language>
    <item>
      <title>97% of what my coding agent billed for was re-reading its own context</title>
      <dc:creator>Evgenii Arsentev</dc:creator>
      <pubDate>Wed, 16 Sep 2026 07:11:32 +0000</pubDate>
      <link>https://dev.to/arsentev/97-of-what-my-coding-agent-billed-for-was-re-reading-its-own-context-4o2</link>
      <guid>https://dev.to/arsentev/97-of-what-my-coding-agent-billed-for-was-re-reading-its-own-context-4o2</guid>
      <description>&lt;p&gt;Token counters tell you how much you spent. I wanted a different number: &lt;strong&gt;how much of what I paid for was new text the model actually produced.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So I measured it against a complete local log corpus of my own agentic coding work: &lt;strong&gt;722 sessions, 150,902 model calls, 34.56 billion tokens.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By tokens billed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Token class&lt;/th&gt;
&lt;th&gt;Share of all tokens&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Cache read (re-reading context)&lt;/td&gt;
&lt;td&gt;97.05%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache write (storing context)&lt;/td&gt;
&lt;td&gt;2.57%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output (generation)&lt;/td&gt;
&lt;td&gt;0.38%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fresh input&lt;/td&gt;
&lt;td&gt;0.01%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For every token the models produced, roughly &lt;strong&gt;256 tokens of cached context were read back in.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Cache pricing softens that ratio, but not the conclusion. Under published per-token list rates:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Category&lt;/th&gt;
&lt;th&gt;Share of cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Re-reading context&lt;/td&gt;
&lt;td&gt;55.89%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Writing context to cache&lt;/td&gt;
&lt;td&gt;31.89%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Generating new text&lt;/td&gt;
&lt;td&gt;12.18%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fresh input&lt;/td&gt;
&lt;td&gt;0.04%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Context handling 87.8%, generation 12.2%.&lt;/strong&gt; Re-reading context alone costs &lt;strong&gt;4.59x&lt;/strong&gt; as much as everything the models wrote. And cache writing is not a rounding error: at 31.89% it is the second-largest line, larger than generation. Caching does not make context free, it moves part of the price to the moment state is stored.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it looks like this
&lt;/h2&gt;

&lt;p&gt;An agent doesn't send a fresh question on every step. It sends the whole conversation so far: instructions, every file it read, every command it ran. Then it adds one step and sends everything again. A token that enters the context on step 1 of a 60-step run is paid for 60 times.&lt;/p&gt;

&lt;p&gt;I put a number on that with a derived measure, &lt;strong&gt;input amplification&lt;/strong&gt;: total input tokens billed in a session, divided by that session's peak context size. Across the 590 sessions with at least three model calls, the median is &lt;strong&gt;23.7x&lt;/strong&gt;, the 90th percentile &lt;strong&gt;124.5x&lt;/strong&gt;, the maximum &lt;strong&gt;4,182x&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The median session pays for its peak working state about 24 times. One session in ten pays for it more than 125 times. A session's cost is not mainly set by how big its context is, nor by how much it writes, but by the product of context size and how many times that context gets traversed.&lt;/p&gt;

&lt;p&gt;Cost is also concentrated: an estimated 80% of the corpus total falls on 21 of 722 sessions (2.9%), and sessions longer than 200 model calls - 8% of sessions - account for an estimated 92.8% of spend.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part you can actually change
&lt;/h2&gt;

&lt;p&gt;None of the above is a knob. How often you clear the context is.&lt;/p&gt;

&lt;p&gt;I ran a controlled comparison: twelve fixed programming tasks under six context-clearing policies - a fresh session every 1, 2, 3, 4, 6 and 12 tasks - six replicates each, with the model, the tasks and their order held constant. 36 runs.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Clear after every&lt;/th&gt;
&lt;th&gt;Mean modeled cost per run&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1 task&lt;/td&gt;
&lt;td&gt;$2.165&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2 tasks&lt;/td&gt;
&lt;td&gt;$1.854&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;3 tasks&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;$1.622&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;4 tasks&lt;/td&gt;
&lt;td&gt;$1.704&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;6 tasks&lt;/td&gt;
&lt;td&gt;$1.679&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12 tasks (never)&lt;/td&gt;
&lt;td&gt;$1.780&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Cost is not monotone in session length. It falls, bottoms out at three tasks, then rises again.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Clearing after &lt;strong&gt;every&lt;/strong&gt; task costs &lt;strong&gt;33.5%&lt;/strong&gt; more than clearing every third (p = 0.0022, Holm-adjusted 0.011).&lt;/li&gt;
&lt;li&gt;Every second task: &lt;strong&gt;+14.3%&lt;/strong&gt; (p = 0.0022, Holm 0.011).&lt;/li&gt;
&lt;li&gt;Going from clearing every task to every third cuts cost by &lt;strong&gt;25.1%&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The reason the constant-clearing end is expensive: a cache write costs &lt;strong&gt;20x&lt;/strong&gt; a cache read. Clear after every task and you keep paying to rebuild state you just threw away. At the optimum the spend splits 39.0% cache read, 32.3% cache write, 28.7% output.&lt;/p&gt;

&lt;p&gt;Two things I want to state plainly rather than round off:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The middle is a plateau, not a point.&lt;/strong&gt; Every fourth task is +5.1% against every third (p = 0.17), every sixth +3.5% (p = 0.45). The data cannot separate 3 from 4 or 6. "Clear every few tasks" is the finding; "clear every third" is just where the observed minimum landed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never clearing is not significantly worse.&lt;/strong&gt; It comes out +9.7% against every third, p = 0.046, Holm-adjusted 0.14. An earlier version of this work claimed both extremes were significantly more expensive than the optimum. That claim is withdrawn for never clearing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring it yourself
&lt;/h2&gt;

&lt;p&gt;I packaged the measurement as a small open-source tool, &lt;a href="https://github.com/arsentev-ai/contextburn" rel="noopener noreferrer"&gt;contextburn&lt;/a&gt;. It reads the transcripts your agent already writes on your machine and makes no network calls.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;contextburn
contextburn detail 24
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It also runs as an MCP server, so the agent can check its own efficiency mid-session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;claude mcp add contextburn &lt;span class="nt"&gt;--&lt;/span&gt; uvx contextburn mcp
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Two traps, in case you write your own counter
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;1. Streaming logs record the same model call more than once.&lt;/strong&gt; An early snapshot and a final record share one message id. Count both and you double the call; keep only the first and you halve the output. Take the element-wise maximum per message id.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Prices change the answer, and they will change yours.&lt;/strong&gt; Both datasets behind this post were re-published with corrected costs, and the errors were mine. Cache reads had been priced at a rate that applies only to a newer model, and every cache write had been priced at the 5-minute rate when the logs show mostly 1-hour writes, billed at 2x input rather than 1.25x. Token counts, call counts and the composition table did not move at all. Every dollar figure did: the corpus split went from 83.5% / 16.5% to the &lt;strong&gt;87.8% / 12.2%&lt;/strong&gt; above. If you report a cost-weighted share, it is only as current as your price table - and worth re-deriving before you quote it anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Limits
&lt;/h2&gt;

&lt;p&gt;This is a single-practitioner case study, not a sample of a population, and the dollar figures are a model applied to logs rather than an invoice.&lt;/p&gt;

&lt;p&gt;Cache-write duration cannot be verified for part of one machine's logs. If every write were instead a 5-minute write, the corpus split would be 86.2% / 13.8% - the direction holds under every assumption I can test, only the size moves.&lt;/p&gt;

&lt;p&gt;In the controlled runs, "no test failures" means tests the agent wrote itself, and the count differed by condition: 116.8 tests per run on average when clearing after every task, 106.8 when never clearing. The three-task reference condition was selected after the fact, as the observed minimum.&lt;/p&gt;

&lt;p&gt;I'd like to see the same measurement run against other people's logs.&lt;/p&gt;

&lt;h2&gt;
  
  
  The data
&lt;/h2&gt;

&lt;p&gt;Report, datasets and recomputation scripts are public:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Corpus report and dataset: &lt;a href="https://doi.org/10.5281/zenodo.22759216" rel="noopener noreferrer"&gt;10.5281/zenodo.22759216&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Peer-reviewed report: &lt;a href="https://doi.org/10.32388/0BV3Z8" rel="noopener noreferrer"&gt;10.32388/0BV3Z8&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Context-clearing experiment, 36 runs: &lt;a href="https://doi.org/10.5281/zenodo.22759217" rel="noopener noreferrer"&gt;10.5281/zenodo.22759217&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Evgenii Arsentev, PhD - Chief Executive Officer. I measure how AI agents spend money, and publish the data and the scripts. More at &lt;a href="https://arsentev.ai" rel="noopener noreferrer"&gt;arsentev.ai&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>claudecode</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
