AI & ML DevOps General Tech Community Best Practices & Tools All News About Contact
advertisement
AI & ML

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

May 2026 8 min read
I tracked where my Claude Code tokens actually go. 37% were wasted.
Back to AI & ML

Last month I reached $180 on my Claude Code bill. I use Opus daily: refactoring, bug fixes, code review, feature creation. But something felt wrong. Sessions were getting expensive and I didn't know why.

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

## The experiment

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

For every 10 files Claude reads, only 6 or 7 really matter. The rest (configs, README files, lock files, type definitions) are loaded in context and never referenced again.

Quick Math:

-

package.json

read "just in case" → 120 tokens, each time - A README for context → 2400 tokens, used once, forgotten

-

tsconfig.json

→ 400 tokens, never needed

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

## The plugin

I created claude-context-optimizer, a Claude Code plugin that silently tracks every file read, edited and searched. No configuration. No configuration. Just install it and forget it.

Connects to Claude Code's tool pipeline (PostToolUse, SessionStart, SessionEnd) and logs:

- 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:

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

## Efficiency score

Run /context-digest

for a weekly report card:

You earn a grade (S to F) based on four metrics:

- Context accuracy: how many files read were actually useful

- Editing efficiency: ratio of edits and reads

- Search Accuracy: Do your Grep/Glob searches find the correct files?

- Focus Score: Are you re-reading files too often?

Plus, actual cost breakdowns: total spent, wasted and saveable by month.

## Token ROI Report

/cco-report

gives you a complete picture of all tracked sessions:

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

##How it works under the hood

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

Each session gets a JSON file that tracks the reads, edits, and utility of each file. When a session ends, the plugin updates a global pattern database that learns which files are consistently useful or wasted across sessions.

## The features you 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-compatible hints: /cco-git

analyzes your current difference and suggests files you will 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 creates bugfix

saves a set of files that you always need. Next time /cco-templates will apply the bug fix

loads exactly the correct context.

## Results after 2 weeks

- Waste ratio reduced from ~40% to ~15%

- Average session cost decreased by approximately 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 (2500+ lines of code, 8 forward slash commands, SVG visualizations, README) was created in a single Claude Code session using Opus. Claude created 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 installation, no build, no configuration. MIT lice

Related Coverage

AI & ML

DumbQuestion.ai - Self-Awareness, Prompt Injection, Search Intent... and darkness

AI & ML

Gemini 2.5 Flash vs Claude 3.7 Sonnet: 4 Production Constraints That Made the Decision for Me

AI & ML

I Made Claude Code Think Before It Codes. Here's the Prompt.