TokenAtlas
Formerly claude-code-energy-monitor.
TokenAtlas is a local, private token and cost atlas for AI coding agents (Claude Code, Codex, OpenCode, Pi): a durable history CLI (tokenatlas), an offline HTML report, list-price costing, session trees and fixed-context overhead.
What TokenAtlas adds beyond the vendors' own tools
- One local, private view across Claude Code, Codex, OpenCode and Pi, and across machines (snapshots merge into one history). Nothing leaves the machine and no model is called.
- The costliest turns, each with its context: an initiating input plus everything it caused, including follow-up inputs and subagent work.
- A list-price dollar valuation of usage, including subscription usage, so that very different plans and harnesses can be compared in one unit (API-equivalent, not what was paid).
- Long history: observations are kept in a local database after the harnesses rotate or delete their logs.
Use the vendor tools for:
- Plan limits and resets (Claude Code
/usage, Codex /usage).
- Actual billing and invoices.
- Organization admin dashboards.
Quick start
TokenAtlas is one command. It only reads the logs the agents already write, so there is nothing to set up in
Claude Code, Codex, OpenCode or Pi: no skills, AGENTS.md, plugins, hooks or MCP servers.
pipx install tokenatlas # or: uv tool install tokenatlas
tokenatlas open # read the logs, build the private report, open it in the browser
tokenatlas show # open the latest report at once (no refresh, no rebuild)
tokenatlas open saves the report as report.html next to the history, by default
~/.local/state/tokenatlas/report.html (a folder Finder hides; it prints the path, and the private report's footer
shows it). Run tokenatlas open again to reopen it, or add --html ~/Desktop/tokenatlas.html to keep it somewhere
visible.
Python 3.10 or newer is needed. macOS ships Python 3.9; uv tool install tokenatlas (or a one-off
uvx tokenatlas open) downloads a suitable Python by itself, so nothing else has to be installed.
Installing only adds the command: nothing runs in the background. Every tokenatlas open stores what the logs hold
at that moment, which is enough to look now and then. For a history that outlasts the agents' own log cleanup (Claude Code deletes transcripts after 30 days by
default, its cleanupPeriodDays setting), run tokenatlas collect on a schedule; see
Keeping the report fresh. Only what was stored before a log was deleted survives.
What is read, from each harness's default location (or where its own variable moved it, see
Durable local usage history):
| Harness |
Logs |
| Claude Code |
~/.claude/projects |
| Claude desktop Cowork (macOS) |
~/Library/Application Support/Claude/local-agent-mode-sessions/…/.claude/projects |
| Codex |
~/.codex/sessions and ~/.codex/archived_sessions (plain and compressed rollout-*.jsonl[.zst]; compressed files need pip install 'tokenatlas[zstd]', pipx inject tokenatlas zstandard or the zstd binary) |
| OpenCode |
~/.local/share/opencode/opencode.db |
| Pi |
~/.pi/agent/sessions |
Off until you opt in:
- the text and context of the costliest turns:
tokenatlas top --keep-text (see Top turns);
- other machines:
tokenatlas collect --remote tag:host, which needs ssh access and TokenAtlas on that machine
(see Other machines).
Coding agents and automation
See the agent CLI guide for task-to-command recipes, stable JSON
fields and exit codes. Reporting commands accept --json, including doctor.
For headless use, open --no-browser / show --print-path return only the path;
TOKENATLAS_NO_BROWSER=1 disables browser launch for both. Add --json for a
versioned path receipt. The synthetic usability eval includes
a ten-task fixture and a separate small-model evaluation protocol.
Durable local usage history
tokenatlas imports Claude, Codex, Pi, and OpenCode observations into a local SQLite
history. It needs Python 3.10+ and the standard library, makes no network or LLM
calls, and does not change your installed statusline (the statusline command records Claude quota readings locally by default and you can turn that off with --no-record-quota, see below).
# Default store: ~/.local/state/tokenatlas/history.sqlite3 (or XDG_STATE_HOME)
tokenatlas refresh --harness claude
tokenatlas refresh --harness codex
tokenatlas refresh --harness pi
tokenatlas refresh --harness opencode
tokenatlas refresh --all # every harness from its default roots (Claude incl. Cowork)
tokenatlas doctor
# Stored history, local time buckets; timestamps must include an offset
tokenatlas report --start 2026-09-01T00:00:00+02:00 --end 2026-10-01T00:00:00+02:00 --granularity hour
tokenatlas report --granularity minute --session SESSION_ID --records
# Isolated input/state, useful for a demonstration or fixture
tokenatlas --db /private/tmp/tokenatlas-demo/history.sqlite3 refresh --harness claude --root /path/to/transcripts
All commands print JSON. refresh imports only changed files; running it twice
or importing a copied transcript does not add the same usage again. Recorded
history survives source deletion. Schedule refresh separately if desired;
there is no background service, and already-deleted logs cannot be recovered.
refresh exits 3 when every requested source root is absent and 1 for other source problems or partial imports, and records diagnostics.
Logs are read from each harness's default location unless the harness itself has been moved with its own
variable, which TokenAtlas reads at every run (an unset, empty or relative value means the default):
| Harness |
Variable |
Read from |
Default |
| Claude Code |
CLAUDE_CONFIG_DIR |
$CLAUDE_CONFIG_DIR/projects |
~/.claude/projects |
| Codex |
CODEX_HOME |
$CODEX_HOME/sessions, $CODEX_HOME/archived_sessions and session_index.jsonl |
~/.codex/sessions |
| Pi |
PI_CODING_AGENT_DIR (leading ~ expanded) |
$PI_CODING_AGENT_DIR/sessions |
~/.pi/agent/sessions |
| OpenCode |
XDG_DATA_HOME |
$XDG_DATA_HOME/opencode/opencode.db |
~/.local/share/opencode/opencode.db |
An explicit command-line root (--root, --claude-root, ...) beats the variable, which beats the default.
The Claude desktop Cowork location is not affected by CLAUDE_CONFIG_DIR. tokenatlas doctor lists the
resolved path and its source (default or the variable name) per harness under roots. A scheduled job
(cron, launchd) does not inherit your interactive shell's environment: set the variable in the schedule
itself, for example CODEX_HOME=/data/codex tokenatlas refresh --all in the crontab line, or under
EnvironmentVariables in the launchd plist.
report supports day/hour/minute, --timezone, --harness, --project (full
identity), --session (including displayed HARNESS:SESSION_ID names), and --turn. --records includes source-file references
and observed/derived turn links. The output is private local data: project
paths are visible, although prompt content and tool inputs are never stored.
Missing counters remain null; known_tokens is only the identified observed subtotal.
Ambiguous identities are excluded and reported separately because they may overlap.
A complete normalized observation does not mean complete account coverage or
verified billing. Nontrivial Claude iterations are retained and flagged rather
than silently ignored or added twice. Claude subagent transcripts often lack the final
usage row of a request, so their output can be a lower bound (warning output_not_final). See accounting and storage decisions.
Keeping the report fresh
A report is a snapshot. To keep one current without manual steps, refresh on a schedule and rebuild the
report only when the data changed and the file is old enough. The history keeps a revision counter
(shown by doctor) that grows whenever a refresh or import stores something new. The report records a
state fingerprint in a <meta name="tokenatlas-state"> tag; it covers the data revision, the report options
(privacy, timezone, granularity, filters) and the coverage, so changing any of them rebuilds the report.
# Every harness from its default roots; a harness that is not installed here is reported as "absent"
tokenatlas refresh --all
# Rebuild only if data changed (--if-changed) and the report is older than 1h (--max-age: 90s, 30m, 1h, 2d)
tokenatlas report --html ~/.local/state/tokenatlas/report.html --private --if-changed --max-age 1h
refresh --all prints one JSON document with a status (ok, partial or missing, the worst of the
present harnesses) and one entry per harness. It exits 0 when every present harness is ok and 2
otherwise; absent harnesses never fail it, so a machine without Claude Code still exits 0. A skipped
report prints {"html": ..., "skipped": true, "reason": "unchanged"|"too recent"}, exits 0 and does not
touch the file. Without --if-changed and --max-age, report --html always rebuilds. A refresh that
finds nothing new leaves the revision alone; a re-import of identical rows with known sources does too.
tokenatlas open reuses a background report built with
report --html $XDG_STATE_HOME/tokenatlas/report.html --private when nothing changed, and only opens it.
The report is available in Swedish and English. --lang auto|sv|en (on report and open, default auto) picks the language: auto uses the saved view language, if set, then the browser (sv gives Swedish, anything else English). The SV/EN toggle in the report header switches live and remembers the choice in the browser when storage is available; an explicit --lang wins over a remembered choice. --lang is part of the report identity, so changing it rebuilds a conditional report.
Choosing what the report shows
Save your usual report layout and opening filters with tokenatlas view. This changes
HTML built by report, open, and scheduled collect; it does not change collection,
delete data, or filter command-line analytics. Existing HTML stays as it was until rebuilt
(show opens the existing file without rebuilding).
tokenatlas view # current layout and available section ids
tokenatlas view --json # versioned, machine-readable configuration
tokenatlas view set --sections glance,turns,limits,quota-windows,facts
tokenatlas view hide energy sessions
tokenatlas view show energy # append to the current order, without duplicates
tokenatlas view default --period 30d --harness codex --plan team
tokenatlas view default --plan '' # clear one saved default
tokenatlas view set --top 20 --lang sv --money-first
tokenatlas view preset subscription # also api-cost, minimal, full
tokenatlas view export > my-view.json
tokenatlas view import my-view.json
tokenatlas view reset # everything, original order, no saved defaults
set --sections replaces the selection in the given order. Use --sections ''
for no sections. hide preserves the remaining order; show appends in argument order.
Presets replace the entire view, including filters and display options: subscription
puts subscriptions, limit hits and quota windows first; api-cost puts the answer panel, cost facts and turns first;
minimal shows glance, KPIs and turns; full restores all sections in the original order.
--top controls the costliest-turn count (1–10000, default 10). --money-first moves
cost to the first turn column; --no-money-first restores the original column order.
Stable section ids, in the default order:
| Id |
Report content |
answer |
Answer panel (total, tools, projects, costliest turns) |
glance |
At a glance |
glossary |
Terms (initially collapsed) |
kpis |
Token KPIs |
analytics |
Request analytics |
efficiency |
Token efficiency |
turns |
Costliest turns |
limits |
Limit hits and quota calibration |
quota-windows |
Quota windows |
subscriptions |
Subscriptions view |
facts |
Cost facts |
cache-spend |
Cache spend: full re-caches by cause, resume tax, TTL what-if |
plan-facts |
Plan facts |
usage |
Clients and local inference |
work |
Work context |
energy |
Energy estimate |
environment |
Environmental estimate |
charts |
Timeline and ranking |
cache |
Cache comparisons |
sessions |
Sessions |
coverage |
Data coverage |
The original layout nests efficiency inside analytics and quota windows inside limits.
Custom layouts can select and order either child independently, even without its parent.
Empty, data-dependent sections may still be absent when there is nothing to show.
The page header, filters, diagnostic notices, footer and separate Subscriptions view
remain available regardless of the section selection.