@virling/subagents 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses [Semantic Versioning](https://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.1.1] - 2026-11-28
8
+
9
+ ### Fixed
10
+
11
+ - Time no longer includes waiting for a person to approve a tool call, which could inflate a subagent from minutes to hours.
12
+
13
+ ## [0.1.0] - 2026-11-27
14
+
15
+ ### Added
16
+
17
+ - `subagents` summarizes each subagent of a Claude Code session: description, active time, tool calls, files read and edited, failed calls, report length and tokens.
18
+ - Flags overlapping reads, repeated commands, error-heavy subagents, edit collisions and empty results.
19
+ - Pick a session with `--session`, a file path or `--project`; `--list` shows recent sessions; `--json` output.
20
+
21
+ [Unreleased]: https://github.com/virling/subagents/compare/v0.1.1...HEAD
22
+ [0.1.1]: https://github.com/virling/subagents/compare/v0.1.0...v0.1.1
23
+ [0.1.0]: https://github.com/virling/subagents/releases/tag/v0.1.0
package/LICENSE ADDED
@@ -0,0 +1,75 @@
1
+ # PolyForm Noncommercial License 1.0.0
2
+
3
+ <https://polyformproject.org/licenses/noncommercial/1.0.0>
4
+
5
+ ## Acceptance
6
+
7
+ In order to get any license under these terms, you must agree to them as both strict obligations and conditions to all your licenses.
8
+
9
+ ## Copyright License
10
+
11
+ The licensor grants you a copyright license for the software to do everything you might do with the software that would otherwise infringe the licensor's copyright in it for any permitted purpose. However, you may only distribute the software according to [Distribution License](#distribution-license) and make changes or new works based on the software according to [Changes and New Works License](#changes-and-new-works-license).
12
+
13
+ ## Distribution License
14
+
15
+ The licensor grants you an additional copyright license to distribute copies of the software. Your license to distribute covers distributing the software with changes and new works permitted by [Changes and New Works License](#changes-and-new-works-license).
16
+
17
+ ## Notices
18
+
19
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms or the URL for them above, as well as copies of any plain-text lines beginning with `Required Notice:` that the licensor provided with the software. For example:
20
+
21
+ > Required Notice: Copyright Yoyodyne, Inc. (http://example.com)
22
+
23
+ ## Changes and New Works License
24
+
25
+ The licensor grants you an additional copyright license to make changes and new works based on the software for any permitted purpose.
26
+
27
+ ## Patent License
28
+
29
+ The licensor grants you a patent license for the software that covers patent claims the licensor can license, or becomes able to license, that you would infringe by using the software.
30
+
31
+ ## Noncommercial Purposes
32
+
33
+ Any noncommercial purpose is a permitted purpose.
34
+
35
+ ## Personal Uses
36
+
37
+ Personal use for research, experiment, and testing for the benefit of public knowledge, personal study, private entertainment, hobby projects, amateur pursuits, or religious observance, without any anticipated commercial application, is use for a permitted purpose.
38
+
39
+ ## Noncommercial Organizations
40
+
41
+ Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is use for a permitted purpose regardless of the source of funding or obligations resulting from the funding.
42
+
43
+ ## Fair Use
44
+
45
+ You may have "fair use" rights for the software under the law. These terms do not limit them.
46
+
47
+ ## No Other Rights
48
+
49
+ These terms do not allow you to sublicense or transfer any of your licenses to anyone else, or prevent the licensor from granting licenses to anyone else. These terms do not imply any other licenses.
50
+
51
+ ## Patent Defense
52
+
53
+ If you make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
54
+
55
+ ## Violations
56
+
57
+ The first time you are notified in writing that you have violated any of these terms, or done anything with the software not covered by your licenses, your licenses can nonetheless continue if you come into full compliance with these terms, and take practical steps to correct past violations, within 32 days of receiving notice. Otherwise, all your licenses end immediately.
58
+
59
+ ## No Liability
60
+
61
+ ***As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.***
62
+
63
+ ## Definitions
64
+
65
+ The **licensor** is the individual or entity offering these terms, and the **software** is the software the licensor makes available under these terms.
66
+
67
+ **You** refers to the individual or entity agreeing to these terms.
68
+
69
+ **Your company** is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. **Control** means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
70
+
71
+ **Your licenses** are all the licenses granted to you for the software under these terms.
72
+
73
+ **Use** means anything you do with the software requiring one of your licenses.
74
+
75
+ Required Notice: Copyright 2026 Virling (https://github.com/virling)
package/README.md CHANGED
@@ -1,3 +1,89 @@
1
- # Temporary Holding Version
1
+ # subagents
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Review what Claude Code subagents actually did in a session: what each one ran, read and edited, how long it took, and where work was repeated or wasted. Zero dependencies, reads your local transcripts, sends nothing anywhere.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js 20 or newer
8
+ - Claude Code sessions on this machine (`~/.claude/projects`, or `$CLAUDE_CONFIG_DIR/projects`)
9
+
10
+ ## Usage
11
+
12
+ ```bash
13
+ npx -y @virling/subagents
14
+ ```
15
+
16
+ ```
17
+ subagents latest session with subagents for the project in this folder
18
+ subagents <session.jsonl> a specific transcript file
19
+ subagents --session <id> a session of the project by id
20
+ subagents --project <path> use another project folder instead of this one
21
+ subagents --list recent sessions with subagent counts
22
+ subagents --json print the report as JSON
23
+ subagents --help
24
+ ```
25
+
26
+ ## Example
27
+
28
+ ```
29
+ Session 3f1c9a2e-0b7d-4c55-9e61-2a8d4f6b1c07
30
+
31
+ #1 a91f0c2d7e3b4a5c6 Map the billing module
32
+ 11-26 14:02 -> 11-26 14:06 4m 12s report 2.1k chars tokens 412.5k
33
+ tools 18 (Read 11, Grep 5, Bash 2)
34
+ read src/billing/invoice.js, src/billing/tax.js, src/db.js
35
+
36
+ #2 b27d4e8a1c9f0b3d2 Find why invoice totals are off
37
+ 11-26 14:02 -> 11-26 14:09 7m 40s report 140 chars tokens 655.0k
38
+ tools 26 (Bash 12, Read 9, Edit 5) failed 9
39
+ read src/billing/invoice.js, src/billing/round.js
40
+ edited src/billing/round.js
41
+
42
+ #3 c5e0a3f9b2d7c1e84 Add tests for rounding
43
+ 11-26 14:10 -> 11-26 14:13 3m 5s report 820 chars tokens 301.2k
44
+ tools 12 (Bash 6, Edit 4, Read 2)
45
+ read src/billing/round.js
46
+ edited src/billing/round.js, test/round.test.js
47
+
48
+ Flags
49
+ overlap: src/billing/invoice.js read by #1, #2
50
+ overlap: src/billing/round.js read by #2, #3
51
+ overlap: src/db.js read again by the main session after #1 finished
52
+ repeated-command: `npm test -- billing` run in #2, #3
53
+ error-heavy: #2 9/26 tool calls failed (35%)
54
+ edit-collision: src/billing/round.js edited by #2, #3
55
+ empty-result: #2 final report is 140 chars (under 200)
56
+
57
+ Total: 3 subagents, 14m 57s, 56 tool calls, 1.4M tokens
58
+ ```
59
+
60
+ ## What is measured
61
+
62
+ Each subagent transcript lives at `~/.claude/projects/<project>/<session>/subagents/agent-<id>.jsonl`. The description comes from the `Agent` (or older `Task`) tool call in the main session, or else the subagent's first message.
63
+
64
+ - **Time**: active time in the subagent transcript. When a subagent is continued later with a follow-up message, the idle gap before that message is not counted. Time spent waiting for a person to approve a tool call is not counted either. A long-running tool, such as a slow Bash command, still counts.
65
+ - **Tool calls**: every `tool_use`, grouped by tool name. **Failed** counts `tool_result` entries with `is_error`.
66
+ - **Read / edited**: file paths from `Read`, and from `Edit`, `Write`, `MultiEdit` and `NotebookEdit`.
67
+ - **Report**: characters of the subagent's last text after its last tool call.
68
+ - **Tokens**: input, output and cache tokens from `message.usage`, counted once per API message.
69
+
70
+ ## Flags
71
+
72
+ - **overlap**: the same file read by 2+ subagents, or read by the main session after a subagent that read it had finished.
73
+ - **repeated-command**: the same Bash command (whitespace collapsed) run in 2+ subagents.
74
+ - **error-heavy**: more than 30% of a subagent's tool calls failed.
75
+ - **edit-collision**: the same file edited by 2+ subagents.
76
+ - **empty-result**: the final report is under 200 characters.
77
+
78
+ Flags are hints, not verdicts: two subagents reading the same file is often fine.
79
+
80
+ ## More tools from Virling
81
+
82
+ - [agentmem](https://github.com/virling/agentmem): project memory for AI coding agents, shared across Claude Code, Cursor, Codex and other MCP clients.
83
+ - [ccdoctor](https://github.com/virling/ccdoctor): checks your Claude Code setup: hooks, MCP servers and plugins that are registered but not working.
84
+ - [ciwhy](https://github.com/virling/ciwhy): finds the real error in a failed GitHub Actions run and tells you if it is flaky.
85
+ - [npmship](https://github.com/virling/npmship): releases an npm package and verifies it landed on npm, in CI and on GitHub.
86
+
87
+ ## License
88
+
89
+ [PolyForm Noncommercial 1.0.0](LICENSE)
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { analyze } from "../src/analyze.js";
5
+ import { formatReport } from "../src/format.js";
6
+ import { defaultBase, listSessions, loadSession, projectDir } from "../src/sessions.js";
7
+
8
+ const HELP = `subagents: review what Claude Code subagents did in a session
9
+
10
+ subagents latest session with subagents for the project in this folder
11
+ subagents <session.jsonl> a specific transcript file
12
+ subagents --session <id> a session of the project by id
13
+ subagents --project <path> use another project folder instead of this one
14
+ subagents --list recent sessions with subagent counts
15
+ subagents --json print the report as JSON
16
+ subagents --help
17
+
18
+ Transcripts are read from $CLAUDE_CONFIG_DIR/projects or ~/.claude/projects.`;
19
+
20
+ const BOOLEAN_FLAGS = ["list", "json", "help"];
21
+
22
+ function parseArgs(argv) {
23
+ const positional = [];
24
+ const flags = {};
25
+ for (let i = 0; i < argv.length; i++) {
26
+ if (!argv[i].startsWith("--")) positional.push(argv[i]);
27
+ else if (BOOLEAN_FLAGS.includes(argv[i].slice(2))) flags[argv[i].slice(2)] = true;
28
+ else flags[argv[i].slice(2)] = argv[++i];
29
+ }
30
+ return { positional, flags };
31
+ }
32
+
33
+ function main() {
34
+ const { positional, flags } = parseArgs(process.argv.slice(2));
35
+ if (flags.help) return console.log(HELP);
36
+ const dir = projectDir(defaultBase(), flags.project || process.cwd());
37
+ const sessions = listSessions(dir);
38
+ if (flags.list) {
39
+ if (!sessions.length) return console.log(`No sessions in ${dir}`);
40
+ const rows = sessions.slice(0, 20).map((s) => `${s.mtime.toLocaleString("sv").slice(0, 16)} ${String(s.subagents).padStart(3)} subagents ${s.id}`);
41
+ return console.log(rows.join("\n"));
42
+ }
43
+ let file = positional[0] && path.resolve(positional[0]);
44
+ if (!file && flags.session) file = path.join(dir, `${flags.session}.jsonl`);
45
+ if (!file) file = sessions.find((s) => s.subagents)?.file;
46
+ if (!file || !fs.existsSync(file)) {
47
+ console.error(file ? `No such session: ${file}` : `No session with subagents in ${dir}`);
48
+ process.exitCode = 1;
49
+ return;
50
+ }
51
+ const session = loadSession(file);
52
+ const report = analyze(session);
53
+ if (flags.json) return console.log(JSON.stringify({ session: session.id, file, ...report }, null, 2));
54
+ if (!report.agents.length) return console.log(`Session ${session.id} has no subagents.`);
55
+ const cwd = session.main.find((e) => e.cwd)?.cwd;
56
+ console.log(`Session ${session.id}\n`);
57
+ console.log(formatReport(report, cwd));
58
+ }
59
+
60
+ main();
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@virling/subagents",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "Review what Claude Code subagents did in a session and flag repeated or wasted work",
5
+ "type": "module",
6
+ "bin": {
7
+ "subagents": "bin/subagents.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node --test"
11
+ },
12
+ "engines": {
13
+ "node": ">=20"
14
+ },
15
+ "license": "PolyForm-Noncommercial-1.0.0",
16
+ "keywords": [
17
+ "claude-code",
18
+ "subagents",
19
+ "ai-agents",
20
+ "transcripts",
21
+ "cli"
22
+ ],
23
+ "files": [
24
+ "bin",
25
+ "src",
26
+ "README.md",
27
+ "LICENSE",
28
+ "CHANGELOG.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "repository": {
34
+ "type": "git",
35
+ "url": "git+https://github.com/virling/subagents.git"
36
+ },
37
+ "homepage": "https://github.com/virling/subagents#readme",
38
+ "bugs": {
39
+ "url": "https://github.com/virling/subagents/issues"
40
+ }
41
+ }
package/src/analyze.js ADDED
@@ -0,0 +1,147 @@
1
+ const AGENT_TOOLS = ["Agent", "Task"];
2
+ const EDIT_TOOLS = ["Edit", "Write", "MultiEdit", "NotebookEdit"];
3
+ export const EMPTY_REPORT_CHARS = 200;
4
+ export const ERROR_RATE = 0.3;
5
+
6
+ const text = (content) =>
7
+ typeof content === "string" ? content : (content || []).filter((c) => c.type === "text").map((c) => c.text).join("\n");
8
+ const blocks = (content) => (Array.isArray(content) ? content : []);
9
+ const turns = (entries) => entries.filter((e) => (e.type === "user" || e.type === "assistant") && e.message);
10
+ const fileOf = (input) => input?.file_path || input?.notebook_path;
11
+ export const normalizeCommand = (cmd) => cmd.trim().replace(/\s+/g, " ");
12
+ const truncate = (s, n = 80) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
13
+
14
+ export function launches(main) {
15
+ const inputs = new Map();
16
+ const byAgent = new Map();
17
+ const reads = [];
18
+ for (const e of turns(main)) {
19
+ for (const c of blocks(e.message.content)) {
20
+ if (c.type === "tool_use" && AGENT_TOOLS.includes(c.name)) inputs.set(c.id, c.input || {});
21
+ if (c.type === "tool_use" && c.name === "Read" && fileOf(c.input) && e.timestamp) reads.push({ file: fileOf(c.input), time: e.timestamp });
22
+ const agentId = e.toolUseResult?.agentId;
23
+ if (c.type === "tool_result" && agentId && inputs.has(c.tool_use_id)) byAgent.set(agentId, inputs.get(c.tool_use_id));
24
+ }
25
+ }
26
+ return { byAgent, reads };
27
+ }
28
+
29
+ export function summarizeAgent(id, entries, input) {
30
+ const tools = {};
31
+ const read = new Set();
32
+ const edited = new Set();
33
+ const commands = new Set();
34
+ const usage = new Map();
35
+ let calls = 0;
36
+ let failed = 0;
37
+ let report = "";
38
+ let first = "";
39
+ const times = [];
40
+ let active = 0;
41
+ let prev = null;
42
+ for (const e of turns(entries)) {
43
+ const { role, content } = e.message;
44
+ if (e.timestamp) {
45
+ times.push(e.timestamp);
46
+ const t = Date.parse(e.timestamp);
47
+ // A new prompt after a pause is a later continuation, and a tool call a person approved waited on them, so both gaps are idle time.
48
+ const prompt = role === "user" && text(content).trim() && !blocks(content).some((c) => c.type === "tool_result");
49
+ const approved = role === "user" && e.permissionDecision?.source?.startsWith("user");
50
+ if (prev !== null && !prompt && !approved) active += t - prev;
51
+ prev = t;
52
+ }
53
+ if (role === "user" && !first) first = text(content).trim();
54
+ if (role === "assistant" && e.message.usage) usage.set(e.message.id || e.uuid, e.message.usage);
55
+ for (const c of blocks(content)) {
56
+ if (c.type === "tool_result" && c.is_error) failed++;
57
+ if (role !== "assistant") continue;
58
+ if (c.type === "text") report += `${c.text}\n`;
59
+ if (c.type !== "tool_use") continue;
60
+ report = "";
61
+ calls++;
62
+ tools[c.name] = (tools[c.name] || 0) + 1;
63
+ const file = fileOf(c.input);
64
+ if (file && c.name === "Read") read.add(file);
65
+ if (file && EDIT_TOOLS.includes(c.name)) edited.add(file);
66
+ if (c.name === "Bash" && c.input?.command) commands.add(normalizeCommand(c.input.command));
67
+ }
68
+ }
69
+ times.sort();
70
+ const start = times[0] || null;
71
+ const end = times.at(-1) || null;
72
+ let tokens = null;
73
+ for (const u of usage.values()) {
74
+ tokens ||= { input: 0, output: 0, cacheRead: 0, cacheCreation: 0, total: 0 };
75
+ tokens.input += u.input_tokens || 0;
76
+ tokens.output += u.output_tokens || 0;
77
+ tokens.cacheRead += u.cache_read_input_tokens || 0;
78
+ tokens.cacheCreation += u.cache_creation_input_tokens || 0;
79
+ }
80
+ if (tokens) tokens.total = tokens.input + tokens.output + tokens.cacheRead + tokens.cacheCreation;
81
+ return {
82
+ id,
83
+ description: truncate((input?.description || first || "").replace(/\s+/g, " ").trim()),
84
+ start,
85
+ end,
86
+ durationMs: active,
87
+ toolCalls: calls,
88
+ tools,
89
+ failed,
90
+ read: [...read],
91
+ edited: [...edited],
92
+ commands: [...commands],
93
+ reportChars: report.trim().length,
94
+ tokens,
95
+ };
96
+ }
97
+
98
+ function groupBy(agents, key) {
99
+ const groups = new Map();
100
+ for (const a of agents) for (const v of a[key]) groups.set(v, [...(groups.get(v) || []), a.n]);
101
+ return [...groups].filter(([, ns]) => ns.length > 1);
102
+ }
103
+
104
+ export function findFlags(agents, mainReads = []) {
105
+ const flags = [];
106
+ const list = (ns) => ns.map((n) => `#${n}`).join(", ");
107
+ for (const [file, ns] of groupBy(agents, "read")) flags.push({ type: "overlap", file, agents: ns, text: `${file} read by ${list(ns)}` });
108
+ const reread = new Map();
109
+ for (const r of mainReads) {
110
+ for (const a of agents) if (a.end && r.time > a.end && a.read.includes(r.file)) reread.set(r.file, new Set([...(reread.get(r.file) || []), a.n]));
111
+ }
112
+ for (const [file, set] of reread) {
113
+ const ns = [...set].sort((x, y) => x - y);
114
+ flags.push({ type: "overlap", file, agents: ns, main: true, text: `${file} read again by the main session after ${list(ns)} finished` });
115
+ }
116
+ for (const [command, ns] of groupBy(agents, "commands"))
117
+ flags.push({ type: "repeated-command", command, agents: ns, text: `\`${truncate(command)}\` run in ${list(ns)}` });
118
+ for (const a of agents) {
119
+ if (a.toolCalls && a.failed / a.toolCalls > ERROR_RATE)
120
+ flags.push({ type: "error-heavy", agents: [a.n], text: `#${a.n} ${a.failed}/${a.toolCalls} tool calls failed (${Math.round((a.failed / a.toolCalls) * 100)}%)` });
121
+ }
122
+ for (const [file, ns] of groupBy(agents, "edited")) flags.push({ type: "edit-collision", file, agents: ns, text: `${file} edited by ${list(ns)}` });
123
+ for (const a of agents) {
124
+ if (a.reportChars < EMPTY_REPORT_CHARS)
125
+ flags.push({ type: "empty-result", agents: [a.n], text: `#${a.n} final report is ${a.reportChars} chars (under ${EMPTY_REPORT_CHARS})` });
126
+ }
127
+ return flags;
128
+ }
129
+
130
+ export function analyze({ main, agents }) {
131
+ const { byAgent, reads } = launches(main);
132
+ const summaries = agents
133
+ .map((a) => summarizeAgent(a.id, a.entries, byAgent.get(a.id)))
134
+ .sort((a, b) => (a.start || "").localeCompare(b.start || ""))
135
+ .map((a, i) => ({ n: i + 1, ...a }));
136
+ const known = summaries.filter((a) => a.tokens);
137
+ return {
138
+ agents: summaries,
139
+ flags: findFlags(summaries, reads),
140
+ totals: {
141
+ subagents: summaries.length,
142
+ durationMs: summaries.reduce((s, a) => s + a.durationMs, 0),
143
+ toolCalls: summaries.reduce((s, a) => s + a.toolCalls, 0),
144
+ tokens: known.length ? known.reduce((s, a) => s + a.tokens.total, 0) : null,
145
+ },
146
+ };
147
+ }
package/src/format.js ADDED
@@ -0,0 +1,42 @@
1
+ import path from "node:path";
2
+
3
+ export function duration(ms) {
4
+ const s = Math.round(ms / 1000);
5
+ if (s < 60) return `${s}s`;
6
+ if (s < 3600) return `${Math.floor(s / 60)}m ${s % 60}s`;
7
+ return `${Math.floor(s / 3600)}h ${Math.floor((s % 3600) / 60)}m`;
8
+ }
9
+
10
+ export function count(n) {
11
+ if (n < 1000) return String(n);
12
+ if (n < 1e6) return `${(n / 1000).toFixed(1)}k`;
13
+ return `${(n / 1e6).toFixed(1)}M`;
14
+ }
15
+
16
+ const time = (iso) => (iso ? new Date(iso).toLocaleString("sv").slice(5, 16) : "?");
17
+
18
+ export function formatReport(report, cwd = "") {
19
+ const rel = (f) => (cwd && f.startsWith(`${cwd}/`) ? path.relative(cwd, f) : f);
20
+ const lines = [];
21
+ for (const a of report.agents) {
22
+ const tools = Object.entries(a.tools)
23
+ .sort((x, y) => y[1] - x[1])
24
+ .map(([name, n]) => `${name} ${n}`)
25
+ .join(", ");
26
+ lines.push(`#${a.n} ${a.id} ${a.description || "(no description)"}`);
27
+ lines.push(` ${time(a.start)} -> ${time(a.end)} ${duration(a.durationMs)} report ${count(a.reportChars)} chars${a.tokens ? ` tokens ${count(a.tokens.total)}` : ""}`);
28
+ lines.push(` tools ${a.toolCalls}${tools ? ` (${tools})` : ""}${a.failed ? ` failed ${a.failed}` : ""}`);
29
+ if (a.read.length) lines.push(` read ${a.read.map(rel).join(", ")}`);
30
+ if (a.edited.length) lines.push(` edited ${a.edited.map(rel).join(", ")}`);
31
+ lines.push("");
32
+ }
33
+ lines.push("Flags");
34
+ if (!report.flags.length) lines.push(" none");
35
+ for (const f of report.flags) lines.push(` ${f.type}: ${f.file ? f.text.replace(f.file, rel(f.file)) : f.text}`);
36
+ const t = report.totals;
37
+ lines.push("");
38
+ lines.push(
39
+ `Total: ${t.subagents} subagents, ${duration(t.durationMs)}, ${t.toolCalls} tool calls${t.tokens === null ? "" : `, ${count(t.tokens)} tokens`}`
40
+ );
41
+ return lines.join("\n");
42
+ }
@@ -0,0 +1,47 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+
5
+ export const defaultBase = () => path.join(process.env.CLAUDE_CONFIG_DIR || path.join(os.homedir(), ".claude"), "projects");
6
+
7
+ export const projectDir = (base, project) => path.join(base, path.resolve(project).replace(/[^a-zA-Z0-9]/g, "-"));
8
+
9
+ export function readEntries(file) {
10
+ const entries = [];
11
+ for (const line of fs.readFileSync(file, "utf8").split("\n")) {
12
+ if (!line.trim()) continue;
13
+ try {
14
+ entries.push(JSON.parse(line));
15
+ } catch {
16
+ continue;
17
+ }
18
+ }
19
+ return entries;
20
+ }
21
+
22
+ export function subagentFiles(sessionFile) {
23
+ const dir = path.join(sessionFile.replace(/\.jsonl$/, ""), "subagents");
24
+ if (!fs.existsSync(dir)) return [];
25
+ return fs.readdirSync(dir).filter((f) => /^agent-.+\.jsonl$/.test(f)).sort().map((f) => path.join(dir, f));
26
+ }
27
+
28
+ export function listSessions(dir) {
29
+ if (!fs.existsSync(dir)) return [];
30
+ return fs
31
+ .readdirSync(dir)
32
+ .filter((f) => f.endsWith(".jsonl"))
33
+ .map((f) => {
34
+ const file = path.join(dir, f);
35
+ return { id: f.slice(0, -6), file, mtime: fs.statSync(file).mtime, subagents: subagentFiles(file).length };
36
+ })
37
+ .sort((a, b) => b.mtime - a.mtime);
38
+ }
39
+
40
+ export function loadSession(file) {
41
+ return {
42
+ id: path.basename(file, ".jsonl"),
43
+ file,
44
+ main: readEntries(file),
45
+ agents: subagentFiles(file).map((f) => ({ id: path.basename(f, ".jsonl").slice(6), entries: readEntries(f) })),
46
+ };
47
+ }