costclaw 0.3.0 → 0.5.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/README.md +15 -5
- package/dist/index.js +183 -35
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,8 +65,16 @@ Recoverable usage (cache-miss exposure): 14.3% of analyzed usage ($1134.61 at AP
|
|
|
65
65
|
Usage analyzed (API-equivalent): $7921.99 Cache hit: 96.2% Active hours: 1889.7
|
|
66
66
|
Plan: max20x. Dollar figures are API-equivalent token value, not money back;
|
|
67
67
|
recovering them buys rate-limit headroom (more work per usage window).
|
|
68
|
+
Usage windows (5h, like your rate limit): median $8.10, busiest $34.20; busiest week $310.55 (API-equivalent)
|
|
69
|
+
Recovering 14.3% buys about 17% more work per window: up to ~42 extra minutes in a window like your busiest.
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
The usage windows are modeled from your own activity timestamps, mirroring how
|
|
73
|
+
the limits actually work: a 5-hour window opens at your first activity, and a
|
|
74
|
+
weekly cap sits above it. Nothing is assumed about Anthropic's actual budgets;
|
|
75
|
+
everything is relative to your observed consumption ("busiest" is the 90th
|
|
76
|
+
percentile window, so one freak outlier does not set the bar).
|
|
77
|
+
|
|
70
78
|
The value is saved to `~/.costclaw/config.json`, so later runs (and `optimize`)
|
|
71
79
|
remember it. The findings and their ranking are identical either way; only the
|
|
72
80
|
unit is framed to match how you actually pay.
|
|
@@ -74,7 +82,7 @@ unit is framed to match how you actually pay.
|
|
|
74
82
|
## Options
|
|
75
83
|
|
|
76
84
|
```
|
|
77
|
-
costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--card [file]]
|
|
85
|
+
costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--no-html] [--card [file]]
|
|
78
86
|
```
|
|
79
87
|
|
|
80
88
|
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
@@ -83,10 +91,12 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
83
91
|
- `--plan <api|pro|max5x|max20x>` declare how you pay for Claude (see above);
|
|
84
92
|
persisted for later runs.
|
|
85
93
|
- `--json` print the raw, derived `AuditRecord` instead of the human report.
|
|
86
|
-
-
|
|
87
|
-
`costclaw-report.html` in the current directory)
|
|
88
|
-
|
|
89
|
-
|
|
94
|
+
- The HTML report is written and opened in your browser **by default**
|
|
95
|
+
(`costclaw-report.html` in the current directory). The file inlines
|
|
96
|
+
everything, so nothing is fetched and nothing is uploaded; the terminal
|
|
97
|
+
report still prints (in color on interactive terminals; set `NO_COLOR` to
|
|
98
|
+
disable). `--html <file>` picks the path; `--no-html` skips the file;
|
|
99
|
+
`--json` runs stay file-free unless `--html` is passed explicitly.
|
|
90
100
|
- `--card [file]` also write a shareable score card SVG (default
|
|
91
101
|
`costclaw-card.svg`): your score, band, recoverable spend, cache hit rate, and
|
|
92
102
|
strongest pillar. A static file, no fonts or network calls.
|
package/dist/index.js
CHANGED
|
@@ -153,9 +153,12 @@ function parseSession(text2, opts = {}) {
|
|
|
153
153
|
skippedLines: 0,
|
|
154
154
|
kind: opts.kind ?? "main",
|
|
155
155
|
parentSessionId: opts.parentSessionId ?? null,
|
|
156
|
-
turnCache: []
|
|
156
|
+
turnCache: [],
|
|
157
|
+
costBuckets: []
|
|
157
158
|
};
|
|
158
159
|
const seen = /* @__PURE__ */ new Set();
|
|
160
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
161
|
+
const BUCKET_MS = 15 * 60 * 1e3;
|
|
159
162
|
const modelCounts = /* @__PURE__ */ new Map();
|
|
160
163
|
let cwd = null;
|
|
161
164
|
let seq = 0;
|
|
@@ -198,8 +201,16 @@ function parseSession(text2, opts = {}) {
|
|
|
198
201
|
s.totals.output_tokens += Number(usage.output_tokens) || 0;
|
|
199
202
|
s.totals.cache_creation_tokens += Number(usage.cache_creation_input_tokens) || 0;
|
|
200
203
|
s.totals.cache_read_tokens += Number(usage.cache_read_input_tokens) || 0;
|
|
201
|
-
|
|
204
|
+
const fragmentUsd = costForUsage(model, usage);
|
|
205
|
+
s.cost_usd += fragmentUsd;
|
|
202
206
|
s.cache_savings_usd += cacheSavingsForUsage(model, usage);
|
|
207
|
+
if (rec.timestamp) {
|
|
208
|
+
const ms = Date.parse(rec.timestamp);
|
|
209
|
+
if (!Number.isNaN(ms)) {
|
|
210
|
+
const t = Math.floor(ms / BUCKET_MS);
|
|
211
|
+
buckets.set(t, (buckets.get(t) ?? 0) + fragmentUsd);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
203
214
|
s.turnCache.push({
|
|
204
215
|
read: Number(usage.cache_read_input_tokens) || 0,
|
|
205
216
|
miss: (Number(usage.input_tokens) || 0) + (Number(usage.cache_creation_input_tokens) || 0)
|
|
@@ -207,6 +218,7 @@ function parseSession(text2, opts = {}) {
|
|
|
207
218
|
}
|
|
208
219
|
}
|
|
209
220
|
}
|
|
221
|
+
s.costBuckets = [...buckets.entries()].sort((a, b) => a[0] - b[0]).map(([t, usd7]) => ({ t, usd: usd7 }));
|
|
210
222
|
s.projectSlug = opts.projectSlug ?? projectFromCwd(cwd);
|
|
211
223
|
let best = null;
|
|
212
224
|
let bestCount = 0;
|
|
@@ -1392,6 +1404,74 @@ function synthesize(report, pillars, cmd, plan = "api") {
|
|
|
1392
1404
|
};
|
|
1393
1405
|
}
|
|
1394
1406
|
|
|
1407
|
+
// ../../packages/engine/src/windows.ts
|
|
1408
|
+
var BUCKET_MINUTES = 15;
|
|
1409
|
+
var WINDOW_BUCKETS = 5 * 60 / BUCKET_MINUTES;
|
|
1410
|
+
var WEEK_BUCKETS = 7 * 24 * 60 / BUCKET_MINUTES;
|
|
1411
|
+
function median(sortedAsc) {
|
|
1412
|
+
const n = sortedAsc.length;
|
|
1413
|
+
if (n === 0) return 0;
|
|
1414
|
+
const mid = Math.floor(n / 2);
|
|
1415
|
+
return n % 2 === 1 ? sortedAsc[mid] : (sortedAsc[mid - 1] + sortedAsc[mid]) / 2;
|
|
1416
|
+
}
|
|
1417
|
+
function p90Index(n) {
|
|
1418
|
+
return Math.max(0, Math.ceil(0.9 * n) - 1);
|
|
1419
|
+
}
|
|
1420
|
+
function computeWindowStats(report) {
|
|
1421
|
+
const merged = /* @__PURE__ */ new Map();
|
|
1422
|
+
for (const project of report.projects) {
|
|
1423
|
+
for (const session of project.sessions) {
|
|
1424
|
+
for (const b of session.costBuckets) merged.set(b.t, (merged.get(b.t) ?? 0) + b.usd);
|
|
1425
|
+
}
|
|
1426
|
+
}
|
|
1427
|
+
const buckets = [...merged.entries()].sort((a, b) => a[0] - b[0]);
|
|
1428
|
+
if (buckets.length === 0) {
|
|
1429
|
+
return {
|
|
1430
|
+
assessed: false,
|
|
1431
|
+
windowsCount: 0,
|
|
1432
|
+
medianWindowUsd: 0,
|
|
1433
|
+
p90WindowUsd: 0,
|
|
1434
|
+
maxWindowUsd: 0,
|
|
1435
|
+
p90WindowActiveMinutes: 0,
|
|
1436
|
+
weeksCount: 0,
|
|
1437
|
+
medianWeekUsd: 0,
|
|
1438
|
+
maxWeekUsd: 0
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
const windows = [];
|
|
1442
|
+
let windowStart = -Infinity;
|
|
1443
|
+
for (const [t, usd7] of buckets) {
|
|
1444
|
+
if (t >= windowStart + WINDOW_BUCKETS) {
|
|
1445
|
+
windows.push({ usd: 0, activeMinutes: 0 });
|
|
1446
|
+
windowStart = t;
|
|
1447
|
+
}
|
|
1448
|
+
const w = windows[windows.length - 1];
|
|
1449
|
+
w.usd += usd7;
|
|
1450
|
+
w.activeMinutes += BUCKET_MINUTES;
|
|
1451
|
+
}
|
|
1452
|
+
const firstT = buckets[0][0];
|
|
1453
|
+
const weeks = /* @__PURE__ */ new Map();
|
|
1454
|
+
for (const [t, usd7] of buckets) {
|
|
1455
|
+
const week = Math.floor((t - firstT) / WEEK_BUCKETS);
|
|
1456
|
+
weeks.set(week, (weeks.get(week) ?? 0) + usd7);
|
|
1457
|
+
}
|
|
1458
|
+
const byUsd = windows.slice().sort((a, b) => a.usd - b.usd);
|
|
1459
|
+
const usdAsc = byUsd.map((w) => w.usd);
|
|
1460
|
+
const p90 = byUsd[p90Index(byUsd.length)];
|
|
1461
|
+
const weekUsdAsc = [...weeks.values()].sort((a, b) => a - b);
|
|
1462
|
+
return {
|
|
1463
|
+
assessed: true,
|
|
1464
|
+
windowsCount: windows.length,
|
|
1465
|
+
medianWindowUsd: median(usdAsc),
|
|
1466
|
+
p90WindowUsd: p90.usd,
|
|
1467
|
+
maxWindowUsd: usdAsc[usdAsc.length - 1],
|
|
1468
|
+
p90WindowActiveMinutes: p90.activeMinutes,
|
|
1469
|
+
weeksCount: weekUsdAsc.length,
|
|
1470
|
+
medianWeekUsd: median(weekUsdAsc),
|
|
1471
|
+
maxWeekUsd: weekUsdAsc[weekUsdAsc.length - 1]
|
|
1472
|
+
};
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1395
1475
|
// ../../packages/engine/src/optimize.ts
|
|
1396
1476
|
function usd(n) {
|
|
1397
1477
|
const rounded = Math.round(n * 100) / 100;
|
|
@@ -1893,6 +1973,17 @@ function toUsageMetrics(report) {
|
|
|
1893
1973
|
pricingSnapshotDate: PRICING_SNAPSHOT_DATE
|
|
1894
1974
|
};
|
|
1895
1975
|
}
|
|
1976
|
+
function roundWindows(w) {
|
|
1977
|
+
return {
|
|
1978
|
+
...w,
|
|
1979
|
+
medianWindowUsd: round2(w.medianWindowUsd),
|
|
1980
|
+
p90WindowUsd: round2(w.p90WindowUsd),
|
|
1981
|
+
maxWindowUsd: round2(w.maxWindowUsd),
|
|
1982
|
+
p90WindowActiveMinutes: Math.round(w.p90WindowActiveMinutes),
|
|
1983
|
+
medianWeekUsd: round2(w.medianWeekUsd),
|
|
1984
|
+
maxWeekUsd: round2(w.maxWeekUsd)
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1896
1987
|
function cleanFix(f) {
|
|
1897
1988
|
return {
|
|
1898
1989
|
...f,
|
|
@@ -1935,6 +2026,7 @@ function buildAudit(input, opts = {}) {
|
|
|
1935
2026
|
headlineWasteLabel: sanitizeText(headlineWasteLabel),
|
|
1936
2027
|
plan,
|
|
1937
2028
|
headlineWasteShare: round4(headlineWasteShare),
|
|
2029
|
+
usageWindows: roundWindows(computeWindowStats(report)),
|
|
1938
2030
|
fixes: fixes.map(cleanFix),
|
|
1939
2031
|
writer: opts.writer ?? "template",
|
|
1940
2032
|
paid: false
|
|
@@ -2118,14 +2210,33 @@ async function readSessions(rootPath) {
|
|
|
2118
2210
|
return { logs, skipped };
|
|
2119
2211
|
}
|
|
2120
2212
|
|
|
2213
|
+
// src/ansi.ts
|
|
2214
|
+
var ESC = String.fromCharCode(27);
|
|
2215
|
+
function bandCode(score) {
|
|
2216
|
+
if (score < 40) return "38;5;160";
|
|
2217
|
+
if (score < 60) return "38;5;173";
|
|
2218
|
+
if (score < 75) return "38;5;178";
|
|
2219
|
+
if (score < 90) return "38;5;71";
|
|
2220
|
+
return "38;5;29";
|
|
2221
|
+
}
|
|
2222
|
+
function ansi(enabled) {
|
|
2223
|
+
const wrap = (open, close) => (s) => enabled ? `${ESC}[${open}m${s}${ESC}[${close}m` : s;
|
|
2224
|
+
return {
|
|
2225
|
+
bold: wrap("1", "22"),
|
|
2226
|
+
dim: wrap("2", "22"),
|
|
2227
|
+
brand: wrap("1;38;5;209", "0"),
|
|
2228
|
+
score: (n, s) => enabled ? `${ESC}[${bandCode(n)}m${s}${ESC}[39m` : s
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2121
2232
|
// src/format.ts
|
|
2122
2233
|
function usd2(n) {
|
|
2123
2234
|
return `$${(Math.round(n * 100) / 100).toFixed(2)}`;
|
|
2124
2235
|
}
|
|
2125
|
-
function bar(score, width = 20) {
|
|
2126
|
-
if (score === null) return "n/a";
|
|
2236
|
+
function bar(score, a, width = 20) {
|
|
2237
|
+
if (score === null) return a.dim("n/a");
|
|
2127
2238
|
const filled = Math.round(score / 100 * width);
|
|
2128
|
-
return `[${"#".repeat(filled)}${".".repeat(width - filled)}] ${score}`;
|
|
2239
|
+
return `[${a.score(score, "#".repeat(filled))}${a.dim(".".repeat(width - filled))}] ${a.bold(String(score))}`;
|
|
2129
2240
|
}
|
|
2130
2241
|
function shortModel(id) {
|
|
2131
2242
|
const m = /(opus|sonnet|haiku|fable)/i.exec(id);
|
|
@@ -2153,80 +2264,103 @@ function unassessedLine(pillars) {
|
|
|
2153
2264
|
});
|
|
2154
2265
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
2155
2266
|
}
|
|
2156
|
-
function formatAudit(record, meta) {
|
|
2267
|
+
function formatAudit(record, meta, color = false) {
|
|
2268
|
+
const a = ansi(color);
|
|
2157
2269
|
const m = record.usageMetrics;
|
|
2158
2270
|
const subscription = record.plan !== void 0 && record.plan !== "api";
|
|
2159
2271
|
const share = record.headlineWasteShare ?? (m.spendUsd > 0 ? record.headlineWasteUsd / m.spendUsd : 0);
|
|
2160
2272
|
const shareText = `${(share * 100).toFixed(1)}%`;
|
|
2161
2273
|
const lines = [];
|
|
2162
|
-
lines.push("CostClaw audit");
|
|
2163
|
-
lines.push(`Source: ${meta.root} (${meta.sessionCount} sessions across ${m.projectsCount} projects)`);
|
|
2164
|
-
if (meta.claudeMdSource) lines.push(`CLAUDE.md: ${meta.claudeMdSource}`);
|
|
2274
|
+
lines.push(a.bold("CostClaw audit"));
|
|
2275
|
+
lines.push(a.dim(`Source: ${meta.root} (${meta.sessionCount} sessions across ${m.projectsCount} projects)`));
|
|
2276
|
+
if (meta.claudeMdSource) lines.push(a.dim(`CLAUDE.md: ${meta.claudeMdSource}`));
|
|
2165
2277
|
lines.push("");
|
|
2166
2278
|
lines.push(
|
|
2167
|
-
subscription ? `${record.headlineWasteLabel}
|
|
2279
|
+
subscription ? `${a.bold(record.headlineWasteLabel + ":")} ${a.brand(shareText + " of analyzed usage")} (${usd2(record.headlineWasteUsd)} at API rates)` : `${a.bold(record.headlineWasteLabel + ":")} ${a.brand(usd2(record.headlineWasteUsd))}`
|
|
2168
2280
|
);
|
|
2169
2281
|
lines.push("");
|
|
2170
2282
|
lines.push(
|
|
2171
|
-
`${subscription ? "Usage analyzed (API-equivalent)" : "Spend analyzed"}
|
|
2283
|
+
`${a.dim(subscription ? "Usage analyzed (API-equivalent):" : "Spend analyzed:")} ${a.bold(usd2(m.spendUsd))} ${a.dim("Cache hit:")} ${a.bold(`${(m.cacheHitRate * 100).toFixed(1)}%`)} ${a.dim("Active hours:")} ${a.bold(m.durationHours.toFixed(1))}`
|
|
2172
2284
|
);
|
|
2173
|
-
lines.push(`Pricing snapshot: ${m.pricingSnapshotDate}`);
|
|
2174
2285
|
const mix = modelMix(m.modelBreakdown);
|
|
2175
|
-
|
|
2286
|
+
lines.push(
|
|
2287
|
+
a.dim(`Pricing snapshot: ${m.pricingSnapshotDate}`) + (mix ? ` ${a.dim("Model spend:")} ${mix}` : "")
|
|
2288
|
+
);
|
|
2289
|
+
const w = record.usageWindows;
|
|
2176
2290
|
if (subscription) {
|
|
2291
|
+
lines.push("");
|
|
2177
2292
|
lines.push(
|
|
2178
|
-
|
|
2293
|
+
a.dim(
|
|
2294
|
+
`Plan: ${record.plan}. Dollar figures are API-equivalent token value, not money back; recovering them buys rate-limit headroom (more work per usage window).`
|
|
2295
|
+
)
|
|
2179
2296
|
);
|
|
2297
|
+
if (w?.assessed) {
|
|
2298
|
+
lines.push(
|
|
2299
|
+
`${a.dim("Usage windows (5h, like your rate limit):")} median ${a.bold(usd2(w.medianWindowUsd))}, busiest ${a.bold(usd2(w.p90WindowUsd))}; busiest week ${a.bold(usd2(w.maxWeekUsd))} (API-equivalent)`
|
|
2300
|
+
);
|
|
2301
|
+
if (share >= 0.01 && share < 1) {
|
|
2302
|
+
const gain = share / (1 - share);
|
|
2303
|
+
const extraMinutes = Math.round(w.p90WindowActiveMinutes * gain);
|
|
2304
|
+
lines.push(
|
|
2305
|
+
`Recovering ${shareText} buys about ${a.bold(`${Math.round(gain * 100)}% more work per window`)}: up to ${a.brand(`~${extraMinutes} extra minutes`)} in a window like your busiest.`
|
|
2306
|
+
);
|
|
2307
|
+
}
|
|
2308
|
+
}
|
|
2180
2309
|
} else if (meta.planSource === "default") {
|
|
2310
|
+
const burn = w?.assessed && w.medianWeekUsd >= 50 ? ` Your median week burns ${usd2(w.medianWeekUsd)} at API rates.` : "";
|
|
2181
2311
|
lines.push(
|
|
2182
|
-
|
|
2312
|
+
a.dim(
|
|
2313
|
+
`Dollar figures are API-equivalent rates.${burn} On a Claude subscription? Rerun with --plan max20x (or pro, max5x) to frame results as token efficiency.`
|
|
2314
|
+
)
|
|
2183
2315
|
);
|
|
2184
2316
|
}
|
|
2185
2317
|
if (m.topProjects.length > 0) {
|
|
2186
2318
|
lines.push("");
|
|
2187
|
-
lines.push("Top projects by spend:");
|
|
2319
|
+
lines.push(a.bold("Top projects by spend:"));
|
|
2188
2320
|
for (const p of m.topProjects.slice(0, 5)) {
|
|
2189
2321
|
const name = p.slug.length > 30 ? p.slug.slice(0, 27) + "..." : p.slug;
|
|
2190
2322
|
const model = p.modelPrimary ? shortModel(p.modelPrimary) : "n/a";
|
|
2191
2323
|
lines.push(
|
|
2192
|
-
` ${name.padEnd(32)}${usd2(p.costUsd).padStart(10)} ${String(p.sessionsCount).padStart(4)} sessions cache ${(p.cacheHitRate * 100).toFixed(1)}% ${model}`
|
|
2324
|
+
` ${name.padEnd(32)}${a.bold(usd2(p.costUsd).padStart(10))} ${String(p.sessionsCount).padStart(4)} sessions ${a.dim(`cache ${(p.cacheHitRate * 100).toFixed(1)}% ${model}`)}`
|
|
2193
2325
|
);
|
|
2194
2326
|
}
|
|
2195
2327
|
}
|
|
2196
2328
|
lines.push("");
|
|
2197
|
-
lines.push(
|
|
2329
|
+
lines.push(
|
|
2330
|
+
`${a.bold("Overall setup score:")} ${a.score(record.overallScore, `${record.overallScore} / 100`)} (${a.score(record.overallScore, record.band.label)})`
|
|
2331
|
+
);
|
|
2198
2332
|
for (const p of record.pillarScores) {
|
|
2199
|
-
lines.push(` ${p.name.padEnd(22)} ${bar(p.score)}`);
|
|
2333
|
+
lines.push(` ${p.name.padEnd(22)} ${bar(p.score, a)}`);
|
|
2200
2334
|
}
|
|
2201
2335
|
lines.push("");
|
|
2202
2336
|
const dollarFixes = record.fixes.filter((f) => f.wasteUsd > 0);
|
|
2203
2337
|
const otherIssues = record.fixes.filter((f) => f.wasteUsd === 0);
|
|
2204
|
-
lines.push("Top fixes by recoverable spend:");
|
|
2338
|
+
lines.push(a.bold("Top fixes by recoverable spend:"));
|
|
2205
2339
|
if (dollarFixes.length === 0) {
|
|
2206
2340
|
lines.push(" No directly recoverable dollars found. See issues below.");
|
|
2207
2341
|
} else {
|
|
2208
2342
|
for (const f of dollarFixes) {
|
|
2209
|
-
lines.push(` - [${usd2(f.wasteUsd)}] ${f.title}`);
|
|
2343
|
+
lines.push(` - [${a.brand(usd2(f.wasteUsd))}] ${a.bold(f.title)}`);
|
|
2210
2344
|
lines.push(` ${f.action}`);
|
|
2211
|
-
if (f.basis) lines.push(` Evidence: ${f.basis}`);
|
|
2345
|
+
if (f.basis) lines.push(a.dim(` Evidence: ${f.basis}`));
|
|
2212
2346
|
}
|
|
2213
2347
|
}
|
|
2214
2348
|
if (otherIssues.length > 0) {
|
|
2215
2349
|
lines.push("");
|
|
2216
|
-
lines.push("Other issues to tighten:");
|
|
2350
|
+
lines.push(a.bold("Other issues to tighten:"));
|
|
2217
2351
|
for (const f of otherIssues) {
|
|
2218
2352
|
lines.push(` - ${f.title}`);
|
|
2219
|
-
if (f.basis) lines.push(` ${f.basis}`);
|
|
2353
|
+
if (f.basis) lines.push(a.dim(` ${f.basis}`));
|
|
2220
2354
|
}
|
|
2221
2355
|
}
|
|
2222
2356
|
if (meta.skipped.length > 0) {
|
|
2223
2357
|
lines.push("");
|
|
2224
|
-
lines.push(`Note: ${meta.skipped.length} file(s) could not be read and were skipped.`);
|
|
2358
|
+
lines.push(a.dim(`Note: ${meta.skipped.length} file(s) could not be read and were skipped.`));
|
|
2225
2359
|
}
|
|
2226
2360
|
const gapLine = unassessedLine(record.pillarScores);
|
|
2227
2361
|
if (gapLine) {
|
|
2228
2362
|
lines.push("");
|
|
2229
|
-
lines.push(gapLine);
|
|
2363
|
+
lines.push(a.dim(gapLine));
|
|
2230
2364
|
}
|
|
2231
2365
|
return lines.join("\n");
|
|
2232
2366
|
}
|
|
@@ -2362,7 +2496,16 @@ function renderHtml(record, meta) {
|
|
|
2362
2496
|
const shareText = `${(share * 100).toFixed(1)}%`;
|
|
2363
2497
|
const bannerAmount = subscription ? `<div class="amount">${shareText} of analyzed usage</div><div class="amount-sub">${esc(usd3(record.headlineWasteUsd))} at API rates</div>` : `<div class="amount">${esc(usd3(record.headlineWasteUsd))}</div>`;
|
|
2364
2498
|
const spendLabel = subscription ? "Usage analyzed (API-equivalent)" : "Spend analyzed";
|
|
2365
|
-
const
|
|
2499
|
+
const w = record.usageWindows;
|
|
2500
|
+
let headroom = "";
|
|
2501
|
+
if (subscription && w?.assessed && share >= 0.01 && share < 1) {
|
|
2502
|
+
const gain = share / (1 - share);
|
|
2503
|
+
const extraMinutes = Math.round(w.p90WindowActiveMinutes * gain);
|
|
2504
|
+
headroom = ` Recovering ${shareText} buys about ${Math.round(gain * 100)}% more work per window: up to ~${extraMinutes} extra minutes in a window like your busiest.`;
|
|
2505
|
+
}
|
|
2506
|
+
const weeklyBurn = !subscription && meta.planSource === "default" && w?.assessed && w.medianWeekUsd >= 50 ? ` Your median week burns ${esc(usd3(w.medianWeekUsd))} at API rates.` : "";
|
|
2507
|
+
const planNote = subscription ? `<p class="sub">Plan: ${esc(record.plan)}. Dollar figures are API-equivalent token value, not money back; recovering them buys rate-limit headroom (more work per usage window).${headroom}</p>` : meta.planSource === "default" ? `<p class="sub">Dollar figures are API-equivalent rates.${weeklyBurn} On a Claude subscription? Rerun with --plan max20x (or pro, max5x) to frame results as token efficiency.</p>` : "";
|
|
2508
|
+
const windowTiles = subscription && w?.assessed ? `<div class="stats"><div class="stat"><div class="k">Median 5h window</div><div class="v">${esc(usd3(w.medianWindowUsd))}</div></div><div class="stat"><div class="k">Busiest 5h window (p90)</div><div class="v">${esc(usd3(w.p90WindowUsd))}</div></div><div class="stat"><div class="k">Busiest week</div><div class="v">${esc(usd3(w.maxWeekUsd))}</div></div></div>` : "";
|
|
2366
2509
|
const dollarFixes = record.fixes.filter((f) => f.wasteUsd > 0).sort((a, b) => b.wasteUsd - a.wasteUsd);
|
|
2367
2510
|
const otherIssues = record.fixes.filter((f) => f.wasteUsd === 0);
|
|
2368
2511
|
const dollarSection = dollarFixes.length === 0 ? `<p class="muted">No directly recoverable dollars found. See issues below.</p>` : `<ul class="fixes">${dollarFixes.map(dollarFixCard).join("")}</ul>`;
|
|
@@ -2394,6 +2537,7 @@ ${planNote}
|
|
|
2394
2537
|
<div class="stat"><div class="k">Active hours</div><div class="v">${m.durationHours.toFixed(1)}</div></div>
|
|
2395
2538
|
${mix ? `<div class="stat"><div class="k">Model spend</div><div class="v v-small">${esc(mix)}</div></div>` : ""}
|
|
2396
2539
|
</div>
|
|
2540
|
+
${windowTiles}
|
|
2397
2541
|
|
|
2398
2542
|
<h2>Spend by project</h2>
|
|
2399
2543
|
<div class="chart">${projectChart(m.topProjects)}</div>
|
|
@@ -2605,7 +2749,8 @@ async function runAudit(opts) {
|
|
|
2605
2749
|
process.stderr.write(`Could not save the audit snapshot: ${err instanceof Error ? err.message : String(err)}
|
|
2606
2750
|
`);
|
|
2607
2751
|
}
|
|
2608
|
-
|
|
2752
|
+
const color = !opts.json && process.stdout.isTTY === true && !process.env["NO_COLOR"];
|
|
2753
|
+
let output = opts.json ? JSON.stringify(record, null, 2) : formatAudit(record, { root, sessionCount: logs.length, skipped, claudeMdSource, planSource }, color);
|
|
2609
2754
|
const notices = [];
|
|
2610
2755
|
if (snapshotNotice) notices.push(snapshotNotice);
|
|
2611
2756
|
if (opts.html) {
|
|
@@ -3621,14 +3766,16 @@ function planFlag(args) {
|
|
|
3621
3766
|
return value;
|
|
3622
3767
|
}
|
|
3623
3768
|
function parseAuditFlags(args) {
|
|
3624
|
-
const
|
|
3769
|
+
const json = args.includes("--json");
|
|
3770
|
+
const htmlExplicit = args.includes("--html");
|
|
3771
|
+
const html = args.includes("--no-html") ? false : htmlExplicit || !json;
|
|
3625
3772
|
const card = args.includes("--card");
|
|
3626
3773
|
return {
|
|
3627
3774
|
path: getFlag(args, "--path"),
|
|
3628
3775
|
claudeMdPath: getFlag(args, "--claude-md"),
|
|
3629
|
-
json
|
|
3776
|
+
json,
|
|
3630
3777
|
html,
|
|
3631
|
-
htmlPath:
|
|
3778
|
+
htmlPath: htmlExplicit ? optionalPathAfter(args, "--html") : void 0,
|
|
3632
3779
|
card,
|
|
3633
3780
|
cardPath: card ? optionalPathAfter(args, "--card") : void 0,
|
|
3634
3781
|
plan: planFlag(args)
|
|
@@ -3642,14 +3789,14 @@ function parseBadgeFlags(args) {
|
|
|
3642
3789
|
};
|
|
3643
3790
|
}
|
|
3644
3791
|
function cliVersion() {
|
|
3645
|
-
return true ? "0.
|
|
3792
|
+
return true ? "0.5.0" : "0.0.0-dev";
|
|
3646
3793
|
}
|
|
3647
3794
|
function helpText() {
|
|
3648
3795
|
return [
|
|
3649
3796
|
"CostClaw - privacy-first Claude Code cost and setup audit",
|
|
3650
3797
|
"",
|
|
3651
3798
|
"Usage:",
|
|
3652
|
-
" costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--card [file]]",
|
|
3799
|
+
" costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--no-html] [--card [file]]",
|
|
3653
3800
|
" costclaw diff [<baseline.json> <current.json>] [--json]",
|
|
3654
3801
|
" costclaw badge [--path <dir>] [--claude-md <file>] [--out <file>]",
|
|
3655
3802
|
" costclaw optimize [--path <dir>] [--claude-md <file>] [--project <dir>] [--out <dir>] [--write <file>] [--apply-settings [file]] [--force]",
|
|
@@ -3659,8 +3806,9 @@ function helpText() {
|
|
|
3659
3806
|
"",
|
|
3660
3807
|
"audit reads your Claude Code logs from ~/.claude/projects (or --path) on this",
|
|
3661
3808
|
"machine and prints a cost report plus a six-pillar setup score. It is free.",
|
|
3662
|
-
"
|
|
3663
|
-
"it in your browser;
|
|
3809
|
+
"By default it also writes a self-contained HTML report (costclaw-report.html)",
|
|
3810
|
+
"and opens it in your browser; --no-html skips that, --html <file> picks the",
|
|
3811
|
+
"path, and --json runs stay file-free unless --html is passed explicitly.",
|
|
3664
3812
|
"--card writes a shareable 600x315 score card SVG (default: costclaw-card.svg):",
|
|
3665
3813
|
"score, band, recoverable spend, cache hit rate, and your strongest pillar.",
|
|
3666
3814
|
"--plan <api|pro|max5x|max20x> declares how you pay for Claude. On a",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "costclaw",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Local cost and setup audit for Claude Code. Finds recoverable token spend and scores your setup across six pillars, with your prompts never leaving your machine.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|