close

DEV Community

yarden ashkenazi
yarden ashkenazi

Posted on Fully Autonomous

How to see exactly how many tokens you've used in Claude Code and Codex

If you use Claude Code or Codex every day, you've probably wondered how many tokens you actually burn. The good news: both tools keep a full local record. You just have to know where to look.

Here are four ways to get the number, from quickest to most thorough.

1. Inside Claude Code: /usage and /cost

  • /usage shows where you are against your plan's session and weekly limits.
  • /cost shows the token count and dollar cost of the current session (most useful on API billing).

Both are handy for "am I about to hit a limit?", but they don't give you a lifetime or monthly total.

2. Read the logs yourself

Claude Code writes every session to JSONL files:

~/.claude/projects/<project-folder>/<session-id>.jsonl
Enter fullscreen mode Exit fullscreen mode

Every assistant message in those files has a message.usage block like this one (from my own logs):

{
  "input_tokens": 2,
  "cache_creation_input_tokens": 44143,
  "cache_read_input_tokens": 53461,
  "output_tokens": 546
}
Enter fullscreen mode Exit fullscreen mode

Codex does the same under ~/.codex/sessions/YYYY/MM/DD/.

This Python script adds up all your Claude Code usage. It skips duplicate message ids, because the same response can show up more than once when a session is resumed:

import json, glob, os
from collections import defaultdict

seen, totals = set(), defaultdict(int)
for path in glob.glob(os.path.expanduser("~/.claude/projects/*/*.jsonl")):
    for line in open(path, errors="ignore"):
        try:
            d = json.loads(line)
        except ValueError:
            continue
        msg = d.get("message") or {}
        u = msg.get("usage")
        if not u or msg.get("id") in seen:
            continue
        seen.add(msg.get("id"))
        for k in ("input_tokens", "output_tokens",
                  "cache_creation_input_tokens", "cache_read_input_tokens"):
            totals[k] += u.get(k) or 0

for k, v in totals.items():
    print(f"{k:32} {v:>15,}")
print(f"{'total':32} {sum(totals.values()):>15,}")
Enter fullscreen mode Exit fullscreen mode

On my machine it printed:

input_tokens                              25,376
output_tokens                          9,143,849
cache_creation_input_tokens           43,069,223
cache_read_input_tokens            2,491,380,206
total                              2,543,618,654
Enter fullscreen mode Exit fullscreen mode

The thing that surprised me most: cache reads are about 98% of the total. Output tokens are under 1%. When someone posts "I used 2 billion tokens", most of that is Claude re-reading the same context from cache. That's normal, and it's why the subscription is such good value.

3. ccusage for daily and monthly reports

ccusage is a great open-source CLI that reads the same files and gives you daily, monthly and per-session tables with cost estimates:

npx ccusage@latest daily
Enter fullscreen mode Exit fullscreen mode

It's the reason you see so many #ccusage screenshots on X.

4. Make it verifiable: TokenTrust

Screenshots have one problem: anyone can edit a number. I built TokenTrust to fix that. It's like TrustMRR, but for AI developers.

It reads the same local logs, checks every response by its provider id (duplicates, ids already claimed by someone else, impossible throughput), and puts the verified total on a public profile and leaderboard. Only the model, timestamps, token counts and hashed ids leave your machine. Never prompts, code or file paths.

curl -fsSL https://www.tokentrustt.dev/connect | sh
Enter fullscreen mode Exit fullscreen mode

Link your X or GitHub and people can find you by how much you actually ship with AI.


What does your breakdown look like? I'm curious whether anyone's cache-read share is much lower than 98%.

Top comments (1)

Collapse
 
jacksonxly profile image
Jackson Ly •

That glob skips subagents. On my machine Claude Code writes their transcripts to <project>/<session-id>/subagents/agent-*.jsonl, and */*.jsonl doesn't go that deep. In files modified since Nov 3, subagents were 4% of all tokens but 12% of output tokens. My cache-read share is 98% too, subagents included.