[FEATURE] Automatic Cost Tracking and Reporting
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
- External monitoring only - Requires users to check AWS/Anthropic dashboards separately (poor UX)
- Post-session analysis - Users can't make real-time decisions about usage
- 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.
Showing cached comments. Read the full discussion on GitHub ↗
11 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
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.
@oktN @mpzarde
I built a
SessionEnd hookthat ~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
~/.claude/logs/session-summaries.jsonl)jqSource + docs: session-summary.sh | Documentation | Part of the Claude Code Ultimate Guide.
Update: now installable as a plugin:
Auto-wired hooks, zero config. Repo: FlorianBruniaux/claude-code-plugins
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.
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.
You can build cost tracking with hooks:
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.
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
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:
Any gateway that sits between Claude Code and the Anthropic API can log:
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.
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.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.