Skip to main content

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

πŸ’° $49.00 ($16.55/h)  πŸ“Š 14638846 tok (279900 tpm)
The display includes:
  • πŸ’° 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:
{
  "cost": {
    "total_cost_usd": 49.00,
    "total_duration_ms": 10677000
  },
  "context_window": {
    "total_input_tokens": 12500000,
    "total_output_tokens": 2138846
  }
}

Implementation

From features/usage.ts:36-88:

Burn Rate Calculation

Why multiply by 3600000?The formula converts cost per millisecond to cost per hour:
cost_per_hour = (total_cost_usd / total_duration_ms) Γ— 3600000
Breaking it down:
  1. total_cost_usd / total_duration_ms = cost per millisecond
  2. Multiply by 1000 = cost per second
  3. Multiply by 60 = cost per minute
  4. Multiply by 60 = cost per hour
  5. Total multiplier: 1000 Γ— 60 Γ— 60 = 3,600,000
Example:
  • 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

From features/usage.ts:50-82:
# Token data from native context_window (no ccusage needed)
input_tokens=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0' 2>/dev/null)
output_tokens=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0' 2>/dev/null)

if [ "$input_tokens" != "null" ] && [ "$output_tokens" != "null" ]; then
  tot_tokens=$(( input_tokens + output_tokens ))
  [ "$tot_tokens" -eq 0 ] && tot_tokens=""
fi

# Calculate tokens per minute from native data
if [ -n "$tot_tokens" ] && [ -n "$total_duration_ms" ] && [ "$total_duration_ms" -gt 0 ]; then
  # Convert ms to minutes and calculate rate
  tpm=$(echo "$tot_tokens $total_duration_ms" | awk '{if ($2 > 0) printf "%.0f", $1 * 60000 / $2; else print ""}')
fi
Token data comes from Claude Code’s native context_window objectβ€”no ccusage required for token stats!

Token Burn Rate Formula

tokens_per_minute = (total_tokens / total_duration_ms) Γ— 60000
Where:
  • total_tokens = input_tokens + output_tokens
  • total_duration_ms = session duration in milliseconds
  • 60000 = conversion factor (60,000 ms = 1 minute)

Display Implementation

From features/usage.ts:154-196:
export function generateUsageDisplayCode(config: UsageFeature, colors: boolean, emojis: boolean): string {
  const costEmoji = emojis ? 'πŸ’΅' : '$'
  const tokenEmoji = emojis ? 'πŸ“Š' : 'tok:'
  
  // Cost display
  if [ -n "$cost_usd" ] && [[ "$cost_usd" =~ ^[0-9.]+$ ]]; then
    if [ -n "$cost_per_hour" ] && [[ "$cost_per_hour" =~ ^[0-9.]+$ ]]; then
      printf '  ${costEmoji} %s$%.2f ($%.2f/h)%s' "$(cost_color)" "$cost_usd" "$cost_per_hour" "$(rst)"
    else
      printf '  ${costEmoji} %s$%.2f%s' "$(cost_color)" "$cost_usd" "$(rst)"
    fi
  fi
  
  // Token display
  if [ -n "$tot_tokens" ] && [[ "$tot_tokens" =~ ^[0-9]+$ ]]; then
    if [ -n "$tpm" ] && [[ "$tpm" =~ ^[0-9.]+$ ]]; then
      printf '  ${tokenEmoji} %s%s tok (%.0f tpm)%s' "$(usage_color)" "$tot_tokens" "$tpm" "$(rst)"
    else
      printf '  ${tokenEmoji} %s%s tok%s' "$(usage_color)" "$tot_tokens" "$(rst)"
    fi
  fi
}

Color Scheme

From features/usage.ts:14-30:
# ---- usage colors ----
usage_color() { if [ "$use_color" -eq 1 ]; then printf '\033[38;5;189m'; fi; }  # lavender
cost_color() { if [ "$use_color" -eq 1 ]; then printf '\033[38;5;222m'; fi; }   # light gold
burn_color() { if [ "$use_color" -eq 1 ]; then printf '\033[38;5;220m'; fi; }   # bright gold
ElementColorANSI CodePurpose
Token countLavender38;5;189General usage info
Total costLight gold38;5;222Dollar amounts
Burn rateBright gold38;5;220Highlighted rates

Configuration

From cli/prompts.ts:28-30:
{ name: 'πŸ’΅ Usage & Cost', value: 'usage', checked: true },
{ name: 'πŸ“Š Token Statistics', value: 'tokens', checked: true },
{ name: '⚑ Burn Rate ($/hr & tokens/min)', value: 'burnrate', checked: true }
All cost and usage features are enabled by default.

Example Outputs

# All metrics enabled
πŸ’° $49.00 ($16.55/h)  πŸ“Š 14638846 tok (279900 tpm)
Shows:
  • 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

FeatureRequirementFallback
Cost displayjq recommendedBash regex fallback available
Burn ratejq + awkLimited without jq
Token statsjq recommendedBash regex fallback available
Token burn ratejq + awkNot 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

Possible causes:
  • No cost data available yet (fresh conversation)
  • JSON extraction failed
  • jq not installed
Solutions:
  1. Continue conversation to generate some usage
  2. Install jq: brew install jq (macOS) or apt-get install jq (Linux)
  3. Enable logging to debug JSON extraction
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.
Debug steps:
  1. Enable debug logging during init
  2. Check .claude/statusline.log for raw JSON
  3. Verify context_window.total_input_tokens and total_output_tokens values
  4. Formula: total = input + output tokens
Note: Token counts are cumulative for the entire conversation.
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
This is expectedβ€”it reflects your actual usage pattern over time.

Next Steps

Session Timer

Track time until usage reset

Customization

Customize display format and colors

Build docs developers (and LLMs) love