tokmax 0.2.0 → 0.4.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/bin/tokmax.mjs CHANGED
@@ -394,6 +394,7 @@ async function main() {
394
394
  machineLabel: opts.machine,
395
395
  models: agg.models,
396
396
  daily: agg.daily,
397
+ ...(opts.subscriptionUsd ? { subscriptionUsd: opts.subscriptionUsd } : {}),
397
398
  };
398
399
 
399
400
  if (opts.dryRun) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokmax",
3
- "version": "0.2.0",
3
+ "version": "0.4.0",
4
4
  "description": "Scan your local Codex + Claude Code logs, aggregate per-model token usage, and publish the API-equivalent $ to the tokenmax leaderboard (tokenmax.ru). Aggregates only — never your prompts, files, or keys.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -40,6 +40,12 @@ async function claudeProjectRoots() {
40
40
  export async function scanClaudeCode() {
41
41
  const records = [];
42
42
  let sessionCount = 0;
43
+ // Dedup assistant turns by message.id: Claude Code resume/branch/continue
44
+ // replays prior turns (with their original usage) into new session files, so
45
+ // summing every file's assistant lines double-counts. message.id is unique per
46
+ // API response, so one id == one billed turn no matter how many files replay it.
47
+ const seenIds = new Set();
48
+ let duplicates = 0;
43
49
 
44
50
  for (const root of await claudeProjectRoots()) {
45
51
  for await (const file of walkJsonl(root)) {
@@ -68,6 +74,15 @@ export async function scanClaudeCode() {
68
74
  const date = isoDay(d.timestamp);
69
75
  if (!date) continue;
70
76
 
77
+ const id = msg.id;
78
+ if (id) {
79
+ if (seenIds.has(id)) {
80
+ duplicates++;
81
+ continue; // already counted this billed turn (replayed in another file)
82
+ }
83
+ seenIds.add(id);
84
+ }
85
+
71
86
  records.push({
72
87
  tool: 'claude-code',
73
88
  model,
@@ -82,5 +97,5 @@ export async function scanClaudeCode() {
82
97
  }
83
98
  }
84
99
 
85
- return { tool: 'claude-code', sessionCount, records };
100
+ return { tool: 'claude-code', sessionCount, records, duplicates };
86
101
  }