<?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: Iyadh Khalfallah</title>
    <description>The latest articles on DEV Community by Iyadh Khalfallah (@iyadh_khalfallah).</description>
    <link>https://dev.to/iyadh_khalfallah</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3866565%2Ff08c8c6f-8152-4312-a14b-7c1a32012258.jpg</url>
      <title>DEV Community: Iyadh Khalfallah</title>
      <link>https://dev.to/iyadh_khalfallah</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iyadh_khalfallah"/>
    <language>en</language>
    <item>
      <title>I Analyzed 42 Claude Code Sessions. 69% of My Tokens Were Wasted.</title>
      <dc:creator>Iyadh Khalfallah</dc:creator>
      <pubDate>Tue, 07 Apr 2026 22:34:36 +0000</pubDate>
      <link>https://dev.to/iyadh_khalfallah/i-analyzed-42-claude-code-sessions-69-of-my-tokens-were-wasted-1od2</link>
      <guid>https://dev.to/iyadh_khalfallah/i-analyzed-42-claude-code-sessions-69-of-my-tokens-were-wasted-1od2</guid>
      <description>&lt;p&gt;Every turn you type in Claude Code costs more than the last. By turn 200, you're paying 10x for the same work. By turn 664, it's 27.3x.&lt;/p&gt;

&lt;p&gt;I didn't guess these numbers. I measured them across 42 of my own sessions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;My worst session: 664 turns, &lt;strong&gt;27.3x waste factor&lt;/strong&gt;, burned &lt;strong&gt;192M tokens&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;20 out of 42 sessions ran at &lt;strong&gt;5x+ waste&lt;/strong&gt; or higher&lt;/li&gt;
&lt;li&gt;Across my sessions: &lt;strong&gt;744M tokens consumed&lt;/strong&gt;. With rotation: &lt;strong&gt;233M&lt;/strong&gt;. That's &lt;strong&gt;69% less quota in my case&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;I also found a &lt;strong&gt;prompt caching bug&lt;/strong&gt; in Claude Code 2.1.69 to 2.1.89. 15 of my sessions had broken caching, one running 196 turns at &lt;strong&gt;0% cache ratio&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So why does this happen, and what did I build to fix it?&lt;/p&gt;




&lt;h2&gt;
  
  
  The Problem: Every Turn Re-sends Everything
&lt;/h2&gt;

&lt;p&gt;Claude Code re-sends your entire conversation history on every single turn. The cost grows linearly while useful output stays flat.&lt;/p&gt;

&lt;p&gt;Real data from my worst session:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Point in session&lt;/th&gt;
&lt;th&gt;Tokens/Turn&lt;/th&gt;
&lt;th&gt;Waste Factor&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Turn 1&lt;/td&gt;
&lt;td&gt;~20K&lt;/td&gt;
&lt;td&gt;1x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Turn 100&lt;/td&gt;
&lt;td&gt;~100K&lt;/td&gt;
&lt;td&gt;5x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Turn 200&lt;/td&gt;
&lt;td&gt;~200K&lt;/td&gt;
&lt;td&gt;10x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Turn 400&lt;/td&gt;
&lt;td&gt;~350K&lt;/td&gt;
&lt;td&gt;17x&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Turn 664 (end)&lt;/td&gt;
&lt;td&gt;~551K&lt;/td&gt;
&lt;td&gt;27.3x&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is why your rate limit gets hit in 20 minutes. You're not doing more work, you're paying linearly more for the same work on every turn.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Manual Rotation Fails
&lt;/h2&gt;

&lt;p&gt;You could rotate sessions manually, but you lose context and waste time re-explaining what you were doing. You never know the optimal rotation point. You break your flow every time. And the handoff between sessions is lossy: critical details get dropped.&lt;/p&gt;

&lt;p&gt;How lossy? I measured it. On my last session rotation, only &lt;strong&gt;35 out of 97 facts survived the handoff&lt;/strong&gt;. That's a 46% preservation rate using text-similarity scoring. In token terms, re-discovery overhead is about &lt;strong&gt;8% of your first 10 turns&lt;/strong&gt;, so the raw cost isn't terrible. The real problem is &lt;em&gt;which&lt;/em&gt; facts get dropped: commands run (6/44 preserved), errors hit (0/3), files read (0/5). The next session had no idea what failed or why.&lt;/p&gt;

&lt;h2&gt;
  
  
  How Clauditor Fixes This
&lt;/h2&gt;

&lt;p&gt;I built &lt;a href="https://github.com/IyadhKhalfallah/clauditor" rel="noopener noreferrer"&gt;clauditor&lt;/a&gt;, a CLI tool that hooks into Claude Code via 7 lifecycle hooks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;UserPromptSubmit&lt;/strong&gt; blocks bloated sessions and detects "continue" prompts that would waste tokens&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PreToolUse&lt;/strong&gt; prevents known errors before they happen&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PostToolUse&lt;/strong&gt; monitors tool calls and blocks during autonomous work when waste is high&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;PreCompact / PostCompact&lt;/strong&gt; measures what gets lost during compaction&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SessionStart&lt;/strong&gt; initializes tracking and loads rotation context for new sessions&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop&lt;/strong&gt; generates the final session report with waste analysis&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It calculates your &lt;strong&gt;waste factor&lt;/strong&gt; in real-time and blocks sessions when efficiency drops below a threshold, telling you to start a fresh session. When you rotate, it generates a structured handoff template so your next session picks up where you left off:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gu"&gt;## TASK&lt;/span&gt;
Implementing OAuth2 flow for the dashboard API

&lt;span class="gu"&gt;## COMPLETED&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Database schema for tokens ✓
&lt;span class="p"&gt;-&lt;/span&gt; Token refresh endpoint ✓
&lt;span class="p"&gt;-&lt;/span&gt; Unit tests for refresh flow (14 passing) ✓

&lt;span class="gu"&gt;## FAILED APPROACHES&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; Tried passport.js, incompatible with our middleware chain
&lt;span class="p"&gt;-&lt;/span&gt; Redis session store caused race conditions under load

&lt;span class="gu"&gt;## CURRENT STATE&lt;/span&gt;
Working on: Authorization code flow
Blocked by: CORS config for redirect URIs
Next step: Add allowed origins to nginx.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This preserves what actually matters: the structured decisions, failures, and next steps. Not a lossy summary.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Rotation Economics
&lt;/h2&gt;

&lt;p&gt;Most people miss this part: rotation isn't just about stopping waste, it's a net positive.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rotation saves &lt;strong&gt;65% of tokens per turn&lt;/strong&gt; on average&lt;/li&gt;
&lt;li&gt;Re-discovery costs ~17K tokens, about &lt;strong&gt;8% overhead&lt;/strong&gt; in your first 10 turns&lt;/li&gt;
&lt;li&gt;At 10x waste, the ROI is &lt;strong&gt;400x&lt;/strong&gt;. You spend 17K tokens re-discovering context and save millions by not running at 200K+/turn&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In my data, clauditor blocked 10 sessions from burning more quota. With rotation on all 42 sessions, I would have used &lt;strong&gt;233M tokens instead of 744M&lt;/strong&gt;. Your numbers will vary depending on session length. Run &lt;code&gt;clauditor report&lt;/code&gt; to see your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Bug Nobody Knew About
&lt;/h2&gt;

&lt;p&gt;While building clauditor, I discovered that Claude Code versions 2.1.69 through 2.1.89 had a &lt;strong&gt;prompt caching bug&lt;/strong&gt; causing 10 to 20x token burn.&lt;/p&gt;

&lt;p&gt;Running &lt;code&gt;clauditor doctor&lt;/code&gt; on my sessions found &lt;strong&gt;14 sessions with degraded caching&lt;/strong&gt;. The worst: 196 turns running at &lt;strong&gt;0% cache ratio&lt;/strong&gt;, meaning every token was billed at full price with zero caching. Another session dropped from 100% cache to 20% mid-session.&lt;/p&gt;

&lt;p&gt;I didn't set out to find bugs, but when you measure token usage at this level of granularity, anomalies become visible. Run &lt;code&gt;clauditor doctor&lt;/code&gt; to check if your sessions are affected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install It
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# npm&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @iyadhk/clauditor &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; clauditor &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Homebrew&lt;/span&gt;
brew tap IyadhKhalfallah/clauditor &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; brew &lt;span class="nb"&gt;install &lt;/span&gt;clauditor &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; clauditor &lt;span class="nb"&gt;install&lt;/span&gt;

&lt;span class="c"&gt;# Zero install&lt;/span&gt;
npx @iyadhk/clauditor
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then run:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;clauditor report&lt;/code&gt; to see your waste factors across sessions&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;clauditor doctor&lt;/code&gt; to check if your Claude Code version has the caching bug&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;clauditor handoff-report&lt;/code&gt; to measure how much knowledge your last rotation lost&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;272 GitHub stars, 6,000+ downloads, 275 tests, MIT licensed.&lt;/strong&gt; Runs locally, no cloud dependency.&lt;/p&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/IyadhKhalfallah/clauditor" rel="noopener noreferrer"&gt;github.com/IyadhKhalfallah/clauditor&lt;/a&gt;&lt;br&gt;
Website: &lt;a href="https://clauditor.ai" rel="noopener noreferrer"&gt;clauditor.ai&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's your worst waste factor?&lt;/strong&gt; Run &lt;code&gt;clauditor report&lt;/code&gt; and drop your number in the comments. I'm curious how it compares to my 27.3x.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>opensource</category>
      <category>devtools</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
