🚀 Major Changes
Multiple Cost Calculation Modes
In response to issue #4 regarding cost calculation discrepancies and missing costUSD
fields in newer Claude Code versions, this release introduces flexible cost calculation modes:
auto
(default): Intelligently uses pre-calculatedcostUSD
when available, otherwise calculates from token countscalculate
: Always calculates costs from token counts using LiteLLM pricing datadisplay
: Only shows pre-calculatedcostUSD
values, displays 0 for missing costs
# Examples
npx ccusage@latest --mode auto # Smart mode - best of both worlds
npx ccusage@latest --mode calculate # Force calculation from tokens
npx ccusage@latest --mode display # Only show stored costs
Internal Debug Functionality
Added internal debug module for cost verification (not exposed as CLI command):
- Compares pre-calculated vs token-calculated costs
- Reports mismatches exceeding 10% threshold
- Helps developers verify cost accuracy across different Claude Code versions
- This is an experimental feature used for development and testing
npx ccusage@latest --debug
🎯 Key Features
Cost Calculation Improvements
- Integration with LiteLLM's pricing database for accurate model costs
- Better handling of missing cost data
Technical Enhancements
- Type-safe enum validation for mode arguments
- Improved error handling and edge case coverage
- Enhanced test coverage with real Claude 4 models
- Better separation of concerns in cost calculation logic
📝 Documentation Updates
- Added comprehensive tips to CLAUDE.md
- Documented all cost calculation modes
- Added important disclaimers about virtual cost calculations
💡 Background
This release addresses the community's need for flexible cost tracking as Claude Code evolves. With some versions not including pre-calculated costs, users can now choose how they want costs to be determined - whether from stored values, calculated from tokens, or a smart combination of both.
As a result of the verification, we found that the costUSD
was sometimes half the price of the API price. So we think the apparent cost will be even more inflated with this change.
In any case, it is not possible to measure costs accurately. Just look at it as a reference.
⚠️ Important Notes
- Cost calculations are based on LiteLLM's pricing data and may not reflect actual billing
- The
calculate
mode provides estimates based on token counts and model pricing - For official billing information, always refer to your Claude account dashboard
🙏 Acknowledgments
Special thanks to all contributors who shared their logs and helped identify the cost calculation discrepancies in issue #4 ( @nnamon @itsUndefined @mimikun )
🚨 Breaking Changes
- Introducing debug command - by @ryoppippi (2b8c5)
🚀 Features
- Implement pricing-fetcher - fetch from litellm's data - by @ryoppippi (599b5)
- Collect versions per session - by @ryoppippi (75f40)
- Add CostMode type - by @ryoppippi (77916)
- Cost mode option to args - by @ryoppippi (a6858)
- Implement cost mode options to command - by @ryoppippi (089d4)
- Extract duplicated process of calculate cost - by @ryoppippi (47cb8)
- data-loader: Add loader forr fetching model - by @ryoppippi (4af0b)
🐞 Bug Fixes
- Argument type of debug should be enum - by @ryoppippi (78fbd)
- Stop fetching pricing when display mode - by @ryoppippi (4f8fd)
- debug.ts: Do not use magic number - by @ryoppippi and Copilot (0b26a)
- log: Add types to log function - by @ryoppippi (4ed8b)