costclaw 0.13.1 → 0.13.3
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 +76 -72
- package/dist/index.js +36 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
A local cost and setup audit for [Claude Code](https://claude.com/claude-code).
|
|
4
4
|
Point it at your session logs and it shows where token spend leaks, scores your
|
|
5
|
-
setup across six pillars, and ranks counterfactual opportunities by estimated
|
|
6
|
-
token value.
|
|
5
|
+
setup across six pillars, and ranks counterfactual opportunities by estimated
|
|
6
|
+
token value.
|
|
7
7
|
|
|
8
|
-
Your prompts are analyzed locally and never uploaded. The audit parses the logs
|
|
9
|
-
already on your disk and prints a report.
|
|
8
|
+
Your prompts are analyzed locally and never uploaded. The audit parses the logs
|
|
9
|
+
already on your disk and prints a report.
|
|
10
10
|
|
|
11
11
|
## Use it
|
|
12
12
|
|
|
@@ -16,43 +16,43 @@ Requires Node 20+.
|
|
|
16
16
|
npx costclaw audit
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
That reads `~/.claude/projects` (override with `--path <dir>`) and prints a
|
|
20
|
-
local report. This concise example is synthetic, generated from synthetic inputs:
|
|
19
|
+
That reads `~/.claude/projects` (override with `--path <dir>`) and prints a
|
|
20
|
+
local report. This concise example is synthetic, generated from synthetic inputs:
|
|
21
21
|
|
|
22
22
|
```
|
|
23
23
|
CostClaw audit
|
|
24
|
-
Source: synthetic example (1 session across 1 project)
|
|
25
|
-
CLAUDE.md: synthetic input
|
|
26
|
-
|
|
27
|
-
Cache-miss exposure (estimate): $90.01
|
|
28
|
-
|
|
29
|
-
Estimated current API-equivalent valuation: $100.01 Cache hit: 0.0% Session hours (timestamp union): 1.0
|
|
30
|
-
Model spend: opus 0.01% / haiku 99.99%
|
|
31
|
-
|
|
32
|
-
Rule-based setup score: 74 / 100 (Solid)
|
|
33
|
-
CLAUDE.md quality 72
|
|
34
|
-
Context hygiene 50
|
|
35
|
-
Prompting patterns 75
|
|
36
|
-
Session management 100
|
|
37
|
-
Tool and MCP config 88
|
|
38
|
-
Cost discipline 67
|
|
39
|
-
|
|
40
|
-
Top opportunities by estimated exposure:
|
|
41
|
-
- [$90.01] Reduce cache-miss exposure
|
|
42
|
-
Synthetic cache-read counterfactual; cold and unique inputs may not be cacheable.
|
|
24
|
+
Source: synthetic example (1 session across 1 project)
|
|
25
|
+
CLAUDE.md: synthetic input
|
|
26
|
+
|
|
27
|
+
Cache-miss exposure (estimate): $90.01
|
|
28
|
+
|
|
29
|
+
Estimated current API-equivalent valuation: $100.01 Cache hit: 0.0% Session hours (timestamp union): 1.0
|
|
30
|
+
Model spend: opus 0.01% / haiku 99.99%
|
|
31
|
+
|
|
32
|
+
Rule-based setup score: 74 / 100 (Solid)
|
|
33
|
+
CLAUDE.md quality 72
|
|
34
|
+
Context hygiene 50
|
|
35
|
+
Prompting patterns 75
|
|
36
|
+
Session management 100
|
|
37
|
+
Tool and MCP config 88
|
|
38
|
+
Cost discipline 67
|
|
39
|
+
|
|
40
|
+
Top opportunities by estimated exposure:
|
|
41
|
+
- [$90.01] Reduce cache-miss exposure
|
|
42
|
+
Synthetic cache-read counterfactual; cold and unique inputs may not be cacheable.
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
The audit applies rules to observed cache and setup patterns. Its suggested causes
|
|
46
|
-
and actions are hypotheses to inspect, not diagnoses or proof that a change will save
|
|
47
|
-
money. Burn Clock needs at least 7 active days of logs; below that it is left out.
|
|
45
|
+
The audit applies rules to observed cache and setup patterns. Its suggested causes
|
|
46
|
+
and actions are hypotheses to inspect, not diagnoses or proof that a change will save
|
|
47
|
+
money. Burn Clock needs at least 7 active days of logs; below that it is left out.
|
|
48
48
|
|
|
49
49
|
## On a subscription? Declare your plan
|
|
50
50
|
|
|
51
51
|
Every dollar the audit prints is an API-equivalent price: what those tokens
|
|
52
52
|
would cost at pay-as-you-go rates. On a Claude subscription (Pro or Max) your
|
|
53
|
-
usage within an included allowance may have no marginal token charge. Extra Usage
|
|
54
|
-
can be billed, so API-equivalent figures are neither money back nor a statement of
|
|
55
|
-
your actual subscription charges.
|
|
53
|
+
usage within an included allowance may have no marginal token charge. Extra Usage
|
|
54
|
+
can be billed, so API-equivalent figures are neither money back nor a statement of
|
|
55
|
+
your actual subscription charges.
|
|
56
56
|
|
|
57
57
|
The first interactive run asks which one you are on and remembers the answer, so
|
|
58
58
|
usually there is nothing to do. To set it directly, or to change it later:
|
|
@@ -64,21 +64,21 @@ npx costclaw audit --plan max20x # or pro, max5x; --plan api switches back
|
|
|
64
64
|
Piped runs, `--json` and CI are never asked and assume API rates, so a scripted
|
|
65
65
|
audit never blocks waiting for an answer.
|
|
66
66
|
|
|
67
|
-
The headline becomes cache-miss exposure - a counterfactual comparison of logged
|
|
68
|
-
token use with a cache-read scenario - with dollars as API-equivalent context. The
|
|
69
|
-
following uses the same synthetic example:
|
|
67
|
+
The headline becomes cache-miss exposure - a counterfactual comparison of logged
|
|
68
|
+
token use with a cache-read scenario - with dollars as API-equivalent context. The
|
|
69
|
+
following uses the same synthetic example:
|
|
70
70
|
|
|
71
71
|
```
|
|
72
|
-
Cache-miss exposure (counterfactual): 90.0% of analyzed usage ($90.01 at API rates)
|
|
73
|
-
|
|
74
|
-
Estimated current API-equivalent valuation: $100.01 Cache hit: 0.0% Session hours (timestamp union): 1.0
|
|
75
|
-
Plan: max20x. This synthetic example does not measure quota, billing, or promise
|
|
76
|
-
more work. Activity windows are omitted when there is insufficient history.
|
|
72
|
+
Cache-miss exposure (counterfactual): 90.0% of analyzed usage ($90.01 at API rates)
|
|
73
|
+
|
|
74
|
+
Estimated current API-equivalent valuation: $100.01 Cache hit: 0.0% Session hours (timestamp union): 1.0
|
|
75
|
+
Plan: max20x. This synthetic example does not measure quota, billing, or promise
|
|
76
|
+
more work. Activity windows are omitted when there is insufficient history.
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
Usage windows are fixed activity bins based on local timestamps. They summarize
|
|
80
|
-
observed activity only: CostClaw does not know Anthropic's actual quota, rate-limit
|
|
81
|
-
windows, subscription inclusion, or billing adjustments.
|
|
79
|
+
Usage windows are fixed activity bins based on local timestamps. They summarize
|
|
80
|
+
observed activity only: CostClaw does not know Anthropic's actual quota, rate-limit
|
|
81
|
+
windows, subscription inclusion, or billing adjustments.
|
|
82
82
|
|
|
83
83
|
The value is saved to `~/.costclaw/config.json`, so later runs (and `optimize`)
|
|
84
84
|
remember it. The findings and their ranking are identical either way; only the
|
|
@@ -91,6 +91,10 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
94
|
+
To audit **one project** instead of all of them, pass that project's own
|
|
95
|
+
directory under `~/.claude/projects` — the one named after its path, like
|
|
96
|
+
`~/.claude/projects/C--Users-you-Projects-myapp`. The report then covers that
|
|
97
|
+
project alone and says `1 project`.
|
|
94
98
|
- `--claude-md <file>` score a specific CLAUDE.md file's quality (by default the
|
|
95
99
|
audit scores `~/.claude/CLAUDE.md` when it exists).
|
|
96
100
|
- `--plan <api|pro|max5x|max20x>` declare how you pay for Claude (see above);
|
|
@@ -107,24 +111,24 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
107
111
|
"What to do next" ramp: the commands to run next, how the optimize license
|
|
108
112
|
works, and a command reference.
|
|
109
113
|
- `--card [file]` also write a shareable score card SVG (default
|
|
110
|
-
`costclaw-card.svg`): your score, band, cache-miss exposure estimate, cache hit rate, and
|
|
114
|
+
`costclaw-card.svg`): your score, band, cache-miss exposure estimate, cache hit rate, and
|
|
111
115
|
strongest pillar. A static file, no fonts or network calls.
|
|
112
116
|
|
|
113
117
|
Run `costclaw --version` (or `-v` / `costclaw version`) to print the installed
|
|
114
|
-
CLI version.
|
|
115
|
-
|
|
116
|
-
## Accuracy boundary
|
|
117
|
-
|
|
118
|
-
The report estimates current API-equivalent list-price value from logged usage and a
|
|
119
|
-
dated rate table. It is not billing proof. Unknown model IDs, unavailable pricing
|
|
120
|
-
modifiers, and incomplete logs add uncertainty. Repeated cumulative request updates
|
|
121
|
-
are counted once using the highest coherent observed total; logged cache TTL splits are priced
|
|
122
|
-
when available. A top-level/split conflict retains the valid top-level count at the
|
|
123
|
-
conservative one-hour rate with a warning; legacy writes without a split use five-minute
|
|
124
|
-
pricing with a warning. Cache-miss exposure is a counterfactual, and the setup score uses
|
|
125
|
-
rules rather than a provider quality grade. The release retests these boundaries with
|
|
126
|
-
`npm test --workspace @costclaw/engine -- accuracy-regression` and
|
|
127
|
-
`npm test --workspace costclaw -- accuracy-report`.
|
|
118
|
+
CLI version.
|
|
119
|
+
|
|
120
|
+
## Accuracy boundary
|
|
121
|
+
|
|
122
|
+
The report estimates current API-equivalent list-price value from logged usage and a
|
|
123
|
+
dated rate table. It is not billing proof. Unknown model IDs, unavailable pricing
|
|
124
|
+
modifiers, and incomplete logs add uncertainty. Repeated cumulative request updates
|
|
125
|
+
are counted once using the highest coherent observed total; logged cache TTL splits are priced
|
|
126
|
+
when available. A top-level/split conflict retains the valid top-level count at the
|
|
127
|
+
conservative one-hour rate with a warning; legacy writes without a split use five-minute
|
|
128
|
+
pricing with a warning. Cache-miss exposure is a counterfactual, and the setup score uses
|
|
129
|
+
rules rather than a provider quality grade. The release retests these boundaries with
|
|
130
|
+
`npm test --workspace @costclaw/engine -- accuracy-regression` and
|
|
131
|
+
`npm test --workspace costclaw -- accuracy-report`.
|
|
128
132
|
|
|
129
133
|
## Diff
|
|
130
134
|
|
|
@@ -135,8 +139,8 @@ Every audit run saves a snapshot of the derived record to `~/.costclaw/history`
|
|
|
135
139
|
npx costclaw diff
|
|
136
140
|
```
|
|
137
141
|
|
|
138
|
-
That compares your latest two audits and shows movement in the estimates. It does not
|
|
139
|
-
verify money recovered. The numeric example below is illustrative:
|
|
142
|
+
That compares your latest two audits and shows movement in the estimates. It does not
|
|
143
|
+
verify money recovered. The numeric example below is illustrative:
|
|
140
144
|
|
|
141
145
|
```
|
|
142
146
|
CostClaw diff
|
|
@@ -145,14 +149,14 @@ Baseline: 2026-06-09 Current: 2026-07-09 (30 days)
|
|
|
145
149
|
Since the baseline:
|
|
146
150
|
New spend $842.10 across 210 new sessions
|
|
147
151
|
Marginal cache hit 97.1% (lifetime 96.2%)
|
|
148
|
-
Cache-miss exposure (estimate) +$96.40 (now $1131.61)
|
|
152
|
+
Cache-miss exposure (estimate) +$96.40 (now $1131.61)
|
|
149
153
|
|
|
150
|
-
Rule-based setup score: 83 -> 86 (+3, Tight)
|
|
154
|
+
Rule-based setup score: 83 -> 86 (+3, Tight)
|
|
151
155
|
CLAUDE.md quality 69 -> 78 (+9)
|
|
152
156
|
...
|
|
153
157
|
|
|
154
158
|
Fixes resolved since the baseline:
|
|
155
|
-
- [$52.40] Review model fit for 61 small sessions
|
|
159
|
+
- [$52.40] Review model fit for 61 small sessions
|
|
156
160
|
```
|
|
157
161
|
|
|
158
162
|
The marginal cache hit rate covers only the period between the two audits, which
|
|
@@ -179,10 +183,10 @@ its band. Drop it in a README with a plain image tag:
|
|
|
179
183
|
costclaw badge [--path <dir>] [--claude-md <file>] [--out <file>]
|
|
180
184
|
```
|
|
181
185
|
|
|
182
|
-
## Optimize
|
|
183
|
-
|
|
184
|
-
The numeric examples in this section are illustrative placeholders, not output from
|
|
185
|
-
an account or a promise of savings.
|
|
186
|
+
## Optimize
|
|
187
|
+
|
|
188
|
+
The numeric examples in this section are illustrative placeholders, not output from
|
|
189
|
+
an account or a promise of savings.
|
|
186
190
|
|
|
187
191
|
```bash
|
|
188
192
|
npx costclaw optimize
|
|
@@ -258,13 +262,13 @@ playbook's per-project table reconciles. costclaw sets no target line count
|
|
|
258
262
|
anywhere: it measures what your sections cost and which lines carry dates, and
|
|
259
263
|
leaves the keep-or-move judgment to you.
|
|
260
264
|
|
|
261
|
-
The playbook breaks the cache-miss exposure estimate down by project, so you can see
|
|
262
|
-
which repository has modeled exposure and at what cache hit rate:
|
|
265
|
+
The playbook breaks the cache-miss exposure estimate down by project, so you can see
|
|
266
|
+
which repository has modeled exposure and at what cache hit rate:
|
|
263
267
|
|
|
264
268
|
```
|
|
265
269
|
### Where that money is
|
|
266
270
|
|
|
267
|
-
| Project | Cache-miss exposure (estimate) | Cache hit | Main sessions |
|
|
271
|
+
| Project | Cache-miss exposure (estimate) | Cache hit | Main sessions |
|
|
268
272
|
| --- | --- | --- | --- |
|
|
269
273
|
| some-app | $490.43 | 98% | 229 |
|
|
270
274
|
| another-app | $312.43 | 99% | 131 |
|
|
@@ -322,6 +326,6 @@ costclaw apply [<dir>] [--remove] [--replace] [--apply-settings [file]] [--from
|
|
|
322
326
|
|
|
323
327
|
## Privacy
|
|
324
328
|
|
|
325
|
-
The audit saves a derived `AuditRecord`: totals and generated prose, with no raw
|
|
326
|
-
prompt text, file paths, or secrets. A hosted dashboard is on the roadmap and would
|
|
327
|
-
receive only that derived record, never your logs.
|
|
329
|
+
The audit saves a derived `AuditRecord`: totals and generated prose, with no raw
|
|
330
|
+
prompt text, file paths, or secrets. A hosted dashboard is on the roadmap and would
|
|
331
|
+
receive only that derived record, never your logs.
|
package/dist/index.js
CHANGED
|
@@ -4434,6 +4434,11 @@ function repoRootFor(startDir) {
|
|
|
4434
4434
|
} catch {
|
|
4435
4435
|
return null;
|
|
4436
4436
|
}
|
|
4437
|
+
try {
|
|
4438
|
+
if (!statSync(dir).isDirectory()) return null;
|
|
4439
|
+
} catch {
|
|
4440
|
+
return null;
|
|
4441
|
+
}
|
|
4437
4442
|
for (let depth = 0; depth < 64; depth += 1) {
|
|
4438
4443
|
const dotGit = join(dir, ".git");
|
|
4439
4444
|
let stat4;
|
|
@@ -4499,15 +4504,36 @@ function projectNameFromLogs(files) {
|
|
|
4499
4504
|
}
|
|
4500
4505
|
return null;
|
|
4501
4506
|
}
|
|
4507
|
+
async function scanProjectDir(projPath, dirName, out) {
|
|
4508
|
+
const files = await collectJsonl(projPath);
|
|
4509
|
+
const probe = projectNameFromLogs(files);
|
|
4510
|
+
const repoRoot = probe ? repoRootFor(probe.cwd) : null;
|
|
4511
|
+
const resolvedSlug = repoRoot ? basename(repoRoot) : probe?.slug;
|
|
4512
|
+
const projectSlug = resolvedSlug || dirName;
|
|
4513
|
+
if (probe && !out.projectDirs.has(projectSlug)) out.projectDirs.set(projectSlug, repoRoot ?? probe.cwd);
|
|
4514
|
+
for (const full of files) {
|
|
4515
|
+
const rel = relative(projPath, full).split(sep).join("/");
|
|
4516
|
+
const name = `${dirName}/${rel}`;
|
|
4517
|
+
const { kind, parentSessionId } = classify(rel);
|
|
4518
|
+
try {
|
|
4519
|
+
closeSync(openSync(full, "r"));
|
|
4520
|
+
out.logs.push(lazyLog(full, { name, kind, parentSessionId, projectSlug }));
|
|
4521
|
+
} catch {
|
|
4522
|
+
out.skipped.push(name);
|
|
4523
|
+
}
|
|
4524
|
+
}
|
|
4525
|
+
}
|
|
4502
4526
|
async function readSessions(rootPath) {
|
|
4503
|
-
const
|
|
4504
|
-
const skipped = [];
|
|
4505
|
-
const projectDirs = /* @__PURE__ */ new Map();
|
|
4527
|
+
const out = { logs: [], skipped: [], projectDirs: /* @__PURE__ */ new Map() };
|
|
4506
4528
|
let entries;
|
|
4507
4529
|
try {
|
|
4508
4530
|
entries = await readdir(rootPath, { withFileTypes: true });
|
|
4509
4531
|
} catch {
|
|
4510
|
-
return
|
|
4532
|
+
return out;
|
|
4533
|
+
}
|
|
4534
|
+
if (entries.some((e) => e.isFile() && e.name.endsWith(".jsonl"))) {
|
|
4535
|
+
await scanProjectDir(rootPath, basename(rootPath), out);
|
|
4536
|
+
return out;
|
|
4511
4537
|
}
|
|
4512
4538
|
for (const dir of entries) {
|
|
4513
4539
|
if (!dir.isDirectory()) continue;
|
|
@@ -4515,28 +4541,12 @@ async function readSessions(rootPath) {
|
|
|
4515
4541
|
try {
|
|
4516
4542
|
await readdir(projPath);
|
|
4517
4543
|
} catch {
|
|
4518
|
-
skipped.push(dir.name);
|
|
4544
|
+
out.skipped.push(dir.name);
|
|
4519
4545
|
continue;
|
|
4520
4546
|
}
|
|
4521
|
-
|
|
4522
|
-
const probe = projectNameFromLogs(files);
|
|
4523
|
-
const repoRoot = probe ? repoRootFor(probe.cwd) : null;
|
|
4524
|
-
const resolvedSlug = repoRoot ? basename(repoRoot) : probe?.slug;
|
|
4525
|
-
const projectSlug = resolvedSlug || dir.name;
|
|
4526
|
-
if (probe && !projectDirs.has(projectSlug)) projectDirs.set(projectSlug, repoRoot ?? probe.cwd);
|
|
4527
|
-
for (const full of files) {
|
|
4528
|
-
const rel = relative(projPath, full).split(sep).join("/");
|
|
4529
|
-
const name = `${dir.name}/${rel}`;
|
|
4530
|
-
const { kind, parentSessionId } = classify(rel);
|
|
4531
|
-
try {
|
|
4532
|
-
closeSync(openSync(full, "r"));
|
|
4533
|
-
logs.push(lazyLog(full, { name, kind, parentSessionId, projectSlug }));
|
|
4534
|
-
} catch {
|
|
4535
|
-
skipped.push(name);
|
|
4536
|
-
}
|
|
4537
|
-
}
|
|
4547
|
+
await scanProjectDir(projPath, dir.name, out);
|
|
4538
4548
|
}
|
|
4539
|
-
return
|
|
4549
|
+
return out;
|
|
4540
4550
|
}
|
|
4541
4551
|
|
|
4542
4552
|
// src/ansi.ts
|
|
@@ -8171,7 +8181,7 @@ function parseApplyFlags(args) {
|
|
|
8171
8181
|
};
|
|
8172
8182
|
}
|
|
8173
8183
|
function cliVersion() {
|
|
8174
|
-
return true ? "0.13.
|
|
8184
|
+
return true ? "0.13.3" : "0.0.0-dev";
|
|
8175
8185
|
}
|
|
8176
8186
|
function isHelpRequest(command, args) {
|
|
8177
8187
|
if (command === void 0) return false;
|
|
@@ -8195,6 +8205,8 @@ function helpText() {
|
|
|
8195
8205
|
"",
|
|
8196
8206
|
"audit reads your Claude Code logs from ~/.claude/projects (or --path) on this",
|
|
8197
8207
|
"machine and prints a cost report plus a six-pillar setup score. It is free.",
|
|
8208
|
+
"To audit one project rather than all of them, point --path at that project's",
|
|
8209
|
+
"own directory under ~/.claude/projects (the one named after its path).",
|
|
8198
8210
|
"By default it also writes a self-contained HTML report (costclaw-report.html)",
|
|
8199
8211
|
"and opens it in your browser; --no-html skips that, --html <file> picks the",
|
|
8200
8212
|
"path, and --json runs stay file-free unless --html is passed explicitly.",
|