@virling/subagents 0.2.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project are documented here. The format follows [Kee
4
4
 
5
5
  ## [Unreleased]
6
6
 
7
+ ## [0.3.0] - 2026-11-28
8
+
9
+ ### Added
10
+
11
+ - Estimated cost at API prices for each subagent and in the total (`costUsd` in `--json`), from per-model prices for Opus 5.5, Opus 5, Sonnet 5.5 and Haiku 5.5, with 1-hour cache writes at 2x input and 5-minute writes at 1.25x. Subagents on other models show no cost.
12
+
7
13
  ## [0.2.0] - 2026-11-28
8
14
 
9
15
  ### Added
@@ -24,7 +30,8 @@ All notable changes to this project are documented here. The format follows [Kee
24
30
  - Flags overlapping reads, repeated commands, error-heavy subagents, edit collisions and empty results.
25
31
  - Pick a session with `--session`, a file path or `--project`; `--list` shows recent sessions; `--json` output.
26
32
 
27
- [Unreleased]: https://github.com/virling/subagents/compare/v0.2.0...HEAD
33
+ [Unreleased]: https://github.com/virling/subagents/compare/v0.3.0...HEAD
34
+ [0.3.0]: https://github.com/virling/subagents/compare/v0.2.0...v0.3.0
28
35
  [0.2.0]: https://github.com/virling/subagents/compare/v0.1.1...v0.2.0
29
36
  [0.1.1]: https://github.com/virling/subagents/compare/v0.1.0...v0.1.1
30
37
  [0.1.0]: https://github.com/virling/subagents/releases/tag/v0.1.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virling/subagents",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Review what Claude Code subagents did in a session and flag repeated or wasted work",
5
5
  "type": "module",
6
6
  "bin": {
package/src/analyze.js CHANGED
@@ -30,6 +30,22 @@ export function launches(main) {
30
30
  return { byAgent, reads };
31
31
  }
32
32
 
33
+ // USD per million tokens (input, output, cache read); cache writes are 1.25x input for 5m and 2x for 1h.
34
+ const PRICES = {
35
+ "claude-opus-5-5": [4, 20, 0.2],
36
+ "claude-opus-5": [5, 25, 0.5],
37
+ "claude-sonnet-5-5": [2, 10, 0.1],
38
+ "claude-haiku-5-5": [0.1, 0.5, 0.01],
39
+ };
40
+
41
+ export function cost(u, model) {
42
+ const p = PRICES[model];
43
+ if (!p) return null;
44
+ const write1h = u.cache_creation?.ephemeral_1h_input_tokens || 0;
45
+ const write5m = (u.cache_creation_input_tokens || 0) - write1h;
46
+ return ((u.input_tokens || 0) * p[0] + (u.output_tokens || 0) * p[1] + (u.cache_read_input_tokens || 0) * p[2] + write5m * p[0] * 1.25 + write1h * p[0] * 2) / 1e6;
47
+ }
48
+
33
49
  export function summarizeAgent(id, entries, input) {
34
50
  const tools = {};
35
51
  const read = new Set();
@@ -64,7 +80,7 @@ export function summarizeAgent(id, entries, input) {
64
80
  prev = t;
65
81
  }
66
82
  if (role === "user" && !first) first = text(content).trim();
67
- if (role === "assistant" && e.message.usage) usage.set(e.message.id || e.uuid, e.message.usage);
83
+ if (role === "assistant" && e.message.usage) usage.set(e.message.id || e.uuid, { ...e.message.usage, model: e.message.model });
68
84
  for (const c of blocks(content)) {
69
85
  if (c.type === "tool_result" && c.is_error) failed++;
70
86
  if (role !== "assistant") continue;
@@ -92,6 +108,8 @@ export function summarizeAgent(id, entries, input) {
92
108
  tokens.cacheCreation += u.cache_creation_input_tokens || 0;
93
109
  }
94
110
  if (tokens) tokens.total = tokens.input + tokens.output + tokens.cacheRead + tokens.cacheCreation;
111
+ const costs = [...usage.values()].map((u) => cost(u, u.model));
112
+ const costUsd = costs.length && costs.every((c) => c !== null) ? costs.reduce((a, b) => a + b, 0) : null;
95
113
  return {
96
114
  id,
97
115
  description: truncate((input?.description || first || "").replace(/\s+/g, " ").trim()),
@@ -108,6 +126,7 @@ export function summarizeAgent(id, entries, input) {
108
126
  commands: [...commands],
109
127
  reportChars: report.trim().length,
110
128
  tokens,
129
+ costUsd,
111
130
  };
112
131
  }
113
132
 
@@ -206,6 +225,7 @@ export function analyze({ main, agents }) {
206
225
  waitMs: summaries.reduce((s, a) => s + a.waitMs, 0),
207
226
  toolCalls: summaries.reduce((s, a) => s + a.toolCalls, 0),
208
227
  tokens: known.length ? known.reduce((s, a) => s + a.tokens.total, 0) : null,
228
+ costUsd: summaries.some((a) => a.costUsd !== null) ? summaries.reduce((s, a) => s + (a.costUsd || 0), 0) : null,
209
229
  },
210
230
  };
211
231
  }
package/src/format.js CHANGED
@@ -26,7 +26,7 @@ export function formatReport(report, cwd = "") {
26
26
  .map(([name, n]) => `${name} ${n}`)
27
27
  .join(", ");
28
28
  lines.push(`#${a.n} ${a.id} ${a.description || "(no description)"}`);
29
- lines.push(` ${time(a.start)} -> ${time(a.end)} ${duration(a.durationMs)} report ${count(a.reportChars)} chars${a.tokens ? ` tokens ${count(a.tokens.total)}` : ""}${a.waitMs ? ` waited ${duration(a.waitMs)} for approval` : ""}`);
29
+ lines.push(` ${time(a.start)} -> ${time(a.end)} ${duration(a.durationMs)} report ${count(a.reportChars)} chars${a.tokens ? ` tokens ${count(a.tokens.total)}` : ""}${a.costUsd === null ? "" : ` ~$${a.costUsd.toFixed(2)}`}${a.waitMs ? ` waited ${duration(a.waitMs)} for approval` : ""}`);
30
30
  lines.push(` tools ${a.toolCalls}${tools ? ` (${tools})` : ""}${a.failed ? ` failed ${a.failed}` : ""}`);
31
31
  if (a.read.length) lines.push(` read ${a.read.map(rel).join(", ")}`);
32
32
  if (a.edited.length) lines.push(` edited ${a.edited.map(rel).join(", ")}`);
@@ -46,7 +46,7 @@ export function formatReport(report, cwd = "") {
46
46
  const t = report.totals;
47
47
  lines.push("");
48
48
  lines.push(
49
- `Total: ${t.subagents} subagents, ${duration(t.durationMs)}, ${t.toolCalls} tool calls${t.tokens === null ? "" : `, ${count(t.tokens)} tokens`}`
49
+ `Total: ${t.subagents} subagents, ${duration(t.durationMs)}, ${t.toolCalls} tool calls${t.tokens === null ? "" : `, ${count(t.tokens)} tokens`}${t.costUsd == null ? "" : `, ~$${t.costUsd.toFixed(2)} at API prices`}`
50
50
  );
51
51
  return lines.join("\n");
52
52
  }