Skip to content

Tracking Costs

Claude Code uses tokens, and tokens cost money. Here’s how to track and optimize your usage.

Tokens are the units Claude uses to process text:

  • ~4 characters = 1 token (English)
  • ~100 tokens = 75 words
  • A typical code file = 500-2000 tokens

Cost factors:

  • Input tokens (what you send to Claude)
  • Output tokens (what Claude generates)
  • Context (accumulated conversation history)

The best way to track costs is ccusage:

  1. Install ccusage

    Terminal window
    npx ccusage

    Or install globally:

    Terminal window
    npm install -g ccusage
  2. View your usage

    Terminal window
    npx ccusage

    This shows:

    • Total tokens used today
    • Estimated cost
    • Breakdown by session
  3. Check specific time periods

    Terminal window
    npx ccusage --days 7 # Last 7 days
    npx ccusage --month # This month
╭─────────────────────────────────────────────────────╮
│ Claude Code Usage Report │
├─────────────────────────────────────────────────────┤
│ Period: Today (Jan 5, 2026) │
│ │
│ Sessions: 12 │
│ Input tokens: 145,230 │
│ Output tokens: 42,891 │
│ Total tokens: 188,121 │
│ │
│ Estimated cost: $2.34 │
╰─────────────────────────────────────────────────────╯

Different activities use different amounts of tokens:

ActivityTypical Token Usage
Simple question500-1,000
Explain a file2,000-5,000
Bug fix5,000-15,000
Feature implementation20,000-50,000
Full project scan50,000-200,000

Don’t continue conversations forever. Start new sessions for new tasks:

Terminal window
# New task? New session.
claude "new task: add user authentication"

When context grows large, compress it:

> /compact

This summarizes the conversation, preserving important context while reducing tokens.

Vague prompts require more back-and-forth:

Expensive:

> fix the bug
> no, the other bug
> in the auth module
> the one about passwords

Cheaper:

> fix the password validation bug in auth.py line 45
ModelCostUse For
Haiku$Quick questions, simple tasks
Sonnet$$Daily coding, most tasks
Opus$$$$Complex architecture, hard problems

Switch models based on task complexity:

> /model haiku
> what's the syntax for a Python list comprehension?
> /model sonnet
> refactor this authentication system

Instead of:

> explain all the code in this project

Try:

> explain the main entry point in app.py
Terminal window
# Interactive mode loads context
claude
> quick question
# Print mode is lighter
claude --print "quick question"

Track spending with a simple script:

#!/usr/bin/env python3
"""Check Claude Code spending and alert if over budget."""
import subprocess
import json
DAILY_BUDGET = 10.00 # dollars
def check_usage():
result = subprocess.run(
["npx", "ccusage", "--json"],
capture_output=True,
text=True
)
data = json.loads(result.stdout)
cost = data.get("estimated_cost", 0)
if cost > DAILY_BUDGET:
print(f"⚠️ Over budget! ${cost:.2f} / ${DAILY_BUDGET:.2f}")
else:
print(f"✓ ${cost:.2f} / ${DAILY_BUDGET:.2f}")
if __name__ == "__main__":
check_usage()

Claude has a maximum context window. When you hit it:

  1. Oldest messages get dropped
  2. You lose important context
  3. Claude may forget earlier instructions

Signs you’re hitting limits:

  • Claude forgets what you discussed earlier
  • Responses become less coherent
  • You see warnings about context length

Solution: Use /compact proactively or start a new session.