Overview
Cost monitoring displays your current API costs with hourly burn rate calculations, helping you understand spending patterns and optimize usage.Requires jq for full functionality. Basic cost display works without jq, but burn rate calculations require it.
What You See
- π° Current total cost in USD
- π΅ Burn rate (cost per hour)
- π Total tokens consumed
- β‘ Token burn rate (tokens per minute)
Cost Tracking
Data Source
Cost data comes from Claude Codeβs native cost tracking:Implementation
Fromfeatures/usage.ts:36-88:
- With jq (Recommended)
- Bash Fallback
- Formula:
(total_cost / total_duration_ms) Γ 3600000 - Converts milliseconds to hours (3600000 ms = 1 hour)
- Results in dollars per hour
Burn Rate Calculation
Understanding burn rate formula
Understanding burn rate formula
Why multiply by 3600000?The formula converts cost per millisecond to cost per hour:Breaking it down:
total_cost_usd / total_duration_ms= cost per millisecond- Multiply by 1000 = cost per second
- Multiply by 60 = cost per minute
- Multiply by 60 = cost per hour
- Total multiplier: 1000 Γ 60 Γ 60 = 3,600,000
- Total cost: $49.00
- Duration: 10,677,000 ms (β 2.97 hours)
- Calculation:
(49.00 / 10677000) Γ 3600000 = 16.52 - Result: $16.52/hour
Token Analytics
Token tracking shows your total token consumption and burn rate.Token Data Extraction
Fromfeatures/usage.ts:50-82:
Token data comes from Claude Codeβs native
context_window objectβno ccusage required for token stats!Token Burn Rate Formula
total_tokens= input_tokens + output_tokenstotal_duration_ms= session duration in milliseconds60000= conversion factor (60,000 ms = 1 minute)
Display Implementation
Fromfeatures/usage.ts:154-196:
Color Scheme
Fromfeatures/usage.ts:14-30:
| Element | Color | ANSI Code | Purpose |
|---|---|---|---|
| Token count | Lavender | 38;5;189 | General usage info |
| Total cost | Light gold | 38;5;222 | Dollar amounts |
| Burn rate | Bright gold | 38;5;220 | Highlighted rates |
Configuration
Fromcli/prompts.ts:28-30:
Example Outputs
- Full Display
- Cost Only
- Tokens Only
- No Burn Rates
- Total cost: $49.00
- Hourly burn rate: $16.55/h
- Total tokens: 14,638,846
- Token burn rate: 279,900 tokens/minute
Understanding Your Costs
Low Burn Rate
< $5/hourTypical for:
- Code review sessions
- Documentation work
- Light development
Medium Burn Rate
$5-20/hourCommon for:
- Active development
- Large refactorings
- Complex debugging
High Burn Rate
$20-50/hourHappens during:
- Heavy code generation
- Large file processing
- Extensive context usage
Very High Burn Rate
> $50/hourConsider:
- Starting fresh conversation
- Reducing context size
- Breaking into smaller tasks
Requirements
| Feature | Requirement | Fallback |
|---|---|---|
| Cost display | jq recommended | Bash regex fallback available |
| Burn rate | jq + awk | Limited without jq |
| Token stats | jq recommended | Bash regex fallback available |
| Token burn rate | jq + awk | Not available without jq |
Performance
- Execution time: ~10-15ms with jq
- Data source: Native Claude Code JSON (no external API calls)
- Calculations: Simple arithmetic via awk
- Overhead: Minimal
Troubleshooting
Cost not showing
Cost not showing
Possible causes:
- No cost data available yet (fresh conversation)
- JSON extraction failed
- jq not installed
- Continue conversation to generate some usage
- Install jq:
brew install jq(macOS) orapt-get install jq(Linux) - Enable logging to debug JSON extraction
Burn rate showing as $0.00/h
Burn rate showing as $0.00/h
Cause: Duration is zero or very smallNormal behavior: Early in a conversation, duration may be too small for meaningful burn rate calculation. The rate will stabilize after a few minutes of usage.
Token count seems wrong
Token count seems wrong
Debug steps:
- Enable debug logging during init
- Check
.claude/statusline.logfor raw JSON - Verify
context_window.total_input_tokensandtotal_output_tokensvalues - Formula: total = input + output tokens
Burn rate fluctuates wildly
Burn rate fluctuates wildly
Normal behavior: Burn rate is calculated as average over total duration:
- Early in conversation: Rate may seem high
- During pauses: Rate decreases
- During heavy usage: Rate increases
Next Steps
Session Timer
Track time until usage reset
Customization
Customize display format and colors