claude code token optimizer vscode extension

claude code token optimizer vscode extension

# claude# opensource# productivity# vscode
claude code token optimizer vscode extensionemi

TL;DR I built a vscode extension that reads the session transcripts claude code already writes to...

TL;DR
I built a vscode extension that reads the session transcripts claude code already writes to ~/.claude/projects/ and turns them into a dashboard that shows users the estimated $ spent, how a session could have been improved, and which actions caused excessive tokens to be used. It's free, MIT licensed, and on the vscode
marketplace. This post is to introduce the extension, how it works, and hopefully to get feedback or future collaborators to help me improve it!

what it does:

  • for each session transcript, it runs 10 detectors each with its own token and dollar estimate
  • separates findings into one off fixes (one session) and habits (across sessions)
  • tracks cache reuse and cost per day, and warns when the last 7 days are worse than the prior 7 days
  • drills into one session turn by turn to show users where their tokens actually went

limits: claude code only (for now), all costs are estimates from a rate table.


claude code writes every turn of every session to a JSONL file in ~/.claude/projects/, with full usage on each line including input and output tokens, cache reads, writes, tool calls, and compactions. So the data to answer "where did that session's money go" already exists.

claude code token optimizer preforms read-only operations those transcripts, then runs them through a rules engine, and formats the results in the sidebar view. everything stays local, no data leaves the machine or is sent to any service.

the view:

  • a potential savings panel with dollars and tokens
  • the portion of tokens that was waste
  • a breakdown by mistake category and a ranking of the most common ones
  • token totals
  • cache reuse
  • tool usage
  • the most expensive sessions
  • a status-bar item shows live spend and cache reuse for the current session.

The claude code token optimizer dashboard showing a potential savings panel, a most common mistakes ranking, and an efficiency over time chart

The claude code token optimizer dashboard showing improvement suggestions

It's on the vs code marketplace,
and the source is at github.com/emihiggins/ai-insights-ext.

what it flags

currently there are 10 detectors in place, one file each in src/rules/:

  • context compactions
  • context pressure (peak prompt at 80% or more of the model's window)
  • broad or unscoped searches
  • uncapped command output
  • oversized or repeated reads
  • reading a file back right after editing it
  • redundant inspection commands
  • failed or interrupted tool calls with output that was billed anyways
  • low cache reuse
  • round-trips with a large prompt and zero to no output

most of the work is in what they don't flag. the redundant command detector only counts read-only inspection commands grep, rg, find, cat, ls, git status, git log, git diff run repeatedly 3 or more times in one session. re-running tests or a build is the agent doing its job, so those are deliberately left out. the regression banner has the same problem in a different place, a quiet week makes everything look like a regression, so it only fires when both 7-day windows have a minimum of 3 active sessions and 20k tokens. low usage history still renders the chart, it just doesn't raise an alert.

honest numbers

claude code's local stats report costUSD: 0, so every dollar figure is an estimate from a rate table in src/pricing.ts: per 1M tokens, Opus $5/$25, Sonnet $3/$15, Haiku $1/$5, with cache reads at 0.1× input and cache writes at 1.25× (5-minute TTL) or 2× (1-hour TTL). if your pricing differs, you should edit the table. (this is also something I plan to keep updating as more models and updated pricing becomes available)

scope

I build the data layer (parser), session model, pricing, rules, discovery — has no vscode dependency and is tested against fixtures and a temp ~/.claude tree. chokidar and chart.js are bundled at build time, so the .vsix ships no runtime node_modules.