showmytokens.

How to check your Claude Code token usage

Three ways to see how many tokens Claude Code has used: its built-in commands, the session logs on your computer, and a shareable receipt.

3 min read · updated 2026-10-02

If you use Claude Code every day, you have probably wondered how many tokens it actually uses. Tokens are what plans meter and what API usage is billed on, so it is worth knowing. There are three practical ways to find out.

1. Use the built-in commands

Claude Code has commands for this inside a session. /cost shows usage for the current session, which is most useful if you pay per API token, and /stats shows usage statistics over time. What each one shows depends on your plan and your Claude Code version, so run /help to see what your install offers.

The limits of the built-in view: it is about now, not about your history, and there is nothing to share.

2. Read the logs on your computer

Claude Code keeps a log of every session as JSON Lines files under ~/.claude/projects/ (or under the folder set by CLAUDE_CONFIG_DIR). Each reply from the model carries a usage block with four numbers:

One catch: Claude Code writes the same reply to the file more than once while it streams, so summing every line double counts. Count each message once, using its message id and request id. This small script does that and prints your totals (Node 18 or newer):

// sum-claude-tokens.mjs
import { readdirSync, readFileSync } from "node:fs";
import { homedir } from "node:os";
import { join } from "node:path";

const root = join(homedir(), ".claude", "projects");
const walk = (dir) =>
  readdirSync(dir, { withFileTypes: true }).flatMap((e) =>
    e.isDirectory() ? walk(join(dir, e.name)) : e.name.endsWith(".jsonl") ? [join(dir, e.name)] : [],
  );

const seen = new Set();
const t = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 };

for (const file of walk(root)) {
  for (const line of readFileSync(file, "utf8").split("\n")) {
    if (!line.startsWith("{")) continue;
    let e;
    try { e = JSON.parse(line); } catch { continue; }
    const u = e.type === "assistant" && e.message?.usage;
    if (!u || e.isApiErrorMessage || e.message.model === "<synthetic>") continue;
    const key = `${e.message.id}:${e.requestId}`;
    if (e.message.id && seen.has(key)) continue;
    seen.add(key);
    t.input += u.input_tokens || 0;
    t.output += u.output_tokens || 0;
    t.cacheRead += u.cache_read_input_tokens || 0;
    t.cacheWrite += u.cache_creation_input_tokens || 0;
  }
}

const total = Object.values(t).reduce((a, b) => a + b, 0);
console.log(t, "\ntotal:", total.toLocaleString("en-US"));

Run it with node sum-claude-tokens.mjs. Do not be surprised by the size of the cache numbers: they are normally far bigger than input and output. The guide to input, output and cache tokens explains why.

Also keep in mind that Claude Code deletes old session files after 30 days by default, so the logs only reach back that far unless you change the setting. See where Claude Code stores your usage data.

3. Get a receipt that keeps your history

If you want a running total, per-day charts, streaks and something you can post, showmytokens does the counting for you. It reads the same local logs, uploads only per-day counts (never prompts, replies, code or file names), and keeps your history on the server, so it survives the 30-day cleanup.

npx showmytokens login

You can preview exactly what would be sent first with npx showmytokens sync --dry-run.

Which one should you use?