- Category
- Developer Tools
- Rank
- No. 2090Tools index
Previous survey · No. 2067 ·
- Pricing
- Open Source
- Type
- TOOL
- Builder
- badlogic
- GitHub
- 26 stars
- Date
About
Instruments Claude Code to track actual token usage and cost.
What it does
Cccost wraps a Claude Code session and forwards its command-line arguments unchanged. While the session runs, it observes Anthropic message responses, totals input, output, and cache tokens by model, calculates cost, and maintains session statistics in JSON. It also prints a summary when the process exits.
Why it's ranked here
The case for choosing Cccost is strong when transcript-derived totals are incomplete. It captures both JSON and streaming responses, preserves usage across resumed sessions, and produces machine-readable data for status displays. Its narrow model-price matching and quiet error handling keep the verdict mixed rather than unconditional.
What's good
The wrapper preserves the normal Claude Code command line, so adoption requires little workflow change. Statistics distinguish input, output, cache creation, and cache reads for each model. Existing session data loads before new requests accumulate, supporting resumed work. Response cloning keeps accounting from consuming the response Claude Code needs.
Tradeoffs
Cost calculation recognizes models through broad opus, sonnet, and haiku name matching. Unknown model families receive zero cost, while future variants may inherit prices that no longer apply. Parsing and file-write failures are often suppressed, so missing statistics can be difficult to diagnose without verbose output. The approach also depends on Claude Code using Node fetch for message requests.
How to use it well
Use Cccost when you run Claude Code locally and want per-session usage data for a custom status line or later inspection. It fits developers comfortable installing a global Node command and routing every session through a wrapper. It does not provide a hosted dashboard, budget enforcement, team reporting, or general API accounting.
Technical notes+
package.json defines a Node 20-or-newer global CLI package with no runtime dependencies. src/cli.ts locates the Claude Code executable, removes the tool-specific verbose flag, then starts Node with src/interceptor-loader.js preloaded. That loader initializes src/interceptor.ts, which replaces global.fetch, filters Anthropic message requests, clones responses, parses JSON or server-sent events, accumulates per-model totals, and writes session JSON beside Claude Code transcripts. Pricing is selected by model-name substrings, and unknown models return zero cost. src/types.ts separately exports MODEL_PRICING, but src/interceptor.ts uses its own pricing table. statusline.js demonstrates consuming the generated data for context percentage and total cost.
Observed
- License
- MIT
- Primary language
- TypeScript, with JavaScript loader and example scripts
- Installation
- Global npm package @mariozechner/cccost
- Interface
- Command-line wrapper named cccost
- Runtime
- Node.js 20 or newer
- Package dependencies
- No runtime dependencies declared; development dependencies include TypeScript, tsx, Biome, and Husky
Read from README.md, package.json, src/cli.ts, src/types.ts, src/interceptor.ts, src/interceptor-loader.js, statusline.js, biome.json, tsconfig.json, .husky/pre-commit.
What it can do
Track token usage for Claude API calls
Claude API requests and responses → Token consumption metrics
Calculate cost of Claude API usage
Token usage data and pricing information → Cost breakdown and totals
Instrument existing Claude code
Claude code implementation → Instrumented code with tracking capabilities
Monitor real-time API costs
Live Claude API interactions → Real-time cost tracking data
Generate usage reports
Collected token and cost data → Usage and cost reports
Tags
Tech Stack
Comments (0)
No comments yet
Editorially curated, with community endorsements as a secondary signal. Corrections welcome.
