DEV Community

Cover image for I tracked where my Claude Code tokens actually go. 37% were wasted.
Egor Fedorov
Egor Fedorov

Posted on

I tracked where my Claude Code tokens actually go. 37% were wasted.

Last month I hit $180 on my Claude Code bill. I use Opus daily — refactoring, bug fixes, code reviews, building features. But something felt off. Sessions were getting expensive, and I couldn't tell why.

So I did what any developer would do: I built a tool to find out.

## The experiment

I started manually logging which files Claude reads during a typical session. After a week of tracking, the pattern was clear:

Out of every 10 files Claude reads, only 6-7 actually matter. The rest — configs, READMEs, lock files, type definitions — get loaded into context and never referenced again.

Quick math:

  • package.json read "just in case" → 120 tokens, every time
  • A README for context → 2,400 tokens, used once, forgotten
  • tsconfig.json → 400 tokens, never needed

At ~$15/M tokens on Opus, 30-50% of my bill was going to irrelevant context.

## The plugin

I built claude-context-optimizer — a Claude Code plugin that silently tracks every file read, edit, and search. No configuration. No setup. Just install and forget.

It hooks into Claude Code's tool pipeline (PostToolUse, SessionStart, SessionEnd) and records:

  • Which files were read and how many times
  • Which files were actually edited (high value)
  • Which files were read once and never used (waste)
  • Estimated token count per file (~4 tokens/line)

## Context Heatmap

Run /cco and see exactly where your tokens went:

Context Heatmap

Green bars = files that were actually edited or referenced multiple times. Red bars = read once, never used. That README.md eating 2,400 tokens? Pure waste.

## Efficiency Score

Run /context-digest for a weekly report card:

Efficiency Score

You get a grade (S through F) based on four metrics:

  • Context Precision — how many files you read were actually useful
  • Edit Efficiency — ratio of edits to reads
  • Search Accuracy — are your Grep/Glob searches finding the right files?
  • Focus Score — are you re-reading files too often?

Plus real cost breakdowns: total spent, wasted, and saveable per month.

## Token ROI Report

/cco-report gives you the full picture across all tracked sessions:

Token ROI Report

Trends over time, top wasted files, top useful files, and specific recommendations.

## How it works under the hood

The architecture is simple — no build step, no dependencies, just Node.js scripts:

How it works

Every session gets a JSON file tracking per-file reads, edits, and usefulness. When a session ends, the plugin updates a global patterns database that learns which files are consistently useful or wasted across sessions.

## The features I didn't expect to need

Token Budget/cco-budget set 80000 sets a token limit with real-time warnings at 50/70/85/95%. Knowing you're at 70% makes you think twice before reading another file "just in case."

Git-Aware Suggestions/cco-git analyzes your current diff and suggests files you'll actually need. Combined with historical patterns, it knows that when you touch auth-service.ts, you almost always need user.model.ts too.

Context Templates/cco-templates create bug-fix saves a set of files you always need. Next time, /cco-templates apply bug-fix loads exactly the right context.

## Results after 2 weeks

  • Waste ratio dropped from ~40% to ~15%
  • Average session cost decreased by roughly 25%
  • Sessions feel faster — less context means faster responses
  • I stopped reading README.md and package.json reflexively
  • Created 3 templates that save ~5 minutes of setup per session

## The meta part

The entire plugin — 2,500+ lines of code, 8 slash commands, SVG visualizations, README — was built in a single Claude Code session using Opus. Claude built the tool that optimizes Claude. Make of that what you will.

## Try it

Install in one command:

git clone https://github.com/egorfedorov/claude-context-optimizer.git ~/.claude/plugins/claude-context-optimizer

No npm install, no build, no config. MIT license. Zero telemetry — everything stays local.

GitHub: egorfedorov/claude-context-optimizer

Stars and PRs welcome.


What's your Claude Code bill looking like? I'm curious if others have noticed the same waste patterns.

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.