github ryoppippi/ccusage v0.4.0

latest releases: v16.2.3, v16.2.2, v16.2.1...
3 months ago

🚀 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-calculated costUSD when available, otherwise calculates from token counts
  • calculate: Always calculates costs from token counts using LiteLLM pricing data
  • display: Only shows pre-calculated costUSD 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

   🚀 Features

   🐞 Bug Fixes

    View changes on GitHub

Don't miss a new ccusage release

NewReleases is sending notifications on new releases.