Skip to content

Commit 9e9cec2

Browse files
baxenmbotclaudeART
authored
perf(usage): read Claude usage once, then only what changed (#1586)
Signed-off-by: Bradley Axen <[email protected]> Co-authored-by: mbot <3754f8729004d95654c46dbab3129e4ab9ef05cc2534e2a3fbfc155983bd637b@buzz.block.builderlab.xyz> Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: ART <ea39c1c8acf57180161ef4ba4ed68abf8589f5291956b909a5aa991fc66664ca@buzz.block.builderlab.xyz>
1 parent 8739ac2 commit 9e9cec2

15 files changed

Lines changed: 1518 additions & 374 deletions

File tree

‎src/bundled/claude-code/index.ts‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const apply: PluginModule["apply"] = (ctx) => {
2525
const { agents, host } = ctx;
2626
const typeKey = `${ctx.pluginOwner?.id ?? "buzz.claude-code"}/${TYPE_ID}`;
2727
const spawn = host.spawn && withScript(host.spawn.bind(host));
28+
const readFile = host.readFile?.bind(host);
2829
const setup = new ClaudeSetup(spawn, (input) => host.request(input));
2930
const providerDefaults = new ClaudeDefaults(agents.storage);
3031
const runtime = new ClaudeRuntime(
@@ -117,17 +118,18 @@ export const apply: PluginModule["apply"] = (ctx) => {
117118
];
118119
},
119120
summary: (agent) => config(agent.config).model || "Claude",
120-
...(spawn && {
121-
usage: (agent, { since, signal }) =>
122-
readUsage(
123-
spawn,
124-
config(agent.config).workspace,
125-
agent.pubkey,
126-
runtime.conversations(agent.pubkey).map((saved) => saved.sessionId),
127-
since,
128-
signal,
129-
),
130-
}),
121+
...(spawn &&
122+
readFile && {
123+
usage: (agent, { since, signal }) =>
124+
readUsage(
125+
{ spawn, readFile },
126+
config(agent.config).workspace,
127+
agent.pubkey,
128+
runtime.conversations(agent.pubkey).map((saved) => saved.sessionId),
129+
since,
130+
signal,
131+
),
132+
}),
131133
provider: {
132134
snapshot: setup.providerSnapshot,
133135
subscribe: setup.subscribe,

‎src/bundled/claude-code/manifest.json‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"host": {
1111
"networkOrigins": ["https://downloads.claude.ai"],
12+
"files": true,
1213
"processes": [
1314
{
1415
"id": "claude-sh",
@@ -26,6 +27,22 @@
2627
"args": ["-i"]
2728
},
2829
{ "id": "workspace", "program": "pwd" },
30+
{
31+
"id": "owners",
32+
"program": "grep",
33+
"args": [
34+
"-rHEo",
35+
"-m1",
36+
"--include=*.jsonl",
37+
"-e",
38+
"Agent: [0-9a-f]{64}"
39+
]
40+
},
41+
{
42+
"id": "list",
43+
"program": "find",
44+
"args": [".", "-type", "f", "-name", "*.jsonl"]
45+
},
2946
{
3047
"id": "find",
3148
"program": "grep",

‎src/bundled/claude-code/transcript.ts‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -262,32 +262,17 @@ async function otherSessions(spawn: Spawn, project: string, pattern: string) {
262262
}
263263

264264
/** Paths of the project's `.jsonl` files, subagents' included, containing
265-
* `pattern`. A failed search finds what it found before failing, unless
266-
* `exhaustive`, when it rejects. */
267-
export async function searchProject(
268-
spawn: Spawn,
269-
project: string,
270-
pattern: string,
271-
exhaustive = false,
272-
) {
265+
* `pattern`. A failed search finds what it found before failing. */
266+
async function searchProject(spawn: Spawn, project: string, pattern: string) {
273267
let output = "";
274-
let errors = "";
275268
const process = await spawn("find", {
276269
args: [pattern, "."],
277270
cwd: `~/.claude/projects/${project}`,
278271
onStdout: (data) => {
279272
output += data;
280273
},
281-
onStderr: (data) => {
282-
errors += data;
283-
},
284274
});
285-
const code = await process.exited;
286-
// No match exits 1.
287-
if (exhaustive && code !== 0 && code !== 1)
288-
throw new Error(
289-
`Couldn’t search the Claude Code history: ${errors.trim() || `exit ${code}`}`,
290-
);
275+
await process.exited;
291276
return output
292277
.split("\n")
293278
.map((line) => line.trim().replace(/^\.\//, ""))

0 commit comments

Comments
 (0)