Local-first token, cost and tool analytics for AI coding agents (OpenCode, Codex CLI, Claude Code).
Local-first usage analytics for AI coding harnesses. toknt reads the native telemetry of OpenCode, OpenAI Codex CLI, Claude Code, Cline, pi, Grok Build, Gemini CLI and more (21 harnesses, see Source support) from your machine, normalizes it into a canonical model, keeps a local SQLite index, and renders token, cost and tool-call analytics in the terminal:
Everything stays on disk. toknt never uploads telemetry, never authenticates to providers, and makes no network requests at any point.
uv tool install toknt # isolated install from PyPI pipx install toknt # or pipx pip install toknt # or into a virtualenv brew install bitpeppr/formulae/toknt # macOS (Homebrew) Then:
toknt doctor # what toknt found on this machine toknt scan # import local history (incremental) toknt # interactive: usage explorer, boot view = contributions toknt -h # all commands accept the short help flag From a checkout, uv sync and prefix commands with uv run (e.g. uv run toknt doctor).
Running bare toknt in a terminal enters the explorer instead of printing a static dashboard. Every view opens with a bold heading and a hairline rule, so the content reads as one page. The page fills the terminal up to 192 columns and centers itself beyond that, so the margins on the left and the right always match — and a big monitor gets more content rather than stretched rows.
It starts on the contributions view: every day of the chosen window laid out like GitHub's contribution graph, colored by total tokens, with weekday labels and month labels centered over their own month (never colliding, even on dense windows). The calendar stays tight and sits directly against its weekday labels — week columns are two cells wide with a single space between them, never stretched across the page. On wide terminals the page splits in two: the left holds the calendar and the days it inspects (picked day under the cursor with its per-harness amounts, then the peak day), while the right rail carries the window total with its daily average, the share-by-project list, the share-by-harness list (both with inline bars) and a quiet note about toggled-off harnesses. On a wide screen the rail splits into two columns — projects beside harnesses — and project paths show their tail (…/Project/kbd), which is what tells two projects apart. The bars that carry a series colour paint it on the used portion only; the unfilled track is plain space, which respects terminals with a transparent background (halftone shade characters puddle into noise there) and reads as less ink everywhere. Narrow terminals fold back to a single column, and the legend there names the harnesses that carry data as colored swatches, keeps toggled-off ones visible (codex (off)) and collapses the idle ones into a single +N idle tail. A compact tab bar (view chips, window/metric/harness state) marks the active view in its series color; the bottom bar pairs each key with a dim action label.
Every launch rescans the sources, so the numbers on screen are the numbers as of now, not as of the last time you opened the app. The rescan runs in its own process: a source that has not changed is skipped in milliseconds, and the interface stays interactive while a busy one is read.
The 3h, 5h and 1d windows are the live views: the tokens-by-model chart switches to hour buckets with clock-time tick labels (19:00 20:00 …), and the app rescans every source in the background every ~30 seconds (quickly on entry, then steadily), sliding the window forward with each completed scan — token counts, the donut and the cache-rate bars move on their own while you watch. The ‣ scanning… chip shows when a refresh is in flight; the UI stays interactive throughout.
The explorer opens on the 3-day window and the t key walks the cycle backwards — 3d → 1d → 5h → 3h → all → 1y → 90d → 30d → 7d — so the shorter, more recent windows are one keystroke away and everything else is one keystroke further.
Windows up to a week (3h, 5h, 1d, 3d, 7d) are charted by the hour, so the day-scale windows still show the working rhythm instead of a handful of flat daily totals; from 30d on, the charts switch to day buckets. The contribution grid always draws calendar days, so a short window shows the days it covers inside the current week.
The models view renders a chart of the current metric split by the top 8 models beside a right rail that holds a donut of the models' token share (on image backends; a colored share ribbon elsewhere), the model's legend chips, and cache hit-rate bars that mirror the per-model table (one bar per visible row, in the table's order; scheme-aware: cache reads are a separate denominator for anthropic-style sources, a subset for openai-style ones, and absent entirely for unknown schemes, shown as —). Below, the per-model breakdown table fills the zone width and ends with a vs max bar showing each model's size relative to the busiest one, and — when the table zone can afford it (about 110 columns or wider) — a tok/s column with each model's mean generation rate. The selected metric drives all of it — the chart, the donut's shares, the table's numbers and the ranking — so switching to input re-ranks the table by input tokens and reports input tokens in every column. Pressing p trades the chart's unit: instead of tokens per bucket it draws the derived tok/s rate per bucket, keeping the same models in the same order (only the lines move, never the colours). Token charts use a logarithmic y-axis — a 5M-token model stays legible next to a 250M one instead of collapsing into the baseline — while the tok/s chart stays linear, because a rate is a ratio, not a magnitude. Piping or scripting (non-tty stdout) gets the old static print; toknt overview forces that dashboard, and TOKNT_TUI=0 disables the interactive boot entirely.
The harnesses record when each assistant message finished, never how long it took, so a rate cannot be read off a single event. toknt instead pairs every message with its predecessor in the same session and derives
tok/s = Σ (generated tokens) / Σ (gap to the previous message) Generated tokens follow the source's own reporting scheme, because the categories mean different things: an Anthropic-style source reports reasoning beside output, so both count; an OpenAI-style source reports reasoning inside output, so counting it again would inflate the rate by tens of percent on reasoning-heavy models. Prompt handling (input and cache) is never part of what a rate measures. The pairing excludes a session's first message, gaps longer than five minutes (a person's lunch is not model slowness), and messages that report no generated tokens, so those events hand their predecessor's gap to whoever follows. Events without session attribution have no conversation to pair within and drop out of every rate. In the weighting, a slow message biases its day more than a fast burst, which matches what the wall clock actually spent. Accuracy depends on the work: tool-free bursts land closest to a model's true output speed, while turns dominated by long tool runs bias the rate down, because the wall clock between messages includes the tools. toknt has no way to measure a true duration, so treat the comparisons between models and the trends over time as the signal — never a single number as gospel. In interactive mode the estimate lives behind p on the models view (chart) and the table's tok/s column; on the command line it is toknt models --tps.
The same model is recorded under different names depending on who served it: z-ai/glm-5.3-flash (vendor prefix), cline-free/muse-spark-1.3-contributor (harness prefix), glm-5.3-flash-free (provider's free tier), thinkingmachines/inkling:free (routing tag), llama-3-70b-q4_k_m (quantization). Pressing m merges those spellings into one row, one chart series and one cache-rate bar — muse-spark-1.3 from Cline and from OpenCode become one model, and z-ai/glm-5.3-flash and glm-5.3-flash-free become one. The same merge is available on the command line with toknt usage --merge-models (also toknt models --merge-models and toknt overview --merge-models).
The merge is deliberately narrow, because merging the wrong models would quietly distort every number:
So glm-5.3 and glm-5.3-flash stay apart, muse-spark-1.3 and muse-spark-1.2 stay apart, and nemotron-3-ultra does not swallow nemotron-3-ultra-550b-a55b. Merged rows are summarized as a whole, so totals, event counts, sessions and reported cost stay consistent.
When the terminal understands an image protocol, the models chart and the token-share donut are rendered as anti-aliased bitmaps — soft-edged strokes, transparent background, gridlines — and placed inline (kitty: kitty/ghostty/WezTerm/Warp/rio, iTerm2: OSC 1337, sixel: xterm/foot). Identical charts are re-rendered from a small cache, so navigating never re-encodes the bitmap; when an image's slot disappears (view switch, smaller window) it is erased with the terminal's own background color, so no ghost graphs live behind the text. The help overlay is plain text and deliberately leaves the chart bitmap on screen. Everything else degrades to sharp Braille-dot charts, so the same data views work in a plain screen.
Check what your terminal reports — and whether it actually draws images:
toknt doctor # the "Graphics" row names the backend and the reason toknt graphics # draws a test chart; force a transport with --backend toknt graphics --alt # same image inside the alternate screen (like the TUI) toknt graphics prints the detected transport (kitty / iterm2 / sixel / off) with the reason, then emits a real chart. If no image appears, your terminal does not implement the detected protocol — force another one with TOKNT_GRAPHICS=kitty|sixel|iterm2 or [presentation] graphics = "…". Inside the TUI the same test is one keypress away: g draws the identical test image.
Terminals without image support (Apple Terminal, Alacritty, most tmux setups) use the Braille charts; toknt refuses to send images inside a multiplexer, where they would be swallowed silently.
[presentation] graphics = "auto" # auto | kitty | iterm2 | sixel | off TOKNT_GRAPHICS overrides the same setting per invocation (off restores character-cell charts everywhere). Non-tty output never emits images.
A harness is the CLI/IDE program that talks to the model (the word "agent" now commonly means plan/build modes, so toknt doesn't use it for this). Every harness below feeds the same canonical model; adapters are parameterized by format family where stores share a shape. Sources are opened read-only and never modified.
Recognized but deliberately unreadable (encrypted, zstd-compressed or per-project stores without a stable schema): aider, antigravity, cherry studio, codewhale, copilot, crush, cursor, deepseek, devin, hermes, jetbrains, junie, muse, openclaw, reasonix, windsurf, zed — toknt doctor lists them so "known" is never confused with "readable".
Config: [adapters] enabled = [...] accepts any of the harness ids above (default: all); paths overrides a harness's root, e.g. paths = { cline = "/Volumes/backup/cline" }.
Period options accept 30d, 12h, 8w, calendar dates (2026-10-01) and all; --harness (alias --agent), --model and --project filters repeat.
toknt usage --since 90d --by model --metric cached --chart stacked toknt tools --since 30d --chart trend --bucket week toknt export --what usage --format csv --since 7d > usage.csv toknt pricing add gpt-6-luna --input 1.25 --output 10 --cache-read 0.125 Token accounting Token categories overlap differently across providers, so every usage event stores a token_scheme and totals are computed per scheme:
Source-specific rules enforced by the adapters:
The optional config file lives in the platform config directory — run toknt doctor to see the exact path (~/.config/toknt/config.toml when XDG_CONFIG_HOME is set, ~/Library/Application Support/toknt/config.toml otherwise on macOS, XDG on Linux), or point TOKNT_CONFIG anywhere:
[general] since = "30d" # default window for all commands bucket = "day" # hour | day | week [adapters] enabled = ["opencode", "codex", "claude_code"] # [] disables scanning entirely paths = { codex = "/Volumes/external/codex" } # per-agent source overrides [display] aliases = { "claude-sonnet-4-5" = "Sonnet 4.5" } # display only; ids stay exact [privacy] ignore_projects = ["/work/secret"] # excluded from analytics [pricing."gpt-6-luna"] # override or extend table prices, field-wise input = 1.25 output = 10 cache_read = 0.125 TOKNT_DATA_DIR relocates the database (default: platform application-data directory, ~/Library/Application Support/toknt/toknt.db on macOS).
toknt doctor explains, without reading any source content:
Quality codes: unparsable_row, unreadable_file, missing_usage, missing_token_info, orphan_tool_output, orphan_tool_result, scan_failed. When a source was last scanned with status partial or error, doctor suggests toknt scan --full to rebuild it from scratch.
Tool success rates use only calls with a known final outcome; pending and unknown calls are excluded from the denominator and stay visible in the outcome columns, so a success rate can never flatter the data. (In the TUI's tools table the unknown column counts both — a pending call has no result yet, which is the same "not a known outcome" bucket.)
Stored per event: timestamps, token counts, cost fields, model/provider/agent ids, project paths, session ids, tool names, outcome status and quality notes. Never stored: prompt bodies, model responses, tool arguments, tool outputs, file contents, credentials.
toknt reads sources incrementally (checkpoints with byte offsets and fingerprints for JSONL, per-source watermarks for SQLite) and indexes SQLite for timestamp/model/session/agent/tool queries. Unchanged files are skipped by a stat check.
tests/test_performance.py builds a synthetic six-month history — three harnesses, 30k usage events and 15k tool calls, including duplicate legacy OpenCode rows, both Codex format generations and Claude snapshot dedupe — and measures (Apple Silicon laptop, SSD, 2026-10):
Real-machine full rescan of ~20k OpenCode events with full-size payloads plus the Codex rollouts takes ≈5 s; synthetic JSON payloads are compact, so treat cold-scan figures as a lower bound. Run uv run pytest tests/test_performance.py -s -q to reproduce; the test also asserts per-agent row counts exactly, so repeated scans can never inflate totals.
uv sync # create the venv and install dependencies uv run pytest # full suite (hermetic; never reads real history) uv run pytest tests/test_performance.py -s -q # benchmark with timings uv run ruff check . # lint uv run toknt doctor # inspect local database and source detection Test fixtures are synthetic and sanitized (tests/fixtures, tests/support); the suite covers parsing pitfalls for every source format family, dedupe and rescans, truncated/replaced files, subagents, outcome correlation, pricing strictness, timezone/bucket boundaries, exports and CLI behavior on empty databases. Milestones and their completion gates are recorded in plan.md.
ai analytics cli codex developer-tools opencode tokens tui usage
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.




