llm-usage-metrics 0.1.7 → 0.1.9
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 +99 -16
- package/dist/index.js +672 -74
- package/dist/index.js.map +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
# llm-usage-metrics
|
|
2
2
|
|
|
3
|
+
[](https://deepwiki.com/ayagmar/llm-usage-metrics)
|
|
4
|
+
[](https://github.com/ayagmar/llm-usage-metrics/actions/workflows/ci.yml)
|
|
5
|
+
[](https://codecov.io/gh/ayagmar/llm-usage-metrics)
|
|
6
|
+
[](https://www.npmjs.com/package/llm-usage-metrics)
|
|
7
|
+
[](https://www.npmjs.com/package/llm-usage-metrics)
|
|
8
|
+
[](https://packagephobia.com/result?p=llm-usage-metrics)
|
|
9
|
+
|
|
3
10
|
CLI to aggregate local LLM usage from:
|
|
4
11
|
|
|
5
12
|
- `~/.pi/agent/sessions/**/*.jsonl`
|
|
6
13
|
- `~/.codex/sessions/**/*.jsonl`
|
|
14
|
+
- OpenCode SQLite DB (auto-discovered or provided via `--opencode-db`)
|
|
7
15
|
|
|
8
16
|
Reports are available for daily, weekly (Monday-start), and monthly periods.
|
|
9
17
|
|
|
10
18
|
Project documentation is available in [`docs/`](./docs/README.md).
|
|
11
19
|
|
|
12
|
-
Built-in adapters currently support `.pi
|
|
20
|
+
Built-in adapters currently support 3 sources: `.pi`, `.codex`, and OpenCode SQLite. The codebase is structured to add more sources (for example Claude/Gemini exports) through the `SourceAdapter` pattern. See [`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
|
13
21
|
|
|
14
22
|
## Install
|
|
15
23
|
|
|
@@ -25,13 +33,20 @@ npx --yes llm-usage-metrics daily
|
|
|
25
33
|
|
|
26
34
|
(`npx llm-usage daily` works when the project is already installed locally.)
|
|
27
35
|
|
|
36
|
+
Runtime notes:
|
|
37
|
+
|
|
38
|
+
- OpenCode parsing requires Node.js 24+ (`node:sqlite`).
|
|
39
|
+
- Bun is supported for dependency/scripts workflow, but OpenCode report runs should use Node-based CLI execution.
|
|
40
|
+
- Example local execution against built dist: `node dist/index.js daily --source opencode --opencode-db /path/to/opencode.db`
|
|
41
|
+
|
|
28
42
|
## Update checks
|
|
29
43
|
|
|
30
44
|
When installed globally, the CLI performs a lightweight npm update check on startup.
|
|
31
45
|
|
|
32
46
|
Behavior:
|
|
33
47
|
|
|
34
|
-
- uses a local cache (`~/.cache/llm-usage-metrics/update-check.json`) with TTL
|
|
48
|
+
- uses a local cache (`<platform-cache-root>/llm-usage-metrics/update-check.json`; defaults to `~/.cache/llm-usage-metrics/update-check.json` on Linux when `XDG_CACHE_HOME` is unset) with a 1-hour default TTL
|
|
49
|
+
- optional session-scoped cache mode via `LLM_USAGE_UPDATE_CACHE_SCOPE=session`
|
|
35
50
|
- skips checks for `--help` / `--version` invocations
|
|
36
51
|
- skips checks when run through `npx`
|
|
37
52
|
- prompts for install + restart only in interactive TTY sessions
|
|
@@ -48,7 +63,9 @@ LLM_USAGE_SKIP_UPDATE_CHECK=1 llm-usage daily
|
|
|
48
63
|
You can tune runtime behavior with environment variables:
|
|
49
64
|
|
|
50
65
|
- `LLM_USAGE_SKIP_UPDATE_CHECK`: skip startup update check when set to `1`
|
|
51
|
-
- `
|
|
66
|
+
- `LLM_USAGE_UPDATE_CACHE_SCOPE`: cache scope for update checks (`global` default, `session` to scope by terminal shell session)
|
|
67
|
+
- `LLM_USAGE_UPDATE_CACHE_SESSION_KEY`: optional custom session key when `LLM_USAGE_UPDATE_CACHE_SCOPE=session` (defaults to parent shell PID)
|
|
68
|
+
- `LLM_USAGE_UPDATE_CACHE_TTL_MS`: update-check cache TTL in milliseconds (clamped: `0..2592000000`; use `0` to check on every CLI run)
|
|
52
69
|
- `LLM_USAGE_UPDATE_FETCH_TIMEOUT_MS`: update-check network timeout in milliseconds (clamped: `200..30000`)
|
|
53
70
|
- `LLM_USAGE_PRICING_CACHE_TTL_MS`: pricing cache TTL in milliseconds (clamped: `60000..2592000000`)
|
|
54
71
|
- `LLM_USAGE_PRICING_FETCH_TIMEOUT_MS`: pricing fetch timeout in milliseconds (clamped: `200..30000`)
|
|
@@ -122,42 +139,105 @@ Or use generic source-id mapping (repeatable):
|
|
|
122
139
|
llm-usage daily --source-dir pi=/path/to/pi/sessions --source-dir codex=/path/to/codex/sessions
|
|
123
140
|
```
|
|
124
141
|
|
|
125
|
-
|
|
142
|
+
Directory override rules:
|
|
126
143
|
|
|
127
|
-
|
|
144
|
+
- `--source-dir` is directory-only (currently `pi` and `codex`).
|
|
145
|
+
- `--source-dir opencode=...` is invalid and points to `--opencode-db`.
|
|
146
|
+
- `--opencode-db <path>` sets an explicit OpenCode SQLite DB path.
|
|
147
|
+
|
|
148
|
+
OpenCode DB override:
|
|
128
149
|
|
|
129
150
|
```bash
|
|
130
|
-
llm-usage
|
|
151
|
+
llm-usage daily --opencode-db /path/to/opencode.db
|
|
131
152
|
```
|
|
132
153
|
|
|
133
|
-
|
|
154
|
+
OpenCode path precedence:
|
|
155
|
+
|
|
156
|
+
1. explicit `--opencode-db`
|
|
157
|
+
2. deterministic OS-specific default path candidates
|
|
158
|
+
|
|
159
|
+
Backfill example from a historical DB snapshot:
|
|
134
160
|
|
|
135
161
|
```bash
|
|
136
|
-
llm-usage monthly --source
|
|
162
|
+
llm-usage monthly --source opencode --opencode-db /archives/opencode-2026-01.db --since 2026-01-01 --until 2026-01-31
|
|
137
163
|
```
|
|
138
164
|
|
|
139
|
-
|
|
165
|
+
OpenCode safety notes:
|
|
166
|
+
|
|
167
|
+
- OpenCode DB is opened in read-only mode
|
|
168
|
+
- unreadable/missing explicit paths fail fast with actionable errors
|
|
169
|
+
- OpenCode CLI is optional for troubleshooting and not required for runtime parsing
|
|
170
|
+
|
|
171
|
+
### Filter by source (`--source`)
|
|
172
|
+
|
|
173
|
+
Use `--source` to limit reports to one or more source ids.
|
|
174
|
+
|
|
175
|
+
Supported source ids:
|
|
176
|
+
|
|
177
|
+
- `pi`
|
|
178
|
+
- `codex`
|
|
179
|
+
- `opencode`
|
|
180
|
+
|
|
181
|
+
Behavior:
|
|
182
|
+
|
|
183
|
+
- repeatable or comma-separated (`--source pi --source codex` or `--source pi,codex`)
|
|
184
|
+
- case-insensitive source id matching
|
|
185
|
+
- unknown ids fail fast with a validation error
|
|
186
|
+
|
|
187
|
+
Examples:
|
|
140
188
|
|
|
141
189
|
```bash
|
|
190
|
+
# only codex data
|
|
191
|
+
llm-usage monthly --source codex
|
|
192
|
+
|
|
193
|
+
# only pi data
|
|
194
|
+
llm-usage monthly --source pi
|
|
195
|
+
|
|
196
|
+
# only OpenCode data
|
|
197
|
+
llm-usage monthly --source opencode
|
|
198
|
+
|
|
199
|
+
# multiple sources
|
|
142
200
|
llm-usage monthly --source pi --source codex
|
|
143
201
|
llm-usage monthly --source pi,codex
|
|
202
|
+
|
|
203
|
+
# OpenCode source with explicit DB path
|
|
204
|
+
llm-usage monthly --source opencode --opencode-db /path/to/opencode.db
|
|
144
205
|
```
|
|
145
206
|
|
|
146
|
-
### Filter by provider (
|
|
207
|
+
### Filter by provider (`--provider`)
|
|
208
|
+
|
|
209
|
+
Use `--provider` to keep only events whose provider contains the filter text.
|
|
210
|
+
|
|
211
|
+
Behavior:
|
|
212
|
+
|
|
213
|
+
- case-insensitive substring match
|
|
214
|
+
- optional flag (when omitted, all providers are included)
|
|
215
|
+
- works together with `--source` and `--model`
|
|
216
|
+
|
|
217
|
+
Examples:
|
|
147
218
|
|
|
148
219
|
```bash
|
|
220
|
+
# all OpenAI-family providers
|
|
149
221
|
llm-usage monthly --provider openai
|
|
222
|
+
|
|
223
|
+
# GitHub Models providers
|
|
150
224
|
llm-usage monthly --provider github
|
|
151
|
-
|
|
225
|
+
|
|
226
|
+
# source + provider together
|
|
227
|
+
llm-usage monthly --source codex --provider openai
|
|
152
228
|
```
|
|
153
229
|
|
|
154
|
-
### Filter by model (
|
|
230
|
+
### Filter by model (`--model`)
|
|
231
|
+
|
|
232
|
+
`--model` supports repeatable and comma-separated filters. Matching is case-insensitive.
|
|
155
233
|
|
|
156
|
-
|
|
234
|
+
Per filter value:
|
|
157
235
|
|
|
158
|
-
- if an exact model exists
|
|
236
|
+
- if an exact model id exists in the currently selected event set (after source/provider/date filtering), exact matching is used
|
|
159
237
|
- otherwise, substring matching is used
|
|
160
238
|
|
|
239
|
+
Examples:
|
|
240
|
+
|
|
161
241
|
```bash
|
|
162
242
|
# substring match (all Claude-family models)
|
|
163
243
|
llm-usage monthly --model claude
|
|
@@ -165,9 +245,12 @@ llm-usage monthly --model claude
|
|
|
165
245
|
# exact match when present
|
|
166
246
|
llm-usage monthly --model claude-sonnet-4.5
|
|
167
247
|
|
|
168
|
-
# multiple filters
|
|
248
|
+
# multiple model filters
|
|
169
249
|
llm-usage monthly --model claude --model gpt-5
|
|
170
250
|
llm-usage monthly --model claude,gpt-5
|
|
251
|
+
|
|
252
|
+
# source + provider + model together
|
|
253
|
+
llm-usage monthly --source opencode --provider openai --model gpt-4.1
|
|
171
254
|
```
|
|
172
255
|
|
|
173
256
|
### Per-model columns (opt-in detailed table layout)
|
|
@@ -218,7 +301,7 @@ Example output:
|
|
|
218
301
|
|
|
219
302
|
Each report includes:
|
|
220
303
|
|
|
221
|
-
- source rows (`pi`, `codex`) for each period
|
|
304
|
+
- source rows (`pi`, `codex`, `opencode`) for each period
|
|
222
305
|
- a per-period combined subtotal row (only when multiple sources exist in that period)
|
|
223
306
|
- a final grand total row across all periods
|
|
224
307
|
|