A VS Code extension that shows how many tokens you've used for the folder you have open — for both Claude Code and Codex — with a live total in the status bar and a detailed breakdown per model and per prompt/session in a sidebar panel. Switch between the two tools with a toggle.
It reads the session logs the tools already write locally
(~/.claude/projects/… for Claude Code, ~/.codex/sessions/… for Codex).
No API keys, no network calls — it just parses local logs for the current
workspace folder and updates live as you work.
- Claude Code & Codex — a tab at the top of the panel toggles between them; the
status bar follows the active tool (e.g.
#️⃣ Claude 10.2M tok/#️⃣ Codex 219K tok). - Status bar indicator showing total tokens for the current folder. Hover for a per-model table; click to open the full dashboard.
- By model — calls, input, output, cache, and total tokens per model.
- By prompt (Claude Code) — every prompt, most recent first, with model and tokens.
- By session (Codex) — Codex logs cumulative per-session totals, so it breaks down by session rather than by individual prompt.
- Live updates via a file watcher; a refresh button is also provided.
- Accurate counting — deduplicates Claude Code's repeated per-block usage and
resumed-session copies (counting each real response once), and skips local
<synthetic>placeholder messages.
- Tokens =
input + output + cache read + cache write. - Model call = one time the model actually ran. A single prompt usually triggers many calls (each tool use / thinking step), so one prompt can show a large total.
- Codex records a cumulative total per session; the extension reads each session's final total.
- Download the latest
claude-code-token-optimizer-*.vsix(from a release, or build it). - In VS Code: Extensions panel →
...menu → Install from VSIX… and pick the file. (Or from a terminal:code --install-extension <path-to-vsix>.) - Reload the window.
npm install
npm run compile
npx @vscode/vsce package # produces the .vsixOr press F5 in VS Code to launch an Extension Development Host.
- Open a folder you've used with Claude Code or Codex.
- Look at the bottom-right status bar for the token total.
- Click it (or open the Token Usage Tracker view in the activity bar) for the full breakdown, and use the Claude Code / Codex tabs to switch tools.
If the folder has no sessions for the active tool, the status bar shows Claude: —
or Codex: —.
You don't have to trust the extension's internals. Two ways to verify:
- The tools' own counters — run
/costin Claude Code or/statusin Codex and compare (use a fresh single-session folder for an apples-to-apples comparison). crosscheck.js— a standalone, readable script in this repo that recomputes the totals from the raw logs:node crosscheck.js [folder] # defaults to the current folder
| Setting | Description |
|---|---|
claudeTokenOptimizer.projectsPath |
Override the path to ~/.claude/projects if your Claude Code logs live somewhere non-standard. |
- Token Usage Tracker: Refresh
- Token Usage Tracker: Toggle Claude Code / Codex
Both tools record each session as JSONL logs:
- Claude Code —
~/.claude/projects/<encoded-folder>/*.jsonl. Each assistant message carries ausageblock andmodel. A single turn is split across many lines (one per content block) with the usage repeated, and resumed sessions copy earlier messages — so the extension deduplicates by API message id to count each response exactly once. - Codex —
~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl. Each session'stoken_countevents carry a cumulativetotal_token_usage; the extension reads the final (largest) one per session and filters by the recordedcwd.
Everything is local. The extension only reads files already on your machine and makes no network requests. It shows usage for the machine it runs on.