big-spender 0.6.0 → 0.8.0

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
@@ -327,23 +327,27 @@ about 15 to 20 percent less.
327
327
 
328
328
  ## How it counts
329
329
 
330
- | Source | Files | Notes |
331
- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
332
- | Claude Code | `~/.claude/projects/**/*.jsonl`, `~/.config/claude/projects`, `$CLAUDE_CONFIG_DIR/projects` | `assistant` lines; de-duplicated by `message.id` + `requestId` (one API response is logged once per content block, and resumed sessions copy history). `<synthetic>` skipped; subagent logs included. Some Claude Code versions (2.1.293 to 2.1.310) log a partial output count on a message's first line and the final count on a later line; a later line that reports more output adds the difference. |
333
- | Codex | `~/.codex/sessions/**/rollout-*.jsonl`, `$CODEX_HOME/sessions` | `event_msg` / `token_count` with `info.last_token_usage`; skipped when `total_token_usage` did not change. Model from the latest `turn_context`. `cached_input_tokens` is part of `input_tokens`; reasoning is part of `output_tokens`. |
334
- | Cursor | Cursor's API, `DashboardService/GetFilteredUsageEvents`, with `BIG_SPENDER_CURSOR_API_KEY` | Events with token counts only. Cost is Cursor's `totalCents`. Events have no unique id and pages can overlap, so a time window with more than 1,000 events is split in half instead of paged. `cacheWriteTokens` count as 5-minute cache writes. Sessions are hashed `conversationId`s. Model names are lowercased, and anything outside `a-z 0-9 . _ : @ -` becomes `-`. |
335
- | pi | `~/.pi/agent/sessions/**/*.jsonl`, `$PI_CODING_AGENT_DIR/sessions`, `$PI_CODING_AGENT_SESSION_DIR`, `$PI_AGENT_DIR` (comma-separated, as in ccusage) | Assistant `message` entries with `usage`; `input` excludes cached tokens, reasoning is part of `output`, and `cacheWrite` counts as 5-minute writes except its `cacheWrite1h` part. Calls with no tokens (aborted, failed before a retry) are skipped, and a call with only `totalTokens` counts it as output. A fork's file starts with a copy of its parent's calls up to the fork; those leading calls are skipped when the parent file has them. ccusage looks only at the parent's current branch, so it counts the copy again once the parent moves to another branch. A model id that is a file path (absolute, a `file://` or `host:/` URL, or ending in `.gguf` and similar) is reduced to its file name. `subagent-artifacts/` transcripts are skipped. Cost is LiteLLM's, not the cost pi stores. |
336
-
337
- **Pricing.** Claude Code, Codex and pi use LiteLLM `model_prices_and_context_window.json`, cached
338
- for 24 hours in `~/.cache/big-spender/`. Each source lists the LiteLLM keys to try for a model. Claude
330
+ | Source | Files | Notes |
331
+ | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
332
+ | Claude Code | `~/.claude/projects/**/*.jsonl`, `~/.config/claude/projects`, `$CLAUDE_CONFIG_DIR/projects` | `assistant` lines; de-duplicated by `message.id` + `requestId` (one API response is logged once per content block, and resumed sessions copy history). `<synthetic>` skipped; subagent logs included. Some Claude Code versions (2.1.293 to 2.1.310) log a partial output count on a message's first line and the final count on a later line; a later line that reports more output adds the difference. |
333
+ | Codex | `~/.codex/sessions/**/rollout-*.jsonl`, `$CODEX_HOME/sessions` | `event_msg` / `token_count` with `info.last_token_usage`; skipped when `total_token_usage` did not change. Model from the latest `turn_context`. `cached_input_tokens` is part of `input_tokens`; reasoning is part of `output_tokens`. |
334
+ | Cursor | Cursor's API, `DashboardService/GetFilteredUsageEvents`, with `BIG_SPENDER_CURSOR_API_KEY` | Events with token counts only. Cost is Cursor's `totalCents`. Events have no unique id and pages can overlap, so a time window with more than 1,000 events is split in half instead of paged. `cacheWriteTokens` count as 5-minute cache writes. Sessions are hashed `conversationId`s. Model names are lowercased, and anything outside `a-z 0-9 . _ : @ -` becomes `-`. |
335
+ | pi | `~/.pi/agent/sessions/**/*.jsonl`, `$PI_CODING_AGENT_DIR/sessions`, `$PI_CODING_AGENT_SESSION_DIR`, `$PI_AGENT_DIR` (comma-separated, as in ccusage) | Assistant `message` entries with `usage`; `input` excludes cached tokens, reasoning is part of `output`, and `cacheWrite` counts as 5-minute writes except its `cacheWrite1h` part. Calls with no tokens (aborted, failed before a retry) are skipped, and a call with only `totalTokens` counts it as output. A fork's file starts with a copy of its parent's calls up to the fork; those leading calls are skipped when the parent file has them. ccusage looks only at the parent's current branch, so it counts the copy again once the parent moves to another branch. A model id that is a file path (absolute, a `file://` or `host:/` URL, or ending in `.gguf` and similar) is reduced to its file name. `subagent-artifacts/` transcripts are skipped. Cost is LiteLLM's, not the cost pi stores. |
336
+ | Grok Build (experimental) | `~/.grok/sessions/**/updates.jsonl`, `$GROK_HOME/sessions` | **Experimental:** checked against ccusage on test fixtures built from its Grok parser tests, not yet against real Grok Build logs. `turn_completed` lines, one row per model in `usage.modelUsage` (the top-level usage under `summary.json`'s `current_model_id` when that map is missing). De-duplicated by `eventId` + model, also across sessions, since one event can be exported into several; a row without `eventId` by its full content within its file. `cachedReadTokens` and `cacheCreationTokens` are part of `inputTokens`; reasoning is part of `outputTokens`. Always the base rate: a turn sums several API requests, so its total cannot pick the long-context tier; a request of its own above 200K tokens is under-priced. A model id that is a file path is reduced to its file name. A turn cut off before it completes is never logged, so it is not counted. |
337
+ | GitHub Copilot CLI (experimental) | `~/.copilot/session-state/*/events.jsonl`, `$COPILOT_HOME/session-state` | Experimental: so far compared with ccusage only on a few sessions from one machine and on ccusage's test fixtures, not on regular use. `session.usage_record` events (one per model call). Older versions log only `session.shutdown`; its cumulative `modelMetrics` count as the growth since the previous shutdown, and only when no per-call record came in that interval. `inputTokens` includes cache reads and writes, so input counts uncached tokens only. Reasoning is part of `outputTokens`. A `-1m` or `-1m-internal` model suffix is dropped. Only the top-level `events.jsonl` of each session is read, not the OpenTelemetry export or `session-store.db`. |
338
+
339
+ **Pricing.** Claude Code, Codex, pi, Grok Build and GitHub Copilot CLI use LiteLLM
340
+ `model_prices_and_context_window.json`, cached for 24 hours in `~/.cache/big-spender/`. Each source lists the LiteLLM keys to try for a model. Claude
339
341
  Code and Codex try the exact model, then the `anthropic/` or `openai/` prefix, then without a date
340
342
  suffix. pi tries the LiteLLM prefixes of the providers pi supports too (`openrouter/`, `fireworks_ai/`,
341
343
  `groq/` and others). For an OpenRouter id such as `anthropic/claude-sonnet-4.5` it then tries
342
- `claude-sonnet-4.5` and `claude-sonnet-4-5`. Unknown models count with cost 0 and log a warning.
344
+ `claude-sonnet-4.5` and `claude-sonnet-4-5`. Grok Build tries the model and its `xai/` key, then
345
+ both without a trailing `-build`. Unknown models count with cost 0 and log a warning.
343
346
  Long-context tiers
344
347
  (`*_above_<N>k_tokens`) are applied per request; 1-hour cache writes use
345
348
  `cache_creation_input_token_cost_above_1hr`. Cache savings are cache-read tokens times (input price
346
- minus cache-read price).
349
+ minus cache-read price). Copilot also tries `github_copilot/<model>`, and swaps a dot between digits
350
+ for a dash in Claude model names (`claude-opus-4.6` is priced as `claude-opus-4-6`).
347
351
 
348
352
  **Adding a provider.** Add an entry to `SOURCES` in `src/collector.mjs`, the provider id to
349
353
  `PROVIDERS` in `src/schema.ts`, a row to the table above, and a test with a fixture log. The entry
@@ -25,7 +25,7 @@ import { createHash } from 'node:crypto';
25
25
  import { createReadStream, existsSync, readFileSync, statSync } from 'node:fs';
26
26
  import { mkdir, open, readdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
27
27
  import { homedir } from 'node:os';
28
- import { dirname, join, resolve, sep } from 'node:path';
28
+ import { basename, dirname, join, resolve, sep } from 'node:path';
29
29
  import { gzipSync } from 'node:zlib';
30
30
 
31
31
  const SCHEMA_VERSION = 1;
@@ -120,8 +120,8 @@ async function acquireLock() {
120
120
  /**
121
121
  * @typedef {{ input: number, cacheRead: number, cacheWrite: number, output: number, savings: number }} Cost
122
122
  * @typedef {{ input: number, cacheRead: number, cacheWrite5m: number, cacheWrite1h: number, output: number, sessions: string[], cost?: Cost }} Bucket
123
- * A JSONL file's read position. Readers may keep their own fields on it (Codex: model, sessionId, lastTotal; pi: forkCalls).
124
- * @typedef {{ size: number, mtimeMs: number, offset: number, model?: string, sessionId?: string, lastTotal?: number, forkCalls?: string[] }} FileState
123
+ * A JSONL file's read position. Readers may keep their own fields on it (Codex: model, sessionId, lastTotal; pi: forkCalls; Copilot: models, callsSinceShutdown).
124
+ * @typedef {{ size: number, mtimeMs: number, offset: number, model?: string, sessionId?: string, lastTotal?: number, forkCalls?: string[], models?: Record<string, { input: number, cacheRead: number, cacheWrite: number, output: number, requests?: number }>, callsSinceShutdown?: boolean }} FileState
125
125
  * A seen entry is the first timestamp, or for Claude [first timestamp, output tokens counted].
126
126
  * A bare number on a Claude key means the counted output is unknown (state from an older version).
127
127
  * @typedef {number | [number, number]} Seen
@@ -411,7 +411,7 @@ function costOf(entry, tier, t) {
411
411
  // ---------------------------------------------------------------------------
412
412
  // Log discovery + incremental reading
413
413
 
414
- async function* walk(dir) {
414
+ async function* walk(dir, keep) {
415
415
  let entries;
416
416
  try {
417
417
  entries = await readdir(dir, { withFileTypes: true });
@@ -420,8 +420,8 @@ async function* walk(dir) {
420
420
  }
421
421
  for (const e of entries) {
422
422
  const p = join(dir, e.name);
423
- if (e.isDirectory()) yield* walk(p);
424
- else if (e.isFile() && e.name.endsWith('.jsonl')) yield p;
423
+ if (e.isDirectory()) yield* walk(p, keep);
424
+ else if (e.isFile() && keep(e.name)) yield p;
425
425
  }
426
426
  }
427
427
 
@@ -673,7 +673,7 @@ const PI_PRICE_PREFIXES = [
673
673
  ];
674
674
 
675
675
  // Local models can have a file path as their id; only the file name leaves the machine.
676
- const piModel = (model) => {
676
+ const localModelName = (model) => {
677
677
  const isPath =
678
678
  /^([/~.]|[A-Za-z]:)|\\|:\/|\/\//.test(model) ||
679
679
  /\.(gguf|ggml|bin|safetensors|pth?|onnx)$/i.test(model);
@@ -723,7 +723,7 @@ function piLineHandler(state, file, path, resolvePrice, cutoffMs) {
723
723
  if (u.ts < cutoffMs) return;
724
724
  if (state.seen[dedupe] !== undefined) return;
725
725
  state.seen[dedupe] = u.ts;
726
- const model = piModel(u.model);
726
+ const model = localModelName(u.model);
727
727
  addRecord(state, {
728
728
  ts: u.ts,
729
729
  provider: 'pi',
@@ -739,16 +739,193 @@ function piLineHandler(state, file, path, resolvePrice, cutoffMs) {
739
739
  };
740
740
  }
741
741
 
742
+ /** A Grok model id as a snapshot model name: `[grok] ` dropped, a path reduced to its file name. */
743
+ const grokModelName = (raw) => localModelName(raw.replace(/^\[grok\] /, '').trim()) || 'unknown';
744
+
745
+ // Grok Build: a completed turn appends one `turn_completed` line whose usage sums the turn's API
746
+ // requests, split per model in `modelUsage` (top-level usage and the session's current model when
747
+ // that map is missing). inputTokens includes cache reads and cache writes; reasoningTokens is part
748
+ // of outputTokens. The same event can be exported into more than one session, so rows with an
749
+ // eventId are deduplicated by eventId and model, others by their full content within the file.
750
+ function grokLineHandler(state, cutoffMs, path) {
751
+ const sessionDir = basename(dirname(path));
752
+ let currentModel;
753
+ const summaryModel = () => {
754
+ if (currentModel === undefined) {
755
+ try {
756
+ const id = JSON.parse(
757
+ readFileSync(join(dirname(path), 'summary.json'), 'utf8')
758
+ )?.current_model_id;
759
+ currentModel = typeof id === 'string' && id ? id : 'unknown';
760
+ } catch {
761
+ currentModel = 'unknown';
762
+ }
763
+ }
764
+ return currentModel;
765
+ };
766
+ const str = (v) => (typeof v === 'string' && v ? v : undefined);
767
+ // Token counts are integers; ccusage reads anything else as 0, and the schema rejects it.
768
+ const count = (v) => (Number.isInteger(v) ? num(v) : 0);
769
+ return (line) => {
770
+ if (!line.includes('"turn_completed"')) return;
771
+ const o = parseJson(line);
772
+ const p = o?.params;
773
+ const usage = p?.update?.sessionUpdate === 'turn_completed' ? p.update.usage : undefined;
774
+ if (!usage || typeof usage !== 'object') return;
775
+ // agentTimestampMs is milliseconds; the envelope timestamp is Unix seconds.
776
+ const ts = num(p._meta?.agentTimestampMs) || num(o.timestamp) * 1000;
777
+ if (!ts || ts < cutoffMs) return;
778
+ const eventId = str(p._meta?.eventId);
779
+ const session = str(p.sessionId) ?? sessionDir;
780
+ const perModel =
781
+ usage.modelUsage &&
782
+ typeof usage.modelUsage === 'object' &&
783
+ Object.keys(usage.modelUsage).length;
784
+ // Top-level usage is keyed without its model: summary.json can appear or change between
785
+ // runs, and the same event must not count again under the new name.
786
+ const byModel = perModel
787
+ ? Object.entries(usage.modelUsage).map(([raw, u]) => [raw, raw, u])
788
+ : [[summaryModel(), '', usage]];
789
+ for (const [raw, keyModel, u] of byModel) {
790
+ const inputAll = count(u?.inputTokens);
791
+ const cacheRead = Math.min(count(u?.cachedReadTokens), inputAll);
792
+ const cacheWrite = Math.min(count(u?.cacheCreationTokens), inputAll - cacheRead);
793
+ const input = inputAll - cacheRead - cacheWrite;
794
+ const output = count(u?.outputTokens);
795
+ const reasoning = count(u?.reasoningTokens);
796
+ if (!input && !cacheRead && !cacheWrite && !output && !reasoning) continue;
797
+ // Without an eventId, identical rows count once per file, as in ccusage.
798
+ const id = eventId
799
+ ? `${eventId}|${keyModel}`
800
+ : `${path}|${ts}|${raw}|${input}|${output}|${cacheRead}|${cacheWrite}|${reasoning}`;
801
+ const dedupe = `g:${shortHash(id)}`;
802
+ if (state.seen[dedupe] !== undefined) continue;
803
+ state.seen[dedupe] = ts;
804
+ addRecord(state, {
805
+ ts,
806
+ provider: 'grok',
807
+ model: grokModelName(raw),
808
+ // xAI picks the long-context rate per request, and a turn sums several requests, so
809
+ // its total cannot pick a tier. Grok's own costUsdTicks bill such turns at base rate.
810
+ tier: 0,
811
+ session: shortHash(`grok:${session}`),
812
+ input,
813
+ cacheRead,
814
+ cacheWrite5m: cacheWrite,
815
+ cacheWrite1h: 0,
816
+ output
817
+ });
818
+ }
819
+ };
820
+ }
821
+
822
+ // Copilot CLI versions without session.usage_record log usage only in session.shutdown. Like
823
+ // ccusage, a shutdown counts as cumulative per model since the session began, which older
824
+ // versions may not hold to (issue #11). inputTokens includes cache reads and writes.
825
+ // reasoningTokens is part of outputTokens.
826
+ // A bring-your-own-key model can be a cloud resource id or gateway URL, which may carry an
827
+ // account id, so only its last path segment leaves the machine.
828
+ const copilotModelName = (raw) => {
829
+ const name = String(raw ?? '')
830
+ .trim()
831
+ .split(/[?#]/)[0]
832
+ .split('/')
833
+ .pop();
834
+ return (/^arn:/i.test(name) ? name.split(':').pop() : name)
835
+ .replace(/-1m(-internal)?$/, '')
836
+ .replace(/[^A-Za-z0-9._:@-]/g, '-')
837
+ .slice(0, 100);
838
+ };
839
+
840
+ function copilotLineHandler(state, file, resolvePrice, cutoffMs, sessionDir) {
841
+ const session = shortHash(`copilot:${sessionDir}`);
842
+ const count = (u, requests) => ({
843
+ input: num(u?.inputTokens),
844
+ cacheRead: num(u?.cacheReadTokens),
845
+ cacheWrite: num(u?.cacheWriteTokens),
846
+ output: num(u?.outputTokens),
847
+ requests: num(requests)
848
+ });
849
+ const add = (ts, model, t, tier) =>
850
+ addRecord(state, {
851
+ ts,
852
+ provider: 'copilot',
853
+ model,
854
+ tier,
855
+ session,
856
+ input: Math.max(0, t.input - t.cacheRead - t.cacheWrite),
857
+ cacheRead: t.cacheRead,
858
+ cacheWrite5m: t.cacheWrite,
859
+ cacheWrite1h: 0,
860
+ output: t.output
861
+ });
862
+ return (line) => {
863
+ const isCall = line.includes('"session.usage_record"');
864
+ if (!isCall && !line.includes('"session.shutdown"')) return;
865
+ const o = parseJson(line);
866
+ if (!o || o.type !== (isCall ? 'session.usage_record' : 'session.shutdown')) return;
867
+ const ts = Date.parse(o.timestamp);
868
+ if (!Number.isFinite(ts)) return;
869
+ const id = o.id ?? o.timestamp;
870
+ if (isCall) {
871
+ file.callsSinceShutdown = true;
872
+ const model = copilotModelName(o.data?.usage?.model);
873
+ const key = `p:${shortHash(`${sessionDir}:${id}`)}`;
874
+ if (!model || ts < cutoffMs || state.seen[key] !== undefined) return;
875
+ state.seen[key] = ts;
876
+ const t = count(o.data.usage);
877
+ add(ts, model, t, tierFor(resolvePrice('copilot', model), t.input));
878
+ return;
879
+ }
880
+ // Names that normalise to one model (`gpt-5.2` and `gpt-5.2-1m`) are added up before the
881
+ // previous shutdown is subtracted.
882
+ /** @type {Record<string, ReturnType<typeof count>>} */
883
+ const totals = {};
884
+ for (const [rawModel, metrics] of Object.entries(o.data?.modelMetrics ?? {})) {
885
+ const model = copilotModelName(rawModel);
886
+ if (!metrics?.usage || !model) continue;
887
+ const t = count(metrics.usage, metrics.requests?.count);
888
+ const sum = (totals[model] ??= count());
889
+ for (const k of Object.keys(t)) sum[k] += t[k];
890
+ }
891
+ file.models ??= {};
892
+ for (const [model, now] of Object.entries(totals)) {
893
+ const was = file.models[model] ?? {};
894
+ file.models[model] = now;
895
+ const delta = count();
896
+ for (const k of Object.keys(delta)) delta[k] = Math.max(0, now[k] - num(was[k]));
897
+ const key = `p:${shortHash(`${sessionDir}:${id}:${model}`)}`;
898
+ if (
899
+ file.callsSinceShutdown ||
900
+ ts < cutoffMs ||
901
+ !(delta.input || delta.cacheRead || delta.cacheWrite || delta.output) ||
902
+ state.seen[key] !== undefined
903
+ ) {
904
+ continue;
905
+ }
906
+ state.seen[key] = ts;
907
+ // An interval of one request is one prompt, so only then can it reach a long-context tier.
908
+ const tier = delta.requests === 1 ? tierFor(resolvePrice('copilot', model), delta.input) : 0;
909
+ add(ts, model, delta, tier);
910
+ }
911
+ file.callsSinceShutdown = false;
912
+ };
913
+ }
914
+
915
+ const allJsonl = (dir) => walk(dir, (name) => name.endsWith('.jsonl'));
916
+
742
917
  /**
743
- * A reader for JSONL logs that only grow: walks `*.jsonl` under each path and parses only the
744
- * bytes added since the last run. `lines` builds the line handler for one file.
918
+ * A reader for JSONL logs that only grow: reads the files `files` lists under each path (every
919
+ * `*.jsonl` below it by default) and parses only the bytes added since the last run. `lines`
920
+ * builds the line handler for one file.
745
921
  * @param {(ctx: ReadContext, file: FileState, path: string) => (line: string) => void} lines
922
+ * @param {(dir: string) => AsyncIterable<string>} [files]
746
923
  */
747
- const jsonlReader = (lines) => async (paths, ctx, provider) => {
924
+ const jsonlReader = (lines, files) => async (paths, ctx, provider) => {
748
925
  const { state } = ctx;
749
926
  for (const dir of paths) {
750
927
  if (!existsSync(dir)) continue;
751
- for await (const path of walk(dir)) {
928
+ for await (const path of (files ?? allJsonl)(dir)) {
752
929
  if (ctx.seenPaths.has(path)) continue;
753
930
  ctx.seenPaths.add(path);
754
931
  let st;
@@ -800,6 +977,20 @@ async function openSqlite(path) {
800
977
  return mod && new mod.DatabaseSync(path, { readOnly: true });
801
978
  }
802
979
 
980
+ /** Copilot keeps user files in other session subfolders, so only `<session>/events.jsonl` counts. */
981
+ async function* sessionEvents(dir) {
982
+ let entries;
983
+ try {
984
+ entries = await readdir(dir, { withFileTypes: true });
985
+ } catch {
986
+ return;
987
+ }
988
+ for (const e of entries) {
989
+ const p = join(dir, e.name, 'events.jsonl');
990
+ if (e.isDirectory() && existsSync(p)) yield p;
991
+ }
992
+ }
993
+
803
994
  const fromEnv = (name, ...rest) => (process.env[name] ? [join(process.env[name], ...rest)] : []);
804
995
 
805
996
  /**
@@ -867,6 +1058,38 @@ const SOURCES = {
867
1058
  )
868
1059
  ];
869
1060
  }
1061
+ },
1062
+ grok: {
1063
+ paths: [join(HOME, '.grok', 'sessions')],
1064
+ envPaths: () => fromEnv('GROK_HOME', 'sessions'),
1065
+ read: jsonlReader(
1066
+ (ctx, _file, path) => grokLineHandler(ctx.state, ctx.cutoffMs, path),
1067
+ (dir) => walk(dir, (name) => name === 'updates.jsonl')
1068
+ ),
1069
+ // Grok Build logs `grok-4.5-build`; LiteLLM prices it as `xai/grok-4.5`.
1070
+ priceKeys: (model) =>
1071
+ [model, model.replace(/-build$/, '')].flatMap((base) => [base, `xai/${base}`])
1072
+ },
1073
+ copilot: {
1074
+ paths: [join(HOME, '.copilot', 'session-state')],
1075
+ envPaths: () => fromEnv('COPILOT_HOME', 'session-state'),
1076
+ read: jsonlReader(
1077
+ (ctx, file, path) =>
1078
+ copilotLineHandler(
1079
+ ctx.state,
1080
+ file,
1081
+ ctx.resolvePrice,
1082
+ ctx.cutoffMs,
1083
+ basename(dirname(path))
1084
+ ),
1085
+ sessionEvents
1086
+ ),
1087
+ priceKeys: (model) => {
1088
+ const claude = model.startsWith('claude-');
1089
+ const name = claude ? model.replace(/(\d)\.(\d)/g, '$1-$2') : model;
1090
+ const prefix = claude ? 'anthropic' : model.startsWith('gemini-') ? 'gemini' : 'openai';
1091
+ return [...new Set([...litellmKeys(prefix)(name), `github_copilot/${model}`])];
1092
+ }
870
1093
  }
871
1094
  };
872
1095
 
package/dist/schema.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare const EARLIEST_DATE = "2020-01-01T00:00:00Z";
3
3
  export declare const MAX_ROWS = 50000;
4
4
  export declare const DEVICE_ID: RegExp;
5
5
  export declare const CURSOR_DEVICE_ID = "cursor";
6
- export declare const PROVIDERS: readonly ['claude', 'codex', 'cursor', 'pi'];
6
+ export declare const PROVIDERS: readonly ['claude', 'codex', 'cursor', 'pi', 'grok', 'copilot'];
7
7
  export declare const RANGES: readonly ['7d', '30d', '90d', 'all'];
8
8
  export declare const usageRowSchema: z.ZodObject<{
9
9
  hour: z.ZodISODateTime;
@@ -14,7 +14,9 @@ export declare const usageRowSchema: z.ZodObject<{
14
14
  provider: z.ZodEnum<{
15
15
  claude: "claude";
16
16
  codex: "codex";
17
+ copilot: "copilot";
17
18
  cursor: "cursor";
19
+ grok: "grok";
18
20
  pi: "pi";
19
21
  }>;
20
22
  model: z.ZodString;
@@ -37,7 +39,9 @@ export declare const limitWindowSchema: z.ZodObject<{
37
39
  provider: z.ZodEnum<{
38
40
  claude: "claude";
39
41
  codex: "codex";
42
+ copilot: "copilot";
40
43
  cursor: "cursor";
44
+ grok: "grok";
41
45
  pi: "pi";
42
46
  }>;
43
47
  window: z.ZodString;
@@ -60,7 +64,9 @@ export declare const usageSnapshotSchema: z.ZodObject<{
60
64
  provider: z.ZodEnum<{
61
65
  claude: "claude";
62
66
  codex: "codex";
67
+ copilot: "copilot";
63
68
  cursor: "cursor";
69
+ grok: "grok";
64
70
  pi: "pi";
65
71
  }>;
66
72
  model: z.ZodString;
@@ -84,28 +90,36 @@ export declare const usageSnapshotSchema: z.ZodObject<{
84
90
  claude: z.ZodNumber;
85
91
  codex: z.ZodNumber;
86
92
  all: z.ZodNumber;
93
+ copilot: z.ZodOptional<z.ZodNumber>;
87
94
  cursor: z.ZodOptional<z.ZodNumber>;
95
+ grok: z.ZodOptional<z.ZodNumber>;
88
96
  pi: z.ZodOptional<z.ZodNumber>;
89
97
  }, z.core.$strict>>;
90
98
  '7d': z.ZodObject<{
91
99
  claude: z.ZodNumber;
92
100
  codex: z.ZodNumber;
93
101
  all: z.ZodNumber;
102
+ copilot: z.ZodOptional<z.ZodNumber>;
94
103
  cursor: z.ZodOptional<z.ZodNumber>;
104
+ grok: z.ZodOptional<z.ZodNumber>;
95
105
  pi: z.ZodOptional<z.ZodNumber>;
96
106
  }, z.core.$strict>;
97
107
  '30d': z.ZodObject<{
98
108
  claude: z.ZodNumber;
99
109
  codex: z.ZodNumber;
100
110
  all: z.ZodNumber;
111
+ copilot: z.ZodOptional<z.ZodNumber>;
101
112
  cursor: z.ZodOptional<z.ZodNumber>;
113
+ grok: z.ZodOptional<z.ZodNumber>;
102
114
  pi: z.ZodOptional<z.ZodNumber>;
103
115
  }, z.core.$strict>;
104
116
  '90d': z.ZodObject<{
105
117
  claude: z.ZodNumber;
106
118
  codex: z.ZodNumber;
107
119
  all: z.ZodNumber;
120
+ copilot: z.ZodOptional<z.ZodNumber>;
108
121
  cursor: z.ZodOptional<z.ZodNumber>;
122
+ grok: z.ZodOptional<z.ZodNumber>;
109
123
  pi: z.ZodOptional<z.ZodNumber>;
110
124
  }, z.core.$strict>;
111
125
  }, z.core.$strict>>;
@@ -113,7 +127,9 @@ export declare const usageSnapshotSchema: z.ZodObject<{
113
127
  provider: z.ZodEnum<{
114
128
  claude: "claude";
115
129
  codex: "codex";
130
+ copilot: "copilot";
116
131
  cursor: "cursor";
132
+ grok: "grok";
117
133
  pi: "pi";
118
134
  }>;
119
135
  window: z.ZodString;
package/dist/schema.js CHANGED
@@ -14,7 +14,7 @@ export const MAX_ROWS = 50_000;
14
14
  export const DEVICE_ID = /^[a-z0-9][a-z0-9-]{0,31}$/;
15
15
  // Collectors send the Cursor account's usage under this id, so no machine may use it.
16
16
  export const CURSOR_DEVICE_ID = 'cursor';
17
- export const PROVIDERS = ['claude', 'codex', 'cursor', 'pi'];
17
+ export const PROVIDERS = ['claude', 'codex', 'cursor', 'pi', 'grok', 'copilot'];
18
18
  // Public ranges. 7d, 30d and 90d are bucketed by UTC day, `all` by ISO week. Nothing is finer
19
19
  // than a day: an hourly view would show when each machine is in use.
20
20
  export const RANGES = ['7d', '30d', '90d', 'all'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "big-spender",
3
- "version": "0.6.0",
3
+ "version": "0.8.0",
4
4
  "description": "Track what your AI coding agents would cost at API prices, across all your machines.",
5
5
  "keywords": [
6
6
  "ai",