@tokz/cli 0.2.4 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,127 +1,153 @@
1
1
  # tokz
2
2
 
3
- Audit where your coding agents' context windows — and API dollars — actually go.
4
-
5
- Supports multiple agentic coders: **Claude Code** (`~/.claude/projects`),
6
- **OpenAI Codex CLI** (`~/.codex/sessions` rollout files, cumulative
7
- token-count deltas), **OpenCode** (`~/.local/share/opencode/storage`), and
8
- **Antigravity CLI** (`~/.gemini/antigravity-cli`). Antigravity stores no
9
- token counts on disk, so its numbers are *estimates*: per-model turn counts
10
- are read from the conversation databases' generation-metadata records,
11
- projects and dates from `history.jsonl`, and tokens are derived from
12
- conversation content size (~4 chars/token) — the UI labels it "estimated"
13
- everywhere. Cursor CLI is detected and listed with the reason it can't be
14
- parsed yet. The TUI opens with an agent picker — choose which agent's
15
- analytics to explore; everything downstream (projects, dashboards,
16
- timeframes) is scoped to it.
3
+ **See where your coding agents' tokens — and dollars — actually go.**
4
+
5
+ tokz reads the session logs your coding agents already write to disk and turns
6
+ them into a clear picture of cost: per model, per project, per tool, per day,
7
+ and per MCP server — including the ones you pay to load on every turn but never
8
+ call. One command, no API key, nothing leaves your machine except an optional
9
+ pricing refresh.
17
10
 
18
11
  ```bash
19
- npx @tokz/cli # interactive TUI: browse projects, drill into charts
12
+ npx @tokz/cli # interactive TUI — pick an agent, browse projects, drill into charts
20
13
  npx @tokz/cli audit # static report for the current project
21
14
  npx @tokz/cli audit --all # static report across every project on this machine
22
15
  npx @tokz/cli blocks # Claude usage by rolling 5-hour billing window
23
16
 
24
- npm i -g @tokz/cli # installs the `tokz` command
25
- tokz # then just: tokz
17
+ npm i -g @tokz/cli # install the `tokz` command, then just: tokz
26
18
  ```
27
19
 
28
- ## Blocks (5-hour billing windows)
20
+ The TUI opens on an agent picker; everything downstream — projects, dashboards,
21
+ timeframes — is scoped to the agent you choose.
22
+
23
+ ## Supported agents
24
+
25
+ tokz auto-detects each agent from its local data directory. No configuration.
26
+
27
+ | Agent | Reads from | Status |
28
+ | --- | --- | --- |
29
+ | Claude Code | `~/.claude/projects` | ✅ parsed |
30
+ | OpenAI Codex | `~/.codex/sessions` | ✅ parsed |
31
+ | OpenCode | `~/.local/share/opencode` | ✅ parsed |
32
+ | Gemini CLI | `~/.gemini/tmp` | ✅ parsed |
33
+ | Qwen Code | `~/.qwen` | ✅ parsed |
34
+ | Droid (Factory) | `~/.factory/sessions` | ✅ parsed |
35
+ | Codebuff | `~/.config/manicode*` | ✅ parsed |
36
+ | OpenClaw | `~/.openclaw` | ✅ parsed |
37
+ | Kimi CLI | `~/.kimi` | ✅ parsed |
38
+ | pi-agent | `~/.pi/agent` | ✅ parsed |
39
+ | Kilo | `~/.local/share/kilo/kilo.db` | ✅ parsed (SQLite) |
40
+ | Goose | `~/.local/share/goose` | ✅ parsed (SQLite) |
41
+ | Hermes | `~/.hermes/state.db` | ✅ parsed (SQLite) |
42
+ | Antigravity | `~/.gemini/antigravity-cli` | ≈ estimated¹ |
43
+ | GitHub Copilot CLI | `~/.copilot/otel` | 🔍 detected, not parsed² |
44
+ | Amp | `~/.local/share/amp` | 🔍 detected, not parsed² |
45
+
46
+ ¹ Antigravity stores no token counts on disk. tokz reads real per-model turn
47
+ counts from its conversation databases and estimates tokens from content size
48
+ (~4 chars/token); the UI labels every Antigravity number **estimated**.
49
+
50
+ ² Detected and listed with the reason, but not yet parsed: Copilot stores usage
51
+ as OpenTelemetry spans, Amp as a usage ledger. (Cursor is intentionally left
52
+ out — it keeps no token counts locally; usage lives server-side behind auth.)
53
+
54
+ The three SQLite-backed agents are read with a small built-in pure-JS SQLite
55
+ reader, so there's no native dependency and `npx` just works.
29
56
 
30
- `tokz blocks` groups Claude usage into the rolling 5-hour windows Claude's
31
- usage limits operate on: one row per block with models, total tokens, and
32
- cost, plus burn rate (tok/min and $/hr), projected tokens/cost by block end,
33
- and time remaining for the active block. `--active` shows only the current
34
- block, `--recent` the last 3 days, `--token-limit N` (or `max` — your
35
- biggest past block) adds ⚠️/🚨 warnings, `--session-length H` changes the
36
- window, `--json` for raw output.
57
+ ## Interactive TUI
37
58
 
38
- ## Statusline for Claude Code
59
+ Bare `tokz` launches a full-screen Ink UI: a live parse progress bar, then a
60
+ landing screen of stat cards — total cost, monthly projection, sessions, turns,
61
+ cache hit rate — with a 30-day activity sparkline.
39
62
 
40
- `tokz statusline` renders one compact line for Claude Code's status bar
41
- model, session cost, today's total, active block cost with time left, burn
42
- rate, and context usage with percentage. One command wires it up:
63
+ - **Project list** every project by short name (real paths recovered from the
64
+ transcripts), ranked by cost, with session count, last activity, and share
65
+ bars, plus a pinned **All projects** row. `/` filters, `s` cycles the sort
66
+ (cost · recent · name), `a` jumps to the aggregate view.
67
+ - **Dashboard** (per project or aggregated) — six tabs via `1–6` or `←`/`→`:
68
+ 1. **Overview** — stat cards, 30-day cost sparkline with peak day, cost by
69
+ model, top tools, unused-server warning.
70
+ 2. **Models** — per-model token table (input / cache read / cache write /
71
+ output / turns), cost, and share.
72
+ 3. **Tools** — top tools ranked by estimated cost (each turn's bill split
73
+ across the tools it called), with call counts; MCP tools highlighted.
74
+ 4. **Servers** — every MCP server with calls observed and estimated cost,
75
+ from configs (`.mcp.json`, `~/.claude.json`) and from transcripts alone
76
+ (plugin and externally-managed servers) — plus whether each is dead weight.
77
+ 5. **Sessions** — costliest sessions with date, wall-clock length, turns, tool
78
+ calls, and dominant model.
79
+ 6. **Activity** — daily cost bars with turn counts; `g` groups by day · week ·
80
+ month.
81
+ - **Timeframe** — `t` cycles All time · Today · Yesterday · Last 7 days · Last
82
+ 30 days; every list, chart, and total rescopes.
83
+ - `?` help overlay, `esc` back, `q` quit.
84
+
85
+ The layout is responsive down to ~35 columns — tables drop non-essential
86
+ columns, tab labels collapse to numbers, the banner shrinks — and long lists
87
+ scroll. Piped or non-interactive, `tokz` prints the static aggregate report.
88
+
89
+ ## Blocks — Claude's 5-hour windows
90
+
91
+ `tokz blocks` groups Claude usage into the rolling 5-hour windows its usage
92
+ limits operate on: one row per block with models, total tokens, and cost, plus
93
+ burn rate (tok/min and $/hr), projected tokens and cost by block end, and time
94
+ remaining on the active block.
43
95
 
44
96
  ```bash
45
- tokz statusline enable # writes the hook into ~/.claude/settings.json
46
- tokz statusline disable # removes it (only if it's tokz's)
97
+ tokz blocks --active # only the current block
98
+ tokz blocks --recent # last 3 days
99
+ tokz blocks --token-limit max # ⚠️/🚨 warnings vs your biggest past block
100
+ tokz blocks --session-length 5 # window length in hours (default 5)
101
+ tokz blocks --json # raw output
47
102
  ```
48
103
 
49
- `enable` preserves everything else in your settings file (and refuses to
50
- touch one it can't parse); it's equivalent to:
51
-
52
- ```json
53
- {
54
- "statusLine": { "type": "command", "command": "npx -y @tokz/cli statusline" }
55
- }
56
- ```
104
+ ## Statusline for Claude Code
57
105
 
58
- It reads only transcripts touched in the last few hours and never fetches
59
- pricing from the network on this path, so it stays fast.
106
+ `tokz statusline` renders one compact line for Claude Code's status bar:
60
107
 
61
- ## Dates, ranges, and timezones
108
+ ```text
109
+ 🤖 Fable 5 (high) | 💰 $0.23 session / $1.23 today / $0.45 block (2h 45m left) | 🔥 $0.12/hr | 🧠 25,000 (12%)
110
+ ```
62
111
 
63
- - `tokz audit --since 2026-07-01 --until 2026-07-15` any inclusive date
64
- range (also accepts `YYYYMMDD`); `--days N` still works.
65
- - `tokz audit --weekly` / `--monthly` appends an activity table rolled up
66
- by ISO week (keyed by its Monday) or calendar month. In the TUI the
67
- Activity tab cycles day · week · month with `g`.
68
- - `tokz --timezone local audit …` — group days in your system timezone, or
69
- any IANA zone (`--timezone Asia/Amman`); default is UTC.
112
+ Model with reasoning effort, session cost, today's total, active-block cost with
113
+ time left, burn rate (colored by tokens/min), and context usage (colored by how
114
+ full the window is). Session cost, context, and effort come from Claude Code's
115
+ hook payload; today's total and the block come from your local transcripts.
70
116
 
71
- ## Interactive TUI
117
+ ```bash
118
+ tokz statusline enable # add the hook to ~/.claude/settings.json
119
+ tokz statusline disable # remove it (only if it's tokz's)
120
+ ```
72
121
 
73
- Bare `tokz` launches a full-screen terminal UI (Ink) with a live parse
74
- progress bar, then a landing screen of stat cards — total cost, monthly
75
- projection, sessions, turns, cache hit rate plus a 30-day activity
76
- sparkline.
122
+ `enable` preserves everything else in your settings and refuses to touch a file
123
+ it can't parse. `--cost-source auto|cc|calc|both` picks the session-cost source:
124
+ `cc` uses Claude Code's own figure, `calc` recomputes from tokens, `both` shows
125
+ `($0.25 cc / $0.23 calc)`. The statusline reads only recently-touched
126
+ transcripts and never fetches pricing, so it stays instant.
77
127
 
78
- From there:
128
+ ## Dates, ranges, timezones
79
129
 
80
- - **Project list** — every project by short name (real paths recovered from
81
- the transcripts themselves), ranked by cost, with session count, last
82
- activity, and share bars, plus a pinned **All projects** row. Press `/` to
83
- filter by name, `s` to cycle sorting (cost · recent · name), `a` to jump to
84
- the aggregate view.
85
- - **Dashboard** (per project or aggregated) — six tabs, switched with `1–6`
86
- or `←`/`→`:
87
- 1. **Overview** — stat cards, 30-day cost sparkline with peak day, cost by
88
- model, top tools, unused-server warning.
89
- 2. **Models** — per-model token table (input / cache read / cache write /
90
- output / turns), cost and share, plus the total cost split.
91
- 3. **Tools** — top tools ranked by estimated cost (each turn's bill split
92
- across the tools that turn called) with call counts and share; MCP tools
93
- highlighted.
94
- 4. **Servers** — every MCP server with calls observed and estimated cost.
95
- Covers both configured servers (`.mcp.json`, `~/.claude.json`) and ones
96
- only visible in transcripts — plugin MCP servers and externally managed
97
- configs — plus whether each is dead weight in your context window.
98
- 5. **Sessions** — costliest sessions with date, wall-clock length, turns,
99
- tool calls, and dominant model.
100
- 6. **Activity** — daily cost bars with turn counts, average per active day.
101
- - **Timeframe** — press `t` anywhere to cycle All time · Today · Yesterday ·
102
- Last 7 days · Last 30 days; every list, chart, and total rescopes to that
103
- window (`--days N` does the same for the static report).
104
- - `?` shows a help overlay, `esc` goes back, `q` quits.
105
-
106
- The layout is responsive: on narrow terminals the list drops columns (share
107
- bar, then last-active, then sessions), tables keep only their key columns,
108
- tab labels collapse to numbers, and the banner shrinks — nothing wraps or
109
- breaks down to ~35 columns.
110
-
111
- Piped or non-interactive, `tokz` falls back to the static aggregate report
112
- automatically.
130
+ ```bash
131
+ tokz audit --since 2026-07-01 --until 2026-07-15 # any inclusive range (also YYYYMMDD)
132
+ tokz audit --days 7 # last N days
133
+ tokz audit --weekly # or --monthly appends an activity table by ISO week / month
134
+ tokz --timezone local audit … # or any IANA zone; default UTC
135
+ ```
113
136
 
114
137
  ## What it measures
115
138
 
116
- Reads Claude Code transcripts (`~/.claude/projects/**/*.jsonl`) and MCP configs
117
- (`.mcp.json`, `~/.claude.json`). Reports real billed token usage per model
118
- (input / cache read / cache write / output), dollar cost at current Anthropic
119
- pricing, a monthly projection, cache hit rate and estimated cache savings,
120
- per-tool call counts, per-day activity, per-session cost, and — the headline —
121
- **MCP servers you pay to load on every turn but never call**.
139
+ Real billed token usage per model (input / cache read / cache write / output),
140
+ dollar cost, monthly projection, cache hit rate and estimated cache savings,
141
+ per-tool call counts and cost, per-day activity, per-session cost, and the
142
+ headline **MCP servers you pay to load on every turn but never call**.
143
+
144
+ Costs are API-equivalent: what these tokens would bill at pay-as-you-go rates.
145
+ On a Pro/Max subscription, read it as value received, not a bill. Pricing comes
146
+ from a live model catalog, cached on disk for a day; run with `--offline` to
147
+ skip the fetch and use built-in rates.
122
148
 
123
- Costs are API-equivalent: what these tokens would bill at Anthropic
124
- pay-as-you-go rates. On a Pro/Max subscription treat it as value received,
125
- not a bill.
149
+ ## Privacy
126
150
 
127
- 100% offline. No API key, no telemetry, nothing leaves your machine.
151
+ Your session logs never leave your machine. The only network call tokz ever
152
+ makes is fetching public model pricing (cacheable, and fully skippable with
153
+ `--offline`). No API key, no telemetry.