A CloudCLI tab plugin for tracking and calculating Claude Code API token costs in real time. Monitors active sessions, aggregates project-level and all-time spending, and fetches live model pricing from the LiteLLM pricing registry.
Based on cloudcli-plugin-token-cost-calculator by NightmareAway / kologram — MIT License. Significant enhancements added; see What's New.
-
Clone this repo into your CloudCLI plugins directory:
git clone https://github.com/strykereye2/cloudcli-token-cost-pro.git \ ~/.claude-code-ui/plugins/token-cost-pro -
Install dev dependencies and build:
cd ~/.claude-code-ui/plugins/token-cost-pro npm install npm run build
-
Restart CloudCLI — the Token Cost Pro tab appears automatically.
Session transcripts (~/.claude/projects/)
Claude Code writes every session as a JSONL file:
~/.claude/projects/<encoded-project-path>/<session-uuid>.jsonl
The path encoding mirrors Claude Code's own convention — each / in the project path is replaced with -. For example, /workspace/my-project becomes -workspace-my-project.
Each line in the JSONL is a JSON object. The plugin reads message.usage fields from assistant turns:
input_tokens— tokens sent to the modeloutput_tokens— tokens generated by the modelcache_creation_input_tokens— tokens written to the prompt cachecache_read_input_tokens— tokens read back from the prompt cachemessage.model— the model ID used for that turn
Sub-agent sessions (spawned by Claude Code's Task tool) are found under <sessionDir>/subagents/*.jsonl and are included in all totals.
LiteLLM pricing registry
Live pricing is fetched from:
https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json
This JSON file contains per-token pricing for 2,700+ models. The plugin filters to mode: "chat" entries only, refreshes every 6 hours, and falls back to hardcoded presets on timeout or network failure.
Model lookup uses exact match first, then strips trailing date suffixes (e.g. claude-haiku-4-5-20251001 → claude-haiku-4-5) for a second attempt.
The plugin provides five modes, selectable via the button bar at the top.
Enter token counts by hand for quick estimates or hypothetical scenarios. Quick-add buttons let you add +1K, +10K, +100K, +1M, or +10M tokens at a time. All inputs persist to localStorage between page loads.
Monitors the currently active Claude Code session in real time. Reads the session JSONL directly, refreshes every 30 seconds, and shows a countdown timer. Automatically detects the model from the session transcript and populates prices from LiteLLM.
If no session context is available from the CloudCLI sidebar, a fallback input appears for manual project path and session ID entry.
Aggregates all sessions under a single project folder. Enter the project path (e.g. /workspace/my-project) and the plugin scans ~/.claude/projects/<encoded-path>/ for all .jsonl files. Sessions are sorted by total token count descending and listed with per-session cost breakdowns.
Scans every subdirectory under ~/.claude/projects/ and aggregates totals across all projects since Claude Code was installed. Each project row shows token counts, session count, and a proportional usage bar. Projects are sorted by total token usage.
Slices session data by calendar date. Use the ◀ / ▶ navigation buttons or the Today shortcut to browse by day. Each day row expands to show per-session details. Useful for tracking daily spend against a budget.
Shared across all modes. Shows three price fields (per 1M tokens):
| Field | What it covers |
|---|---|
| Input | Tokens sent to the model |
| Output | Tokens generated by the model |
| Cache input | Prompt cache read + write (averaged) |
Auto-price: In Auto-detect, Project, and Daily modes, the plugin detects the model from session data and fills prices automatically from LiteLLM. A status indicator shows LiteLLM live (green), Preset fallback (amber), or LiteLLM unavailable (amber) depending on the pricing source.
Override: Click the override button to lock the price fields and edit them manually. Click auto to revert to auto-detected prices.
Preset dropdown: Eight built-in presets for quick selection:
- Claude Opus 4.7, Sonnet 4.6, Haiku 4.5
- GPT-4o, GPT-4o-mini
- Gemini 2.5 Pro, Gemini 2.5 Flash
- DeepSeek V4 Pro
The plugin runs a local Node.js HTTP server. All endpoints are called internally via the CloudCLI plugin RPC bridge.
| Method | Path | Description |
|---|---|---|
GET |
/presets |
Returns the 8 hardcoded model presets |
GET |
/session-usage |
Token counts for a single session (?projectPath=&sessionId=) |
POST |
/calculate |
Server-side cost calculation verification |
GET |
/project-usage |
All sessions in one project (?projectPath=) |
GET |
/all-usage |
All sessions across all projects |
GET |
/daily-usage |
All sessions grouped by calendar date |
GET |
/model-price |
Live LiteLLM price lookup (?model=) |
GET |
/pricing-status |
LiteLLM fetch status (ready/loading/error) |
POST |
/refresh-prices |
Force re-fetch LiteLLM pricing data |
Changes made in this fork relative to the original plugin:
The original plugin used only hardcoded preset prices. This fork adds a full live pricing system:
- Fetches the LiteLLM model pricing JSON on startup and every 6 hours
- 8-second fetch timeout with graceful fallback to presets
/model-price,/pricing-status, and/refresh-pricesAPI endpoints added to the server- Status indicator in the UI shows source (live / preset / unavailable)
In Auto-detect, Project, and Daily modes, the plugin now reads the model name from the session JSONL and automatically populates the pricing fields — no manual preset selection needed.
Added override and auto buttons so users can lock prices manually and revert to auto-detected values without losing their customization.
The original encodeProjectPath function only handled Windows-style backslash separators. On Linux/macOS, project paths like /workspace/my-project were not encoded correctly, causing "Project directory not found" errors. Fixed by adding forward-slash replacement.
Removed the Google Fonts CDN dependency (JetBrains Mono external load). Replaced with a system monospace font stack (SFMono-Regular, Cascadia Code, Consolas, Liberation Mono) — no external requests, faster load, works fully offline.
Added PricingStatus and LivePriceResult interfaces for the new pricing system.
Original plugin by NightmareAway (GitHub: kologram). Repository: cloudcli-plugin-token-cost-calculator License: MIT
This fork extends the original with live pricing, automatic model detection, and Linux compatibility fixes.
MIT — see original license terms. Modifications are contributed under the same MIT License.