{
  "id": 18379084,
  "title": "Replaying 147 Claude Code & Codex Sessions to Tune autoCompactWindow (and Catching a 3x Token Overcount)",
  "url": "https://urgent.news/2026/11/05/replaying-147-claude-code-codex-sessions-to-tune-autocompactwindow",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-05T21:39:31.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/princejain756/replaying-147-claude-code-codex-sessions-to-tune-autocompactwindow-and-catching-a-3x-token-2f43"
  },
  "original_language": "en",
  "account": "This report analyzes the local Claude Code and Codex sessions on a machine, totaling 147 sessions with 3,197 raw records. After deduplication, 2,284 real API turns, 255.79M input tokens, and a 43.9% cache hit rate were identified. Notably, 13.4% of turns accounted for 47.8% of weighted token cost, specifically those running above 200K context. The report reveals that early tool outputs carry significant \"Context Rent,\" with a single 12K-token file read or git diff output on turn 3 of a 45-turn session occupying the prompt window for 42 subsequent turns.\n\nCompaction often occurs immediately after, causing the agent to re-read the exact same files on the next 3 turns due to the summary dropping active file paths. To mitigate this issue, the author developed compactsim, a zero-dependency Node.js CLI tool to audit ~/.claude/projects and ~/.codex/sessions offline and run counterfactual compaction simulations against actual turn history. Running compactsim on the 147-session corpus revealed that adjusting the autoCompactWindow parameter can significantly reduce token usage and compaction frequency.\n\nWith the default autoCompactWindow, the simulator found that baseline token usage was 160.79M weighted token-equivalents (tok-eq), with 0% savings and 9 compactions. However, by setting autoCompactWindow to 250,000 tokens, the system achieved 114.93M tok-eq, a 28.5% reduction in token usage and only 10 compactions. Further adjustments up to 150,000 tokens resulted in even greater savings, with 89.49M tok-eq, a 44.3% reduction, and 17 compactions. The report also highlights the impact of mid-session cache-bust spikes and the importance of considering both uncached re-prefill penalties and empirical post-compaction file re-read taxes when implementing compaction strategies.",
  "summary": "My first script for checking local Claude Code token usage summed raw assistant lines in ~/.claude/projects/**/*.jsonl and overcounted session 4baee81b by 3.0x (33 JSONL usage rows for 11 actual API turns). Whenever a single turn emits text plus multiple tool_use blocks, Claude Code writes separate streaming records sharing the same message.id , and every record repeats the cumulative prompt…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 2,
    "also_reported_by": [
      {
        "outlet": "XDA Developers",
        "title": "Someone used Claude Code to get Need for Speed: Underground 2 running in browsers with online multiplayer",
        "url": "https://urgent.news/2026/11/04/someone-used-claude-code-to-get-need-for-speed-underground-2-running",
        "published": "2026-11-04T07:04:47.000Z"
      }
    ]
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}