Feat/cost#2
Open
akshatshaw wants to merge 2 commits intoharshkedia177:mainfrom
Open
Conversation
Author
|
@harshkedia177 i have added support to get estimated cost for claude code usage, have a look and merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
--cost — Estimated cost breakdown by model
What :
Adds a new --cost flag that calculates and displays estimated API costs per model, broken down by input, output, cache read, and cache write tokens.
Pricing is local — no API calls. Prices are hardcoded from official public pricing pages with prefix/substring matching for versioned model names. Unknown models fall back to Sonnet-tier pricing.
enrichFromStatsCache()
— JSONL parsing gives proportional estimates, but
stats-cache.json
has authoritative per-model token breakdowns including cacheCreationInputTokens. We use that when available for accuracy.
Non-breaking — --cost is opt-in. Without it, output is identical to before.
tokenviz --claude --cost
💰 ESTIMATED COST
MODEL INPUT OUTPUT CACHE READ CACHE WRITE TOTAL
claude-opus-4-6 $0.37 $5.65 $33.9 $59.7 $99.5
claude-sonnet-4-6 $0.03 $1.58 $4.06 $5.48 $11.2
claude-haiku-4-5-20251001 $0.006 $0.18 $0.63 $0.83 $1.66
TOTAL $116
Works in both terminal and exported PNG/SVG.