<?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: Leo</title>
    <description>The latest articles on DEV Community by Leo (@liaojiwoo).</description>
    <link>https://dev.to/liaojiwoo</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%2F4250850%2F4179faf1-8ee2-426c-8a15-049d5b62d68c.png</url>
      <title>DEV Community: Leo</title>
      <link>https://dev.to/liaojiwoo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/liaojiwoo"/>
    <language>en</language>
    <item>
      <title>Is It Cheaper to Keep a Long Codex Session or Start a New One?</title>
      <dc:creator>Leo</dc:creator>
      <pubDate>Wed, 18 Nov 2026 02:57:49 +0000</pubDate>
      <link>https://dev.to/liaojiwoo/is-it-cheaper-to-keep-a-long-codex-session-or-start-a-new-one-31a1</link>
      <guid>https://dev.to/liaojiwoo/is-it-cheaper-to-keep-a-long-codex-session-or-start-a-new-one-31a1</guid>
      <description>&lt;p&gt;When you use Codex on a substantial project, you eventually face a familiar decision: the conversation has grown long, but the work is not finished.&lt;/p&gt;

&lt;p&gt;You can keep going in the same session, preserving the discussion and tool history. Or you can ask Codex to write a handoff document, summarize the progress and decisions, and continue in a new session.&lt;/p&gt;

&lt;p&gt;The first approach may reuse more cached input. The second sends less context. Which one costs less?&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://linux.do/t/topic/2092533" rel="noopener noreferrer"&gt;discussion on the Chinese developer community LINUX DO&lt;/a&gt; raised exactly this question. One useful observation was that a new session might have a lower cache hit rate while still costing less because it sends substantially fewer tokens.&lt;/p&gt;

&lt;p&gt;That distinction matters: &lt;strong&gt;cache hit rate and total cost are not the same metric.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How a New Session Can Cost Less
&lt;/h2&gt;

&lt;p&gt;Suppose an API charges $1 per million uncached input tokens and $0.10 per million cached input tokens. These are hypothetical prices chosen to make the calculation easy, not a quote for any particular model or provider.&lt;/p&gt;

&lt;p&gt;Consider two requests:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Continue the long session:&lt;/strong&gt; 200,000 input tokens, of which 180,000 are cached and 20,000 are uncached.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Start a new session:&lt;/strong&gt; 30,000 input tokens, all uncached for this request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The long session’s input cost is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;180,000 × $0.10 / 1,000,000 = $0.018
 20,000 × $1.00 / 1,000,000 = $0.020
Total: $0.038
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new session’s input cost is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;30,000 × $1.00 / 1,000,000 = $0.030
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The long session has a 90% cache hit rate. The new session has a 0% hit rate. Yet the new session’s input costs less for this request.&lt;/p&gt;

&lt;p&gt;The reason is straightforward: discounted input still costs money. The long session sends much more of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;This is an illustration of input costs for one request, not a benchmark of complete tasks.&lt;/strong&gt; It excludes the cost of generating the handoff, rereading files, producing output, and any separately billed cache writes. Different token counts or prices can reverse the result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why a Coding Session Accumulates So Much Context
&lt;/h2&gt;

&lt;p&gt;You might type only “keep updating this page,” but the model’s input can include much more than that sentence: system instructions, project rules, previous messages, tool definitions, file contents, and results from earlier tool calls.&lt;/p&gt;

&lt;p&gt;A task can also involve several model calls. Codex may read a file, inspect related components, run a command, examine an error, and make another change. From your perspective, that is one task. From the API’s perspective, it can be a sequence of requests, each carrying context.&lt;/p&gt;

&lt;p&gt;That helps explain why the same short instruction can produce very different usage at the beginning of a session and much later in it. The &lt;a href="https://juejin.cn/post/7586482851103195171" rel="noopener noreferrer"&gt;Qoder team’s explanation of agent credit consumption&lt;/a&gt; describes a similar cycle of model calls and tool results.&lt;/p&gt;

&lt;h2&gt;
  
  
  Read the Bill, Not Just the Cache Percentage
&lt;/h2&gt;

&lt;p&gt;Prompt caching lets eligible requests reuse matching context and receive cached-input pricing rather than processing every input token at the ordinary rate.&lt;/p&gt;

&lt;p&gt;But “90% cached” is not enough information to understand a bill. You also need to know:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;How many input tokens were sent in total.&lt;/li&gt;
&lt;li&gt;How many were billed as cache reads versus uncached input.&lt;/li&gt;
&lt;li&gt;Whether cache writes were charged separately.&lt;/li&gt;
&lt;li&gt;How many output tokens were generated.&lt;/li&gt;
&lt;li&gt;How many calls were needed to finish the task.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Providers and models do not all report or bill these categories in the same way. Some usage reports include cached tokens within the total input count, so you must subtract them before calculating uncached-input charges. Others expose cache-write categories separately. Follow the accounting rules for the specific model and service you use.&lt;/p&gt;

&lt;p&gt;For direct OpenAI API requests, the &lt;a href="https://developers.openai.com/api/docs/guides/prompt-caching" rel="noopener noreferrer"&gt;official prompt-caching guide&lt;/a&gt; notes that compaction can reduce cache reuse while the smaller input can still lower total cost. Whether a third-party gateway or client exposes the same fields needs to be checked separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Does Starting Fresh Make Sense?
&lt;/h2&gt;

&lt;p&gt;I would start with the relationship between the current task and the conversation history, rather than a fixed rule such as “restart after a certain number of tokens.”&lt;/p&gt;

&lt;p&gt;If the new task is largely unrelated to the previous work, a fresh session can make it easier to keep the context focused. For example, after a long discussion about a login page, an independent settings-page task may need the project rules and relevant files, but not the entire earlier conversation.&lt;/p&gt;

&lt;p&gt;If the work still depends on earlier reasoning, rejected approaches, or decisions that have not made it into the code, continuing the current session may be more practical. A new session has less context, but missing information can lead it to reread files, repeat investigations, or make changes that conflict with the original plan. That adds both cost and time.&lt;/p&gt;

&lt;p&gt;A handoff document sits between those approaches. It carries forward the information the next session needs without reproducing the whole conversation. A useful handoff can cover:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The current task and its status.&lt;/li&gt;
&lt;li&gt;What has already been completed.&lt;/li&gt;
&lt;li&gt;Important decisions and constraints.&lt;/li&gt;
&lt;li&gt;The next steps.&lt;/li&gt;
&lt;li&gt;Relevant files and unresolved issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new session should not be assumed to have zero cache reuse, either. The all-uncached request above is a simplifying assumption for the calculation, not a universal description of what happens when you start a new conversation.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Compare the Two Approaches for Your Own Work
&lt;/h2&gt;

&lt;p&gt;The useful comparison is &lt;strong&gt;the total cost of completing comparable tasks&lt;/strong&gt;, not the cache percentage on one request.&lt;/p&gt;

&lt;p&gt;Choose a small, repeatable task and use the same model and billing route. In one run, continue an existing conversation. In another, generate a handoff and begin a new session. Record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Model-call count.&lt;/li&gt;
&lt;li&gt;Uncached input tokens.&lt;/li&gt;
&lt;li&gt;Cached input tokens.&lt;/li&gt;
&lt;li&gt;Cache-write tokens, where applicable.&lt;/li&gt;
&lt;li&gt;Output tokens.&lt;/li&gt;
&lt;li&gt;Total billed cost.&lt;/li&gt;
&lt;li&gt;Elapsed time.&lt;/li&gt;
&lt;li&gt;Whether the result meets the same requirements.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Include the cost of writing the handoff in the fresh-session run. Repeat the comparison where practical, and record the tool version, task, and date. A single result can be affected by context differences, model output, and routing behavior.&lt;/p&gt;

&lt;p&gt;If your service does not expose all the relevant usage categories, say what is missing. An estimate can still be useful, but it should not be presented as a precise measurement.&lt;/p&gt;

&lt;p&gt;Also, API usage charges and subscription allowances are different accounting systems. A calculated API cost is not automatically equivalent to the amount of subscription allowance consumed.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Disclosure: I’m part of the &lt;a href="https://zashmodel.com/?utm_source=devto&amp;amp;utm_medium=article&amp;amp;utm_campaign=codex_cache_handoff" rel="noopener noreferrer"&gt;Zashmodel&lt;/a&gt; team. We build a multi-model API service, so model pricing and actual usage costs are directly relevant to our work. Whether you use a direct provider API or a third-party service, check how your specific model and route are billed before drawing conclusions from a cache percentage.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There is no universal answer to “keep going or start fresh.” Cache reuse is worth measuring, but it is only part of the bill. What matters is how much the completed task costs, how long it takes, and whether the result is usable.&lt;/p&gt;

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