← Oscar Labs

method

from totals to projects

8 November 2026

TLDRA method for Claude Code and Codex logs, with two scripts you can copy and run on your own machine tonight.

Check it yourself

This follows where did the tokens go, which ends with a script that counts your totals. This is the next step: which project those tokens belong to.

TLDR. Claude Code and Codex already write a usage record for every reply, on your disk. You can turn those records into tokens per project, per type, per day in an evening. Three traps make most first attempts wrong: the same reply is logged more than once, Codex counts cached tokens inside input, and a folder is not a project. Whatever you can't place, call it unknown and show how big it is. That number is the honest part.

The fast route first

If a per-day or per-folder count is enough, use ccusage. It reads these same logs and groups Claude Code usage by project folder. Read on when folders aren't enough: one product across several repos, sessions that serve several projects, and an honest unknown.

1. Find the records

ToolWhereOne file is
Claude Code~/.claude/projects/<folder>/<session>.jsonl, plus <session>/subagents/agent-*.jsonlone session, or one subagent
Codex~/.codex/sessions/YYYY/MM/DD/*.jsonl and ~/.codex/archived_sessions/one session

Each line is one JSON event. Nothing here is your bill; these are the counts the tool logged.

Check this first. Claude Code deletes old session files after cleanupPeriodDays, which defaults to 30 days. If you want history, raise it in ~/.claude/settings.json today. Zero is rejected, so the docs suggest a large number such as 3650. What is already deleted is gone, and an empty month is not proof of zero use.

2. Know the four token types

TypeClaude Code fieldCodex fieldWhat it is
Fresh inputinput_tokensinput_tokens minus both cache fields belownew text sent to the model
Cache writecache_creation_input_tokenscache_write_input_tokens (inside input)context stored for reuse
Cache readcache_read_input_tokenscached_input_tokens (inside input)stored context sent again
Outputoutput_tokensoutput_tokens (already includes reasoning_output_tokens)what the model wrote

The two tools count differently, and this is the easiest way to double count. In Claude Code the four numbers are separate, so you add them. In Codex, the cached numbers are already inside input_tokens, and total_tokens is just input plus output. Add the cached number on top and you count it twice.

Cache reads usually dwarf everything else by volume, because the whole conversation is sent again every turn. They are also the cheapest per token at list price. Report volume and estimated cost separately. A chart of raw tokens will say re-reading is your biggest project, which is true by count and misleading by cost.

3. Count each reply once

Claude Code: deduplicate by reply. One API reply can appear on several lines, one per content block, each carrying the same usage. A reply is identified by its message.id plus the line's requestId (the id of the API request that produced it). Keep the first line per pair. In my own logs about half the usage lines were repeats.

Claude Code: include subagents. Subagent work is logged in its own files under <session>/subagents/ and is not repeated in the parent session. A glob of projects//.jsonl skips those files; use projects/**/*.jsonl.

Codex: take the last running total. total_token_usage in a token_count event only grows during a session. Keep the last one per session. Summing last_token_usage instead also works, but some events repeat, so it runs slightly high. A session can appear in both sessions and archived_sessions; count each session id once.

4. Attribute: folder, then repo, then project

Every Claude Code line carries cwd. Codex puts it in the session_meta line. That is your starting point, not your answer.

  1. Folder to repo. Walk up from cwd to the nearest .git. Sessions started in src/, web/ and the repo root are then one row. The scripts below do this.
  2. Repo to project. Several repos can be one product: a public mirror, a worktree, a fork. Keep a small hand-written map from repo to project.
  3. Home-folder sessions. A session started in ~ has no repo. Look at what it touched (file paths in tool calls, commits made in that time window) or leave it unknown.
  4. One session, many projects. A session that dispatches work to five repos belongs to five projects. Split it by turn, using the files each turn touched, or give it its own "coordination" row. Don't hand it all to the folder it started in.

5. Name the unknown, and shrink it honestly

Whatever is left goes in a row called unknown, shown at the top as a share of the total. Then work it down:

Stop when what's left is too small to change a decision. A precise-looking table with a hidden 30% unknown is worse than a rough one that says "unknown: 30%". When I first posted a breakdown like this, the one stranger who replied quoted exactly that line.

6. Price it, carefully (optional)

Multiply each token type by the provider's list rate for that model. Call the result an API-equivalent estimate. On a subscription it is not what you paid, and it says nothing about your plan's limits.

Script: Claude Code, steps 1 to 4.1

import json, glob, os, collections

TYPES = ["input_tokens", "cache_creation_input_tokens", "cache_read_input_tokens", "output_tokens"] seen, totals, roots = set(), collections.defaultdict(collections.Counter), {}

def project_of(cwd): """Walk up from the session folder to the nearest .git. No repo found: unknown.""" if not cwd: return "unknown" if cwd not in roots: d, found = cwd, None while d and d != os.path.dirname(d): if os.path.exists(os.path.join(d, ".git")): found = d break d = os.path.dirname(d) roots[cwd] = found or "unknown" return roots[cwd]

for project, c in sorted(totals.items(), key=lambda kv: -sum(kv[1].values())): print(f"{sum(c.values()):>15,} {project}") ```

Script: Codex, steps 1 to 4.1

import json, glob, os, collections

totals = collections.defaultdict(collections.Counter) patterns = ["~/.codex/sessions/**/*.jsonl", "~/.codex/archived_sessions/**/*.jsonl"] seen_sessions = set()

roots = {}

def project_of(cwd): """Walk up from the session folder to the nearest .git. No repo found: unknown.""" if not cwd: return "unknown" if cwd not in roots: d, found = cwd, None while d and d != os.path.dirname(d): if os.path.exists(os.path.join(d, ".git")): found = d break d = os.path.dirname(d) roots[cwd] = found or "unknown" return roots[cwd]

for pattern in patterns: for path in glob.glob(os.path.expanduser(pattern), recursive=True): session, cwd, last = None, "unknown", None for line in open(path, errors="ignore"): try: row = json.loads(line) except ValueError: continue p = row.get("payload") or {} if row.get("type") == "session_meta": session, cwd = p.get("id"), project_of(p.get("cwd")) elif p.get("type") == "token_count" and p.get("info"): last = p["info"]["total_token_usage"] # cumulative: keep the last one session = session or path # no session_meta line: treat the file as its own session if last is None or session in seen_sessions: continue seen_sessions.add(session) cached = last.get("cached_input_tokens") or 0 written = last.get("cache_write_input_tokens") or 0 # Codex counts cached tokens INSIDE input_tokens; total_tokens = input + output. totals[cwd]["fresh_input"] += (last.get("input_tokens") or 0) - cached - written totals[cwd]["cache_read"] += cached totals[cwd]["cache_write"] += written totals[cwd]["output"] += last.get("output_tokens") or 0 # includes reasoning

for folder, c in sorted(totals.items(), key=lambda kv: -sum(kv[1].values())): print(f"{sum(c.values()):>15,} {folder}") ```

Both print one row per repo, and unknown for sessions outside any repo. The Codex total per row should match the sum of Codex's own total_tokens for those sessions. If yours comes out higher, something is counted twice. Steps 4.2 to 5 are yours: they need your judgement about what your projects are.

Or use the tool

I packaged this as Local Token Inventory. It runs on your machine, asks before reading each source, does the dedupe and the repo walk, lets you move part of a session to another project, and keeps unknown as unknown. Demo with invented data, no install: https://morkeeth.github.io/where-did-the-tokens-go-public/