[FEATURE] Automatic Cost Tracking and Reporting

Status Closed — not planned
Maintainer reply None cached
Activity 12 comments · opened Jan 16, 2026 · closed Jun 16, 2026

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Currently, users have no visibility into the cost of their Claude Code operations without manually asking Claude to estimate costs or checking external billing dashboards. This makes it difficult to:

  • Understand the cost impact of different commands (e.g., /init, code generation, file operations)
  • Budget and manage AI usage within teams/organizations
  • Make informed decisions about when to use Claude Code vs. other tools
  • Track costs in real-time during development sessions

Proposed Solution

1. Per-Command Cost Display

After each command or significant operation, display estimated costs:

✓ /init completed successfully

Tokens used: 38,315 (30,000 input + 8,315 output)
Estimated cost: $0.21 (based on Claude 3.5 Sonnet pricing)

2. Session Summary

When exiting Claude Code or on-demand via a command like /costs, show:

=== Session Cost Summary ===
Duration: 45 minutes
Total tokens: 156,432 (120,000 input + 36,432 output)
Estimated cost: $0.91

Breakdown by operation:
  /init command:        $0.21 (38,315 tokens)
  Code generation:      $0.45 (85,120 tokens)
  File operations:      $0.15 (22,450 tokens)
  Conversation:         $0.10 (10,547 tokens)

3. Running Cost Counter

Display current session costs in the status bar or header:

Claude Code | Session: $0.45 | Tokens: 67.2K

Alternative Solutions

  1. External monitoring only - Requires users to check AWS/Anthropic dashboards separately (poor UX)
  2. Post-session analysis - Users can't make real-time decisions about usage
  3. Third-party wrappers - Adds complexity and maintenance burden

Priority

Medium - Would be very helpful

Feature Category

CLI commands and flags

Use Case Example

As a developer, I want to see the cost of each command so I can understand which operations are most expensive.

As a team lead, I want a session summary showing total costs so I can track and budget for Claude Code usage across my team.

As a finance manager, I want users to see cost warnings when sessions become expensive so we can control AI spending.

As an enterprise user, I want to configure custom pricing that matches my negotiated rates so cost estimates are accurate.

Additional Context

Token usage warnings are already displayed (e.g., "Token usage: 38315/200000"), which shows the infrastructure for tracking is in place. This feature would add cost calculation and better presentation of that existing data.

View original on GitHub ↗

11 Comments

github-actions[bot] · 7 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/12899
  2. https://github.com/anthropics/claude-code/issues/9617
  3. https://github.com/anthropics/claude-code/issues/17431

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

mpzarde · 6 months ago

Noticed that on Claude Code Cli v2.1.20 usage stats were provided on session exit with no extra configuration on my part, but now it's gone in v2.1.29.

Would be nice to have it back.

FlorianBruniaux · 6 months ago

@oktN @mpzarde
I built a SessionEnd hook that ~addresses this, displays session analytics automatically when you exit Claude Code, including cost estimation.

15 configurable sections: cost (via ccusage or built-in pricing table), model usage with cache hit rate, tool calls breakdown with error details, files touched, git diff summary, lines of code written, features used (MCP servers, agents, skills), duration/turns, conversation ratio.

!session-summary-v3

  • Uses the official hooks API, no modification of Claude Code internals
  • All sections toggleable via env vars or CLI config tool
  • JSONL logging for historical analysis (~/.claude/logs/session-summaries.jsonl)
  • Only requires jq

Source + docs: session-summary.sh | Documentation | Part of the Claude Code Ultimate Guide.

FlorianBruniaux · 6 months ago

Update: now installable as a plugin:

claude plugin marketplace add FlorianBruniaux/claude-code-plugins
claude plugin install session-summary@florian-claude-tools

Auto-wired hooks, zero config. Repo: FlorianBruniaux/claude-code-plugins

smarth-tech · 6 months ago

I ran into the exact same problem - the /cost command gives a snapshot of the current session, but there's no way to see cumulative costs across sessions, compare spend by model, or get alerts when a project is approaching a budget.
The use cases you described (team lead tracking budget, finance manager setting cost warnings) are spot-on. Those are the exact scenarios I kept hitting while managing multiple Claude Code projects.
I ended up building an open-source tool to solve this: [[ClaudeTrack]](https://github.com/smarth-tech/claudetrack). It's a self-hosted proxy that sits between your app and the Anthropic API — every request gets logged with full token counts, cost breakdowns (input/output/cache), and latency.
It gives you:

Per-session cost tracking — see exactly what each coding session costs
Per-project breakdowns — separate proxy keys per app/team/environment
Cost forecasting — daily and monthly spend projections with trend lines
Budget alerts — set limits per project, get notified before you overshoot
Rate limit prediction — reads the anthropic-ratelimit-* response headers and predicts 429s before they happen

Zero code changes needed - you just set ANTHROPIC_BASE_URL to point at ClaudeTrack. MIT licensed, free, self-hosted via Docker.
Still early and actively developing - would genuinely love feedback on what's missing, especially from the team lead / finance perspective you described. The multi-user cost attribution is an area I'm actively working on.

Sagargupta16 · 5 months ago

For anyone looking for cost optimization strategies beyond tracking, I put together an open-source resource that covers the "prevention" side of this problem:

claude-cost-optimizer — guides, benchmarks, and templates for reducing Claude Code costs by 30-60%.

Relevant to this thread:

All March 2026 pricing (Opus 4.6 $5/$25, Sonnet 4.6 $3/$15, Haiku 4.5 $1/$5). Complements the tracking tools shared above by @FlorianBruniaux and @smarth-tech with optimization strategies.

yurukusa · 5 months ago

You can build cost tracking with hooks:

INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name // "unknown"' 2>/dev/null)
TS=$(date -Iseconds)
COST_FILE="$HOME/.claude/session-costs.jsonl"
echo "{\"ts\":\"$TS\",\"tool\":\"$TOOL\"}" >> "$COST_FILE"
exit 0
COST_FILE="$HOME/.claude/session-costs.jsonl"
[ ! -f "$COST_FILE" ] && exit 0
TOTAL=$(wc -l < "$COST_FILE")
BASH_COUNT=$(grep -c '"Bash"' "$COST_FILE")
EDIT_COUNT=$(grep -c '"Edit"' "$COST_FILE")
READ_COUNT=$(grep -c '"Read"' "$COST_FILE")
REPORT="$HOME/.claude/cost-reports/$(date +%Y-%m-%d_%H%M%S).txt"
mkdir -p "$(dirname "$REPORT")"
cat > "$REPORT" << EOF
Session Cost Report — $(date)
Total tool calls: $TOTAL
  Bash: $BASH_COUNT
  Edit: $EDIT_COUNT
  Read: $READ_COUNT
EOF
rm -f "$COST_FILE"
echo "Cost report saved to $REPORT" >&2
exit 0
COST_FILE="$HOME/.claude/session-costs.jsonl"
CALLS=$(wc -l < "$COST_FILE" 2>/dev/null || echo 0)
echo "Calls: $CALLS"
{
  "hooks": {
    "PostToolUse": [{"hooks": [{"type": "command", "command": "bash ~/.claude/hooks/cost-tracker.sh"}]}],
    "Stop": [{"hooks": [{"type": "command", "command": "bash ~/.claude/hooks/cost-report.sh"}]}],
    "Notification": [{"matcher": "start", "hooks": [{"type": "command", "command": "rm -f ~/.claude/session-costs.jsonl"}]}]
  },
  "statusLine": {"command": "bash ~/.claude/hooks/cost-statusline.sh"}
}

This gives you per-session cost tracking (tool call counts by type), a report on exit, and a live statusline counter. For actual dollar costs, you'd need the API to expose token counts in the hook input — currently hooks don't receive billing data, but tool call frequency is a reasonable proxy.

Solomonic · 4 months ago

Built this. Tails the JSONL files Claude Code already writes to ~/.claude/projects/, prices every tool call, rolls up per project and per git branch. Also does the thing nobody else does: kills the session when you hit your cap.

Single binary, fully local, never phones home.

https://github.com/RoninForge/budgetclaw

FuturMix · 3 months ago

If you're using an API key (not a Max subscription), a practical workaround today is to route through an API gateway that handles cost tracking for you.

The setup:

export ANTHROPIC_BASE_URL="https://your-gateway-url"
export ANTHROPIC_API_KEY="your-gateway-key"

Any gateway that sits between Claude Code and the Anthropic API can log:

  • Per-request token counts (input/output)
  • Cost per session
  • Cumulative spend over time
  • Per-model breakdowns

Open source options like LiteLLM give you a self-hosted dashboard with usage analytics. Hosted options (OpenRouter, FuturMix, etc.) provide the same out of the box.

The key advantage is you get cost tracking across all your tools — Claude Code, Cursor, Aider, custom scripts — in one dashboard, rather than needing each tool to build its own cost tracking.

Not a replacement for native Claude Code cost tracking (which would be great), but it solves the immediate problem.

m13v · 3 months ago

token-cost-per-command and server-enforced quota are two different numbers, and conflating them is how people get surprised. local-log tools (ccusage, Claude-Code-Usage-Monitor) tally what the SDK reports. Anthropic enforces a rolling 5h window plus weekly quota server-side, and the SDK doesn't see that count. you can have a 'cheap' session in token terms that still slams into the wall mid-refactor because the meter the model respects lives on Anthropic's end. dollar display answers what a session cost. the question max devs actually need answered is how close am i to the wall right now.

github-actions[bot] · 2 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

Showing cached comments. Read the full discussion on GitHub ↗