The debug module provides utilities for detecting and analyzing mismatches between pre-calculated costs (from Claude Code’s costUSD field) and costs calculated from token usage and model pricing.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ryoppippi/ccusage/llms.txt
Use this file to discover all available pages before exploring further.
Import
Functions
detectMismatches
Analyzes usage data to detect pricing mismatches between stored and calculated costs.Optional path to Claude data directory. If not provided, uses the default Claude data directory.
Statistics about pricing mismatches found in the usage data.
MismatchStats Type
Total number of usage entries analyzed
Number of entries that have both pre-calculated cost and model information
Number of entries where calculated cost matches stored cost (within threshold)
Number of entries where calculated cost differs from stored cost
Array of detailed discrepancy information for mismatched entries
Per-model statistics showing match/mismatch rates and average percentage differences
Per-version statistics showing match/mismatch rates across different Claude Code versions
printMismatchReport
Prints a formatted report of pricing mismatches to the console.The mismatch statistics returned from
detectMismatches()Number of sample discrepancies to display in the report
Usage Examples
Basic Mismatch Detection
Detect and print pricing mismatches from the default Claude data directory:Custom Path Analysis
Analyze usage data from a custom directory:Programmatic Analysis
Process mismatch data programmatically:Integration with CLI
The--debug flag in CLI commands uses this module internally:
Use Cases
Cost validation
Verify that calculated costs match Claude Code’s reported costs
Pricing analysis
Identify patterns in pricing discrepancies across models and versions
Data quality
Detect potential issues in usage data or pricing calculations
Model comparison
Compare pricing accuracy across different Claude models
Match Threshold
The module uses a configurable threshold to determine matches. By default, costs within 0.1% of each other are considered matches. This accounts for minor floating-point precision differences.Related Documentation
- Cost Calculation Modes - Understanding auto/calculate/display modes
- CLI Options - Using —debug flag in CLI commands
- Data Loader - Loading usage data for analysis