<?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.us-east-2.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 tried "weight-space programming" on 6 kinds of models. Here's where it works and where it breaks.</title>
      <dc:creator>Iyadh Khalfallah</dc:creator>
      <pubDate>Fri, 06 Nov 2026 13:44:17 +0000</pubDate>
      <link>https://dev.to/iyadh_khalfallah/i-tried-weight-space-programming-on-6-kinds-of-models-heres-where-it-works-and-where-it-breaks-58e3</link>
      <guid>https://dev.to/iyadh_khalfallah/i-tried-weight-space-programming-on-6-kinds-of-models-heres-where-it-works-and-where-it-breaks-58e3</guid>
      <description>&lt;p&gt;A few days ago, MIT CSAIL researchers published &lt;a href="https://rikiyat.github.io/blog/weight-space-programming/" rel="noopener noreferrer"&gt;Sparks of Weight-Space Programming&lt;/a&gt;: a frontier model that reads a neural network's weights and edits them directly, with no gradient descent, to change its behavior.&lt;/p&gt;

&lt;p&gt;That's a big claim. If it holds, models stop being black boxes you retrain and become something closer to code: you read them, patch them, review the diff.&lt;/p&gt;

&lt;p&gt;So I tested it. Over a few days I used an AI coding agent as a "model engineer": it inspected models, wrote edits to their weights, tested them on held-out data, and versioned every change. I tried logistic regression, small neural nets, gradient-boosted trees, an RL agent, a CNN and a small LLM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Short version:&lt;/strong&gt; on classic and small models, it works, sometimes remarkably well. On LLMs, finding the cause inside the model works; writing an edit that holds up doesn't (yet).&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The result that surprised me: a model written with zero labels
&lt;/h2&gt;

&lt;p&gt;The usual way to get a model: collect labelled data, train. I tried the opposite. No labels, no training. The AI writes the model from what it knows.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Task:&lt;/strong&gt; will it rain (≥ 1 mm) tomorrow in 10 European cities, given today's weather (pressure, pressure change, humidity, cloud, wind, rain today…), using public &lt;a href="https://open-meteo.com/" rel="noopener noreferrer"&gt;Open-Meteo&lt;/a&gt; data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The catch that makes it fair:&lt;/strong&gt; the test period is &lt;strong&gt;July–October 2026, after the AI's knowledge cutoff&lt;/strong&gt;. It cannot have memorised the answers.&lt;/p&gt;

&lt;p&gt;The AI wrote the model as a small program of decision trees, each with a reason attached:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"why"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"falling barometer = low approaching; rising = high building"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"if"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pressure_change_24h"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;-3.4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"then"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"if"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pressure_change_24h"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;-7.2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"then"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"else"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
 &lt;/span&gt;&lt;span class="nl"&gt;"else"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"if"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"pressure_change_24h"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;3.4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"then"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;-0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"else"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;}}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only data it was allowed to look at was &lt;strong&gt;unlabelled&lt;/strong&gt;: feature percentiles, so "low pressure" can be written as &lt;code&gt;"p20"&lt;/code&gt; instead of guessing hPa values. A small compiler turns this program into a &lt;strong&gt;standard XGBoost model file&lt;/strong&gt;, which loads in stock XGBoost like any trained model.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxq9e0qfanz6uj5pwgz14.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxq9e0qfanz6uj5pwgz14.png" alt="Rain forecaster results" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Written with zero labels: AUC 0.809.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;XGBoost trained on 2.5 years (9,110 labelled days): 0.839.&lt;/li&gt;
&lt;li&gt;XGBoost trained on 60 labelled days: 0.747.&lt;/li&gt;
&lt;li&gt;"Tomorrow = today" persistence: 0.719.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The hand-written model recovers about &lt;strong&gt;75% of the gain&lt;/strong&gt; that 2.5 years of training gives over persistence, and it beats a model trained on two months of data.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqww6urd0g6jjr6d4k58k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqww6urd0g6jjr6d4k58k.png" alt="ROC curves" width="800" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a second round, I let the AI read 2024–25 labels (diagnostics only, still no training), revise its trees, and validate on Jan–Jun 2026 before a single final test run. That moved AUC from 0.809 to 0.815 and log-loss from 0.493 to 0.479. It's a modest gain, and along the way I caught a bug in my own analysis script (averaging log-odds where I meant probabilities), which led to the calibration fix.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Caveats, honestly:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The trained baseline is a reasonable but untuned XGBoost. A tuned one would widen the gap.&lt;/li&gt;
&lt;li&gt;With plenty of data, training is still cheaper and better. The interesting case is &lt;strong&gt;day one, before any data exists&lt;/strong&gt;, or when data is scarce.&lt;/li&gt;
&lt;li&gt;On a famous dataset (breast cancer), a written model reached AUC 0.972 vs 0.985 trained, but that dataset may be memorised, so I lead with the rain test.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Fixing trained models by editing weights
&lt;/h2&gt;

&lt;p&gt;The second question: when a trained model has a flaw, can you fix it by editing it directly instead of retraining?&lt;/p&gt;

&lt;p&gt;Each experiment followed the same loop:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Diagnose&lt;/strong&gt; inside the model: which inputs and units drive the bad behavior.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write a small edit&lt;/strong&gt;: change a few weights, or add a "rule block" (a tiny gated sub-network that only fires when its conditions hold).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Test before/after&lt;/strong&gt; on new data, per segment, and flag any regression.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Commit&lt;/strong&gt; it as a reversible patch: the base model is never modified, and the current model = base + active patches.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuiifg8543pzibvoirr31.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuiifg8543pzibvoirr31.png" alt="Before and after edits" width="800" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(The fraud, router and delivery-time models were trained on synthetic data I generated with a realistic flaw built in, so the "right answer" is known.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A fraud model biased against one currency.&lt;/strong&gt; It had learned from old data that Brazilian real transactions were 3.9× riskier; recent data says 1.2×. The edit shrinks that input's weights toward the real level. 32 weights changed; false flags on BRL fell from 7.2% to 2.0%, and overall AUC &lt;em&gt;improved&lt;/em&gt; (0.817 → 0.837).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A new scam, added the same day.&lt;/strong&gt; "Gift card AND amount &amp;gt; $500" was a new pattern the model had never seen. Instead of retraining, I added a new input and a rule block: 23 weights. Catch rate on that scam went from 10% to 98%, and &lt;strong&gt;nothing outside the rule changed&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A ticket router with an old habit.&lt;/strong&gt; A 4-class PyTorch router kept sending enterprise customers' technical tickets to account managers (an outdated policy), and missed account-takeover tickets. Two patches took takeover tickets from 2.6% to 95.8% correctly routed; the other tickets' outputs moved by less than 1e-7, and no other prediction flipped.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Trees.&lt;/strong&gt; The easiest case. In a gradient-boosted model you can neutralise a feature by editing split thresholds, or append a hand-written tree. The edited XGBoost JSON still loads in stock XGBoost.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An RL agent that learned a bug.&lt;/strong&gt; A game agent (catch a falling ball) was trained in an environment with a rendering bug: a "shadow" showing where the ball would land. The agent learned to follow the shadow. Remove the bug and it scores −0.1. I hand-wrote a small circuit that &lt;em&gt;computes&lt;/em&gt; the shadow from the ball's position and direction, and grafted it into the agent's inputs: score +19.3, vs +19.4 originally. (Honestly: retraining this toy is also cheap. The point is that the repair was exact and explainable.)&lt;/p&gt;

&lt;h3&gt;
  
  
  Lessons from the failures along the way
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Copy a real reference, not an average.&lt;/strong&gt; In a small neural net, setting the biased currency to "the average of all currencies" failed: nonlinear units don't average. Setting it to behave like one real comparable currency (USD) worked.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weight size lies.&lt;/strong&gt; Big weights aren't necessarily what matters. Behavioral tests on real data were the only reliable guide.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Don't guess the architecture.&lt;/strong&gt; Importing a PyTorch state_dict with BatchNorm, a guessed layer order produced a model that loaded fine and was silently wrong. Now the tool refuses and asks for the layout.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  3. Where it breaks
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9f078q77cykfkd09rft0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F9f078q77cykfkd09rft0.png" alt="Where it works" width="799" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  You can't edit in a skill the model never learned
&lt;/h3&gt;

&lt;p&gt;A CNN learned a shortcut: a camera stamp that correlated with one class. Zeroing 32 weights removed the shortcut completely, but accuracy stayed at &lt;strong&gt;52%&lt;/strong&gt;, because without the shortcut the model had never learned the actual shapes. Hand-writing a straight-edge detector (40 weights) brought it to 71%. Partial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Editing removes or redirects behavior; it doesn't easily add knowledge.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  LLMs: finding the cause works, the edit doesn't hold up
&lt;/h3&gt;

&lt;p&gt;The MIT post's showcase edit makes Qwen3.5-0.8B stop overthinking (end its reasoning earlier). I verified their released edit: it makes the end-of-reasoning token about &lt;strong&gt;29× more likely&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Then I tried to find such an edit myself, with a 0.8B model on a laptop. I found real directions linked to stopping, and an automated search over layers picked the three that moved the stop probability most on my search set. On a held-out measurement, my edit moved it &lt;strong&gt;1.2×&lt;/strong&gt;. Effectively nothing.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4u5qcblvgkv9fxoq9dgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F4u5qcblvgkv9fxoq9dgy.png" alt="LLM result" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This matches what others replicating the paper report: diagnosis transfers, edits often don't. The MIT result used a frontier model doing the editing; doing it reliably is still an open problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  So what is this, really?
&lt;/h2&gt;

&lt;p&gt;My takeaway after all of this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Reading a model works on every model I tried&lt;/strong&gt;, including the LLM. That alone is useful: explaining why a model does something, from inside the model, not from guesses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Editing works today on classic and small models&lt;/strong&gt;: fraud, credit, pricing, routing, forecasting. Those are most of the models running in production. Fixes take minutes instead of a retraining cycle, they're precise, reversible and explainable.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Writing models from knowledge is real&lt;/strong&gt;, at least for tabular problems. It gives you a working model on day one, then you correct it as labels arrive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Large models are the frontier.&lt;/strong&gt; You can read them but not reliably patch them yet. That gap probably shrinks with each generation of AI models.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The bigger idea is that models stop being compiled blobs you re-cook with more data, and become source code: something you can read, diff, review, test and patch. We built git, code review and CI for code. Models will need the same layer.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The tooling: a small CLI that imports PyTorch, scikit-learn and XGBoost models, exposes inspection tools (feature effects, unit activity, weights), applies JSON edit ops (&lt;code&gt;shrink_input_toward&lt;/code&gt;, &lt;code&gt;project_out&lt;/code&gt;, &lt;code&gt;add_rule&lt;/code&gt;…), runs before/after evals per slice, and exports back to PyTorch (&lt;code&gt;torch.export&lt;/code&gt;), scikit-learn or XGBoost. Code: &lt;a href="https://github.com/IyadhKhalfallah/weight-space-programming" rel="noopener noreferrer"&gt;https://github.com/IyadhKhalfallah/weight-space-programming&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you have a model with a flaw you'd like to try this on, I'd love to hear from you.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>machinelearning</category>
      <category>ai</category>
      <category>python</category>
      <category>xgboost</category>
    </item>
    <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>
