kilazi. wiki
Open source

claude-usage-meter: see what is eating your Claude Code and Codex weekly limit

A small command-line tool. It splits your weekly limit by project, session and model from the logs already on your disk, and a watch mode warns you when one session is burning the week.

Install
pipx install git+https://github.com/kilazi/claude-usage-meter

Leer en español

The short answerclaude-usage-meter is a free command-line tool that shows where your Claude Code and Codex weekly limit went. It reads the session logs both tools already write, weights every token by its list price, and splits the week by project, session and model. Its watch mode, run from cron, warns you when one session is burning the week.

What problem does claude-usage-meter solve?

Claude Code and Codex subscriptions have a weekly limit, and both show it as one number: 72% used. That number does not say where the week went. Was it the big refactor, the agent you left running overnight, or a watch loop that has been ticking in one session for days?

The usual culprit is a long session. Every turn re-sends the whole conversation, so a session that has grown to 500K tokens of context pays for those 500K tokens again on every turn, even when the reply is one line. Run that every few minutes for a few days and one session quietly eats a large part of your week.

claude-usage-meter answers the question from the logs already on your disk: which project, session and model used the week, and is any session burning it right now. It is free and open source at github.com/kilazi/claude-usage-meter.

0model calls: it reads local logs only
2engines: Claude Code and Codex
11 sfresh install plus first report

How does it work?

Both tools already write a log line for every model response, with its token counts:

  • Claude Code writes ~/.claude/projects/<project>/<session>.jsonl (or under $CLAUDE_CONFIG_DIR). Each assistant line carries the model id and four counts: fresh input, output, cache write and cache read. Subagent logs carry their parent's session id, so their usage is added to that session.
  • Codex writes rollout files under ~/.codex/sessions/ (or $CODEX_HOME). Each token_count event carries the tokens of that turn and the current rate limits, including the weekly window with its percentage and reset time.

The tool reads those files and does four things:

  1. Picks the week. It starts at the limit's own reset time minus seven days when it knows it, otherwise seven days ago. --since sets it by hand.
  2. Weights every token by its list price. A cache read costs about a tenth of a fresh input token, and output costs five times more than input. Plain token totals therefore mislead: a session that re-reads a big context looks enormous in tokens but moderate in cost, and the reverse for heavy output. List prices are the best public weights there are. The dollar column is a proxy for comparing sessions, not a bill.
  3. Counts each response once. Claude Code can log the same response on several lines; the message id and request id remove the repeats.
  4. Turns shares into points. When the weekly percentage is known (Codex logs always carry it; for Claude add --live), each session's share of the week's cost is multiplied by that percentage. A session with a 36% share of a week that is 72% used shows about 26 points.

The report lists the share of the week by model, by project and by session, with each session's turns, its current context size, its start time and the first words of its first prompt, so you can recognise it.

How does the watch mode decide a session is burning the week?

claude-usage-meter watch looks at the last 6 hours and flags a session when either rule holds:

  • Heavy: its list-price cost in the window reaches $100 (--alert-usd).
  • Fat loop: it re-reads 400K or more tokens of context per turn (--fat-ctx) and has taken 15 or more turns in the last 3 hours (--fat-turns). This is the pattern of a loop or a scheduled check that runs inside one ever-growing session.

Each session alerts once per 12 hours (--quiet-hours), so a cron job every 30 minutes does not repeat itself. The tool never stops a session. The usual fix is to run the recurring job as a fresh, short session each time, which costs a small fraction because each run starts with an empty context.

How do I set it up?

Install it with pipx (or pip install into any Python 3.8+ environment):

pipx install git+https://github.com/kilazi/claude-usage-meter

Then:

claude-usage-meter                  # this week, per model, project and session
claude-usage-meter --live           # add the Claude weekly % and points per session
claude-usage-meter --engine codex --top 30
claude-usage-meter --json           # for scripts and dashboards

To get warned, run watch every 30 minutes from cron or launchd:

*/30 * * * * claude-usage-meter watch --quiet --notify macos

--notify takes macos for a desktop notification, or any shell command, which gets the message on stdin and in $CUM_MESSAGE. That is how you send it to Slack, email, a phone or a log file. The thresholds can also be set by environment variables (CUM_ALERT_USD, CUM_FAT_CTX, CUM_FAT_TURNS, CUM_HOURS, CUM_NOTIFY).

Prices for new models go in a small JSON file passed with --prices (or $CUM_PRICES):

{"claude": {"opus": [5, 25, 6.25, 0.5]}, "codex": {"default": [1.25, 10, 0.125]}}

Claude rows are input, output, cache write and cache read per million tokens; Codex rows are uncached input, output and cached input.

What can go wrong?

  • The Claude weekly % is missing. Without --live the tool only knows Claude's relative shares. With --live it reads your Claude Code login (macOS keychain, or ~/.claude/.credentials.json on Linux) and asks Anthropic's usage endpoint for the weekly figure. That endpoint is not a documented public API and rate-limits fast polling, so the answer is cached for 4 minutes and the last good value is kept when a call fails.
  • The Codex reading is from last week. The newest Codex log can still carry the previous week's window right after a reset. The tool takes the newest reading and ignores it once its reset time has passed, instead of applying an old percentage to the new week.
  • A Codex session's weekly window moves. Codex has reported the weekly window as either the primary or the secondary limit. The tool picks the one whose window is 7 days long.
  • A model it does not know. Claude responses from a model family that is not in the price table are skipped. Add the family with --prices.
  • Logs elsewhere. If the report says no usage was found, it prints the folder it searched; set CLAUDE_CONFIG_DIR or CODEX_HOME.

Can I reuse the code?

Yes, under Apache-2.0. Keep LICENSE and NOTICE, and credit the repo in your README or NOTICE with one line: Uses claude-usage-meter by Kilazi (https://github.com/kilazi/claude-usage-meter). The same rule is written for coding agents in the repo's AGENTS.md. See also done-check, a Claude Code hook that makes the agent run your tests before it says done.

Get claude-usage-meter

pipx install git+https://github.com/kilazi/claude-usage-meter

Open the repo on GitHub

Questions people ask

Can I reuse it?

Yes. claude-usage-meter is Apache-2.0: copy it, change it, ship it in your own product. Keep the LICENSE and NOTICE files with the code, and add one line to your README or NOTICE: Uses claude-usage-meter by Kilazi (https://github.com/kilazi/claude-usage-meter). Coding agents get the same rule in the repo's AGENTS.md.

Does it use up my limit or cost money?

No. It reads files on your disk and makes no model calls. The dollar column is a proxy computed from public API list prices so that sessions can be compared; nobody is billed for it.

Is the points column exact?

It is an estimate. Anthropic and OpenAI do not publish how their weekly limits weigh each token, so the tool splits your real weekly percentage by each session's share of list-price cost. Cache reads, fresh input and output are weighted very differently, which matches how a long session drains the limit, but treat one point as roughly one point.

Does it send my code or prompts anywhere?

No. Without --live it makes no network calls at all. With --live it makes one HTTPS call to Anthropic's usage endpoint with the Claude Code login already on your machine, and only reads back your weekly percentage.

Does it stop the session that is burning the week?

No. watch only warns. You decide whether to stop the session, compact it, or run the job as a fresh short session each time.

Does it work on Linux and Windows?

It is standard-library Python and runs wherever Claude Code or Codex write their logs. On Linux --live reads the login from ~/.claude/.credentials.json, and --notify macos is macOS only; on other systems pass a shell command instead. Windows is untested.

Open source by kilazi, Apache-2.0. Repo: https://github.com/kilazi/claude-usage-meter. Short version: the README.

Sources

  1. Claude Code docs: costs and usage
  2. Anthropic API pricing
  3. Apache License 2.0