Skip to content

Dhruvy0804/Token-Calculator-Claude-Code-Codex

Repository files navigation

Token Calculator: Claude Code & Codex

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.

Features

  • 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.

What "tokens" and "calls" mean

  • 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.

Install

From a .vsix file

  1. Download the latest claude-code-token-optimizer-*.vsix (from a release, or build it).
  2. In VS Code: Extensions panel → ... menu → Install from VSIX… and pick the file. (Or from a terminal: code --install-extension <path-to-vsix>.)
  3. Reload the window.

Build from source

npm install
npm run compile
npx @vscode/vsce package   # produces the .vsix

Or press F5 in VS Code to launch an Extension Development Host.

Usage

  1. Open a folder you've used with Claude Code or Codex.
  2. Look at the bottom-right status bar for the token total.
  3. 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: —.

Cross-checking the numbers

You don't have to trust the extension's internals. Two ways to verify:

  1. The tools' own counters — run /cost in Claude Code or /status in Codex and compare (use a fresh single-session folder for an apples-to-apples comparison).
  2. 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

Settings

Setting Description
claudeTokenOptimizer.projectsPath Override the path to ~/.claude/projects if your Claude Code logs live somewhere non-standard.

Commands

  • Token Usage Tracker: Refresh
  • Token Usage Tracker: Toggle Claude Code / Codex

How it works

Both tools record each session as JSONL logs:

  • Claude Code~/.claude/projects/<encoded-folder>/*.jsonl. Each assistant message carries a usage block and model. 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's token_count events carry a cumulative total_token_usage; the extension reads the final (largest) one per session and filters by the recorded cwd.

Privacy

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.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors