Monitoring Claude API usage and costs with a local CLI analyzer
Author
DW
Date Published

TL;DR
Managing LLM API costs requires granular usage data. The ccusage CLI tool addresses this by analyzing local Claude Code usage logs, providing detailed reports on tokens, models, and estimated costs across various timeframes. This allows developers to understand their spending patterns and optimize their LLM interactions.
Context
Developers building with large language models, particularly Claude, often face challenges in tracking their API usage and associated costs. Without clear visibility into token consumption per session, model choice, or billing periods, it becomes difficult to manage expenses and optimize application efficiency. The creator of ccusage built a solution to provide this missing transparency directly from local log files.
The approach
The ccusage tool operates as a command-line interface that processes local JSONL log files generated from Claude API interactions. It aggregates this data into various structured reports, including daily, weekly, and monthly summaries, as well as breakdowns by individual conversation sessions or Claude's specific 5-hour billing windows.
Why it worked
This direct, local analysis worked because it provided immediate, granular visibility into otherwise opaque API usage. By breaking down costs by model, tracking cache usage, and presenting data in human-readable tables or JSON, developers gained actionable insights. The ability to work offline with cached pricing data further ensured uninterrupted cost monitoring, making it a reliable resource for managing LLM development budgets.
Apply it yourself
Implement a similar local logging and analysis strategy for your LLM API usage, regardless of the provider. Even if a dedicated tool isn't available, capturing raw usage data and building simple scripts to aggregate and visualize it can provide invaluable insights for cost control and prompt engineering optimization.
Source
https://ccusage.com/ — ccusage