Empirical log audit of 9,911 sessions: Claude Code prompt caching bottlenecks & optimization recommendations

Open 💬 1 comment Opened Jun 18, 2026 by Korck-lab

Hello Claude Code team!

We love using Claude Code. To better understand context efficiency, prompt caching economics, and cost management, we built claude-code-optimizer, an audit tool that ingests and analyzes local session log files (~/.claude/projects/).

We ran a deep audit across 9,911 real-world session logs (representing over 32 billion tokens of context and 200k assistant turns). We wanted to share the main resource bottlenecks we identified:

1. The Cost of Zombie Sessions (>30 turns)

  • Finding: Interactive sessions that exceed 30 turns without using /reset accumulate huge history windows. Out of the 24B quota units consumed, zombie sessions accounted for over 1.3B wasted tokens (repeating conversational history).
  • Recommendation: Consider adding a subtle CLI warning or tip suggesting a /reset when the turn count exceeds 30 or the context size crosses 300k tokens.

2. Cache Invalidation Loops (Unignored File Writes)

  • Finding: Files modified during a session that are not ignored in .claudignore immediately invalidate the prompt cache. On the subsequent turn, the entire context must be re-parsed and re-uploaded at full write rates ($3.75/M).
  • Recommendation: Enhance default prompt caching hygiene. Warn users or auto-stage rules to ignore frequently modified files/folders (such as build logs, package caches, lockfiles, or local database writes) if they trigger multiple cache invalidations.

3. System Prompt Tool/Skill Overhead

  • Finding: Every declared MCP tool and custom skill (which are not used in a given session) adds context overhead to every single turn. This accounted for ~7.2B context tokens of overhead in our dataset.
  • Recommendation: Support dynamic, session-based MCP tool loading or lazy-loading tool definitions based on active intent to keep the initial prompt cache overhead as light as possible.

We published our CLI audit tool and the detailed metrics on Korck-lab/claude-code-optimizer. We hope these empirical findings are useful for guiding future performance optimizations!

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗