@tokz/cli 0.2.3 → 0.2.5

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,78 +1,153 @@
1
1
  # tokz
2
2
 
3
- Audit where your coding agents' context windows — and API dollars — actually go.
3
+ **See where your coding agents' tokens — and dollars — actually go.**
4
4
 
5
- Supports multiple agentic coders: **Claude Code** (`~/.claude/projects`),
6
- **OpenAI Codex CLI** (`~/.codex/sessions` rollout files, cumulative
7
- token-count deltas), and **OpenCode** (`~/.local/share/opencode/storage`).
8
- Gemini CLI and Cursor CLI are detected and listed; their session formats
9
- aren't parsed yet. The TUI opens with an agent picker — choose which agent's
10
- analytics to explore; everything downstream (projects, dashboards,
11
- timeframes) is scoped to it.
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.
12
10
 
13
11
  ```bash
14
- npx @tokz/cli # interactive TUI: browse projects, drill into charts
12
+ npx @tokz/cli # interactive TUI — pick an agent, browse projects, drill into charts
15
13
  npx @tokz/cli audit # static report for the current project
16
14
  npx @tokz/cli audit --all # static report across every project on this machine
15
+ npx @tokz/cli blocks # Claude usage by rolling 5-hour billing window
17
16
 
18
- npm i -g @tokz/cli # installs the `tokz` command
19
- tokz # then just: tokz
17
+ npm i -g @tokz/cli # install the `tokz` command, then just: tokz
20
18
  ```
21
19
 
22
- ## Interactive TUI
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.
23
56
 
24
- Bare `tokz` launches a full-screen terminal UI (Ink) with a live parse
25
- progress bar, then a landing screen of stat cards — total cost, monthly
26
- projection, sessions, turns, cache hit rate — plus a 30-day activity
27
- sparkline.
57
+ ## Interactive TUI
28
58
 
29
- From there:
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.
30
62
 
31
- - **Project list** — every project by short name (real paths recovered from
32
- the transcripts themselves), ranked by cost, with session count, last
33
- activity, and share bars, plus a pinned **All projects** row. Press `/` to
34
- filter by name, `s` to cycle sorting (cost · recent · name), `a` to jump to
35
- the aggregate view.
36
- - **Dashboard** (per project or aggregated) — six tabs, switched with `1–6`
37
- or `←`/`→`:
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 `←`/`→`:
38
68
  1. **Overview** — stat cards, 30-day cost sparkline with peak day, cost by
39
69
  model, top tools, unused-server warning.
40
70
  2. **Models** — per-model token table (input / cache read / cache write /
41
- output / turns), cost and share, plus the total cost split.
71
+ output / turns), cost, and share.
42
72
  3. **Tools** — top tools ranked by estimated cost (each turn's bill split
43
- across the tools that turn called) with call counts and share; MCP tools
44
- highlighted.
45
- 4. **Servers** every MCP server with calls observed and estimated cost.
46
- Covers both configured servers (`.mcp.json`, `~/.claude.json`) and ones
47
- only visible in transcripts plugin MCP servers and externally managed
48
- configs plus whether each is dead weight in your context window.
49
- 5. **Sessions** — costliest sessions with date, wall-clock length, turns,
50
- tool calls, and dominant model.
51
- 6. **Activity** — daily cost bars with turn counts, average per active day.
52
- - **Timeframe** press `t` anywhere to cycle All time · Today · Yesterday ·
53
- Last 7 days · Last 30 days; every list, chart, and total rescopes to that
54
- window (`--days N` does the same for the static report).
55
- - `?` shows a help overlay, `esc` goes back, `q` quits.
56
-
57
- The layout is responsive: on narrow terminals the list drops columns (share
58
- bar, then last-active, then sessions), tables keep only their key columns,
59
- tab labels collapse to numbers, and the banner shrinks nothing wraps or
60
- breaks down to ~35 columns.
61
-
62
- Piped or non-interactive, `tokz` falls back to the static aggregate report
63
- automatically.
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
+ ## BlocksClaude'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.
95
+
96
+ ```bash
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
102
+ ```
103
+
104
+ ## Statusline for Claude Code
105
+
106
+ `tokz statusline` renders one compact line for Claude Code's status bar:
107
+
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
+ ```
111
+
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.
116
+
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
+ ```
121
+
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.
127
+
128
+ ## Dates, ranges, timezones
129
+
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
+ ```
64
136
 
65
137
  ## What it measures
66
138
 
67
- Reads Claude Code transcripts (`~/.claude/projects/**/*.jsonl`) and MCP configs
68
- (`.mcp.json`, `~/.claude.json`). Reports real billed token usage per model
69
- (input / cache read / cache write / output), dollar cost at current Anthropic
70
- pricing, a monthly projection, cache hit rate and estimated cache savings,
71
- per-tool call counts, per-day activity, per-session cost, and — the headline —
72
- **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.
73
148
 
74
- Costs are API-equivalent: what these tokens would bill at Anthropic
75
- pay-as-you-go rates. On a Pro/Max subscription treat it as value received,
76
- not a bill.
149
+ ## Privacy
77
150
 
78
- 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.