How to Monitor Claude Code Usage & Costs (2026)
Track token consumption, spending, and usage patterns in Claude Code
Start Building with Hypereal
Access Kling, Flux, Sora, Veo & more through a single API. Free credits to start, scale to millions.
No credit card required • 100k+ developers • Enterprise ready
How to Monitor Claude Code Usage & Costs (2026)
Claude Code is Anthropic's agentic coding CLI that can edit files, run commands, search codebases, and perform complex multi-step development tasks. It is powerful but also token-intensive -- a single complex task can consume tens of thousands of tokens across multiple tool calls and reasoning steps.
Understanding your usage patterns and costs is essential for budgeting, especially if you are on the API plan or managing a team. This guide covers every method for monitoring Claude Code usage, from built-in commands to third-party dashboards.
Understanding Claude Code Billing
Claude Code has two billing models:
| Plan | How It Works | Cost |
|---|---|---|
| Max subscription | Included with Anthropic Max plan ($100/mo or $200/mo) | Fixed monthly fee with usage limits |
| API-based | Pay per token through your Anthropic API key | Variable based on usage |
If you are on the Max plan, you get a generous allocation of Claude Code usage included in your subscription. If you are using your own API key, every token counts toward your bill.
Token Costs for Claude Code (API Plan)
Claude Code primarily uses Claude 3.5 Sonnet and Claude 3.5 Haiku:
| Model | Input (per 1M) | Output (per 1M) | Typical Use in Claude Code |
|---|---|---|---|
| Claude 3.5 Sonnet | $3.00 | $15.00 | Main reasoning, code generation |
| Claude 3.5 Haiku | $0.80 | $4.00 | Quick tasks, file reading |
| Claude 3 Opus | $15.00 | $75.00 | Complex reasoning (if enabled) |
A typical Claude Code session involves:
- Reading file contents (input tokens)
- System prompt and tool definitions (input tokens, every turn)
- Model reasoning and responses (output tokens)
- Tool call results fed back (input tokens)
This means a multi-step task can easily consume 50K-200K tokens.
Method 1: Built-in Usage Display
Claude Code shows token usage information directly in the terminal. After each response, look for the usage summary at the bottom of the output:
> claude "refactor the auth module to use middleware pattern"
[Claude Code processes the task...]
───────────────────────────────────────
Cost: $0.24 | Tokens: 42,891 in / 3,204 out | Duration: 34s
Using the `/cost` Command
During an interactive session, use the /cost command to see cumulative usage:
claude
> /cost
Session usage:
Input tokens: 128,432
Output tokens: 12,891
Cache read: 89,204
Cache write: 31,002
Total cost: $0.72
Duration: 4m 23s
This shows your running total for the current session, including cached tokens (which are cheaper).
Check Usage at Session End
When you exit Claude Code or a session completes, it displays a final summary:
claude -p "add error handling to all API routes"
# After completion:
# Total tokens: 89,234 in / 8,921 out
# Estimated cost: $0.42
# Session duration: 1m 47s
Method 2: Anthropic Console Dashboard
The Anthropic Console provides detailed usage analytics for API-based usage:
- Go to console.anthropic.com
- Navigate to Usage in the left sidebar
- View your usage by:
- Time period (daily, weekly, monthly)
- Model (Sonnet, Haiku, Opus)
- API key
The dashboard shows:
| Metric | Description |
|---|---|
| Total tokens | Input + output tokens consumed |
| Total cost | Dollar amount spent |
| Requests | Number of API calls |
| Rate limit utilization | How close you are to rate limits |
| Usage by model | Breakdown per model |
Setting Up Usage Alerts
Configure spending alerts in the Anthropic Console:
- Go to Settings > Usage Limits
- Set a monthly spending limit (hard cap)
- Set a notification threshold (e.g., alert at 80% of budget)
- Add email addresses for notifications
Example configuration:
Monthly limit: $100
Alert at: $80 (80%)
Notification emails: dev@company.com, billing@company.com
Method 3: Environment Variable for Verbose Logging
Set the CLAUDE_CODE_VERBOSE environment variable to get detailed token logging:
# Add to your shell profile (.bashrc, .zshrc)
export ANTHROPIC_LOG=debug
# Or run with verbose output for a single session
ANTHROPIC_LOG=debug claude "explain this codebase"
This outputs detailed information about each API call, including exact token counts per request.
Method 4: Custom Usage Tracking Script
For teams that need detailed tracking, you can wrap Claude Code with a monitoring script:
#!/bin/bash
# claude-tracked.sh - Wrapper that logs Claude Code usage
LOG_FILE="$HOME/.claude-usage.log"
START_TIME=$(date +%s)
# Run Claude Code and capture output
claude "$@" 2>&1 | tee /tmp/claude-output.txt
END_TIME=$(date +%s)
DURATION=$((END_TIME - START_TIME))
# Extract cost from output (adjust regex as needed)
COST=$(grep -oP 'Cost: \$[\d.]+' /tmp/claude-output.txt | tail -1 | grep -oP '[\d.]+')
TOKENS=$(grep -oP 'Tokens: [\d,]+ in / [\d,]+ out' /tmp/claude-output.txt | tail -1)
# Log usage
echo "$(date -Iseconds) | Duration: ${DURATION}s | Cost: \$${COST:-unknown} | ${TOKENS:-unknown} | Command: $*" >> "$LOG_FILE"
# Clean up
rm -f /tmp/claude-output.txt
Make it executable and alias it:
chmod +x ~/claude-tracked.sh
alias claude-t='~/claude-tracked.sh'
Then review your usage log:
# View recent usage
tail -20 ~/.claude-usage.log
# Sum costs for the current month
grep "$(date +%Y-%m)" ~/.claude-usage.log | awk -F'Cost: \\$' '{sum+=$2} END {print "Monthly total: $"sum}'
Method 5: Use Claude Code's JSON Output for Programmatic Tracking
Claude Code supports JSON output mode, which makes it easy to parse usage data programmatically:
# Get structured output with usage info
claude -p --output-format json "list all TODO comments in this project" 2>/dev/null | jq '.usage'
Build a more sophisticated tracker in Python:
import subprocess
import json
import sqlite3
from datetime import datetime
def run_claude_tracked(prompt, project_dir="."):
"""Run Claude Code and track usage in a SQLite database."""
result = subprocess.run(
["claude", "-p", "--output-format", "json", prompt],
capture_output=True,
text=True,
cwd=project_dir
)
try:
output = json.loads(result.stdout)
usage = output.get("usage", {})
# Store in database
conn = sqlite3.connect("claude_usage.db")
conn.execute("""
CREATE TABLE IF NOT EXISTS usage (
id INTEGER PRIMARY KEY,
timestamp TEXT,
prompt TEXT,
input_tokens INTEGER,
output_tokens INTEGER,
cost_usd REAL,
model TEXT,
project TEXT
)
""")
conn.execute("""
INSERT INTO usage (timestamp, prompt, input_tokens, output_tokens, cost_usd, model, project)
VALUES (?, ?, ?, ?, ?, ?, ?)
""", (
datetime.now().isoformat(),
prompt[:200],
usage.get("input_tokens", 0),
usage.get("output_tokens", 0),
usage.get("cost_usd", 0),
usage.get("model", "unknown"),
project_dir
))
conn.commit()
conn.close()
return output.get("result", "")
except json.JSONDecodeError:
return result.stdout
# Usage
response = run_claude_tracked(
"add input validation to the user registration endpoint",
"/path/to/project"
)
Query your usage database:
-- Daily cost summary
SELECT date(timestamp) as day, SUM(cost_usd) as total_cost,
SUM(input_tokens) as total_input, SUM(output_tokens) as total_output
FROM usage
GROUP BY date(timestamp)
ORDER BY day DESC;
-- Cost by project
SELECT project, SUM(cost_usd) as total_cost, COUNT(*) as requests
FROM usage
GROUP BY project
ORDER BY total_cost DESC;
-- Most expensive single requests
SELECT timestamp, prompt, cost_usd, input_tokens, output_tokens
FROM usage
ORDER BY cost_usd DESC
LIMIT 10;
Method 6: Monitor Max Plan Usage
If you are on the Anthropic Max plan, your Claude Code usage is part of your subscription allowance. To monitor it:
- Visit claude.ai/settings
- Check your usage under the subscription section
- Look for the Claude Code usage meter
Max plan limits reset monthly. Keep an eye on:
| Max Plan | Monthly Price | Claude Code Allowance |
|---|---|---|
| Max (standard) | $100/mo | High usage limit |
| Max (scaled) | $200/mo | Very high usage limit |
When you approach your limit, Claude Code may throttle to smaller models or reduce response length. Monitor your usage mid-month to avoid hitting the wall during critical development periods.
Cost Optimization Tips
| Strategy | Savings | How |
|---|---|---|
Use -p (print mode) for one-shots |
10-30% | Avoids loading interactive session overhead |
| Be specific in prompts | 20-40% | Reduces back-and-forth and retries |
Use --max-turns flag |
Up to 50% | Limits runaway agentic loops |
| Scope to specific files | 15-25% | Use @file references instead of letting Claude search |
| Use Haiku for simple tasks | 70-80% | claude --model haiku "simple question" |
| Cache-friendly conversations | 20-30% | Resume sessions instead of starting new ones |
# Limit turns to prevent runaway costs
claude --max-turns 5 "add tests for the payment module"
# Use Haiku for quick questions
claude --model haiku "what does the handleAuth function do?"
# Resume previous session to benefit from cached context
claude --resume
Team Usage Monitoring
For teams, set up per-developer API keys and monitor individually:
# Create per-developer keys in the Anthropic Console
# Then set in each developer's environment:
export ANTHROPIC_API_KEY=sk-ant-developer-specific-key
# View usage per key in the Anthropic Console > API Keys > Usage
Consider setting per-key spending limits:
| Developer | Monthly Limit | Alert Threshold |
|---|---|---|
| Senior engineers | $200 | $160 |
| Junior engineers | $100 | $80 |
| QA/Testing | $50 | $40 |
| CI/CD automation | $300 | $240 |
Wrapping Up
Monitoring Claude Code usage is straightforward once you know where to look. The built-in /cost command and session summaries handle casual monitoring. For serious tracking, combine the Anthropic Console dashboard with spending alerts and a custom logging solution. The key is setting up monitoring before costs become a surprise, not after.
If you are building AI-powered applications and want to monitor costs across multiple AI services -- including media generation for images, video, and avatars -- try Hypereal AI free -- 35 credits, no credit card required. Our dashboard provides transparent per-request cost tracking so you always know what you are spending.
Related Articles
Start Building Today
Get 35 free credits on signup. No credit card required. Generate your first image in under 5 minutes.
