costclaw 0.4.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 +7 -5
- package/dist/index.js +66 -34
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -82,7 +82,7 @@ unit is framed to match how you actually pay.
|
|
|
82
82
|
## Options
|
|
83
83
|
|
|
84
84
|
```
|
|
85
|
-
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]]
|
|
86
86
|
```
|
|
87
87
|
|
|
88
88
|
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
@@ -91,10 +91,12 @@ costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--h
|
|
|
91
91
|
- `--plan <api|pro|max5x|max20x>` declare how you pay for Claude (see above);
|
|
92
92
|
persisted for later runs.
|
|
93
93
|
- `--json` print the raw, derived `AuditRecord` instead of the human report.
|
|
94
|
-
-
|
|
95
|
-
`costclaw-report.html` in the current directory)
|
|
96
|
-
|
|
97
|
-
|
|
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.
|
|
98
100
|
- `--card [file]` also write a shareable score card SVG (default
|
|
99
101
|
`costclaw-card.svg`): your score, band, recoverable spend, cache hit rate, and
|
|
100
102
|
strongest pillar. A static file, no fonts or network calls.
|
package/dist/index.js
CHANGED
|
@@ -2210,14 +2210,33 @@ async function readSessions(rootPath) {
|
|
|
2210
2210
|
return { logs, skipped };
|
|
2211
2211
|
}
|
|
2212
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
|
+
|
|
2213
2232
|
// src/format.ts
|
|
2214
2233
|
function usd2(n) {
|
|
2215
2234
|
return `$${(Math.round(n * 100) / 100).toFixed(2)}`;
|
|
2216
2235
|
}
|
|
2217
|
-
function bar(score, width = 20) {
|
|
2218
|
-
if (score === null) return "n/a";
|
|
2236
|
+
function bar(score, a, width = 20) {
|
|
2237
|
+
if (score === null) return a.dim("n/a");
|
|
2219
2238
|
const filled = Math.round(score / 100 * width);
|
|
2220
|
-
return `[${"#".repeat(filled)}${".".repeat(width - filled)}] ${score}`;
|
|
2239
|
+
return `[${a.score(score, "#".repeat(filled))}${a.dim(".".repeat(width - filled))}] ${a.bold(String(score))}`;
|
|
2221
2240
|
}
|
|
2222
2241
|
function shortModel(id) {
|
|
2223
2242
|
const m = /(opus|sonnet|haiku|fable)/i.exec(id);
|
|
@@ -2245,94 +2264,103 @@ function unassessedLine(pillars) {
|
|
|
2245
2264
|
});
|
|
2246
2265
|
return `Not yet scored: ${parts.join(" ")}`;
|
|
2247
2266
|
}
|
|
2248
|
-
function formatAudit(record, meta) {
|
|
2267
|
+
function formatAudit(record, meta, color = false) {
|
|
2268
|
+
const a = ansi(color);
|
|
2249
2269
|
const m = record.usageMetrics;
|
|
2250
2270
|
const subscription = record.plan !== void 0 && record.plan !== "api";
|
|
2251
2271
|
const share = record.headlineWasteShare ?? (m.spendUsd > 0 ? record.headlineWasteUsd / m.spendUsd : 0);
|
|
2252
2272
|
const shareText = `${(share * 100).toFixed(1)}%`;
|
|
2253
2273
|
const lines = [];
|
|
2254
|
-
lines.push("CostClaw audit");
|
|
2255
|
-
lines.push(`Source: ${meta.root} (${meta.sessionCount} sessions across ${m.projectsCount} projects)`);
|
|
2256
|
-
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}`));
|
|
2257
2277
|
lines.push("");
|
|
2258
2278
|
lines.push(
|
|
2259
|
-
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))}`
|
|
2260
2280
|
);
|
|
2261
2281
|
lines.push("");
|
|
2262
2282
|
lines.push(
|
|
2263
|
-
`${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))}`
|
|
2264
2284
|
);
|
|
2265
|
-
lines.push(`Pricing snapshot: ${m.pricingSnapshotDate}`);
|
|
2266
2285
|
const mix = modelMix(m.modelBreakdown);
|
|
2267
|
-
|
|
2286
|
+
lines.push(
|
|
2287
|
+
a.dim(`Pricing snapshot: ${m.pricingSnapshotDate}`) + (mix ? ` ${a.dim("Model spend:")} ${mix}` : "")
|
|
2288
|
+
);
|
|
2268
2289
|
const w = record.usageWindows;
|
|
2269
2290
|
if (subscription) {
|
|
2291
|
+
lines.push("");
|
|
2270
2292
|
lines.push(
|
|
2271
|
-
|
|
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
|
+
)
|
|
2272
2296
|
);
|
|
2273
2297
|
if (w?.assessed) {
|
|
2274
2298
|
lines.push(
|
|
2275
|
-
|
|
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)`
|
|
2276
2300
|
);
|
|
2277
2301
|
if (share >= 0.01 && share < 1) {
|
|
2278
2302
|
const gain = share / (1 - share);
|
|
2279
2303
|
const extraMinutes = Math.round(w.p90WindowActiveMinutes * gain);
|
|
2280
2304
|
lines.push(
|
|
2281
|
-
`Recovering ${shareText} buys about ${Math.round(gain * 100)}% more work per window: up to
|
|
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.`
|
|
2282
2306
|
);
|
|
2283
2307
|
}
|
|
2284
2308
|
}
|
|
2285
2309
|
} else if (meta.planSource === "default") {
|
|
2286
2310
|
const burn = w?.assessed && w.medianWeekUsd >= 50 ? ` Your median week burns ${usd2(w.medianWeekUsd)} at API rates.` : "";
|
|
2287
2311
|
lines.push(
|
|
2288
|
-
|
|
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
|
+
)
|
|
2289
2315
|
);
|
|
2290
2316
|
}
|
|
2291
2317
|
if (m.topProjects.length > 0) {
|
|
2292
2318
|
lines.push("");
|
|
2293
|
-
lines.push("Top projects by spend:");
|
|
2319
|
+
lines.push(a.bold("Top projects by spend:"));
|
|
2294
2320
|
for (const p of m.topProjects.slice(0, 5)) {
|
|
2295
2321
|
const name = p.slug.length > 30 ? p.slug.slice(0, 27) + "..." : p.slug;
|
|
2296
2322
|
const model = p.modelPrimary ? shortModel(p.modelPrimary) : "n/a";
|
|
2297
2323
|
lines.push(
|
|
2298
|
-
` ${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}`)}`
|
|
2299
2325
|
);
|
|
2300
2326
|
}
|
|
2301
2327
|
}
|
|
2302
2328
|
lines.push("");
|
|
2303
|
-
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
|
+
);
|
|
2304
2332
|
for (const p of record.pillarScores) {
|
|
2305
|
-
lines.push(` ${p.name.padEnd(22)} ${bar(p.score)}`);
|
|
2333
|
+
lines.push(` ${p.name.padEnd(22)} ${bar(p.score, a)}`);
|
|
2306
2334
|
}
|
|
2307
2335
|
lines.push("");
|
|
2308
2336
|
const dollarFixes = record.fixes.filter((f) => f.wasteUsd > 0);
|
|
2309
2337
|
const otherIssues = record.fixes.filter((f) => f.wasteUsd === 0);
|
|
2310
|
-
lines.push("Top fixes by recoverable spend:");
|
|
2338
|
+
lines.push(a.bold("Top fixes by recoverable spend:"));
|
|
2311
2339
|
if (dollarFixes.length === 0) {
|
|
2312
2340
|
lines.push(" No directly recoverable dollars found. See issues below.");
|
|
2313
2341
|
} else {
|
|
2314
2342
|
for (const f of dollarFixes) {
|
|
2315
|
-
lines.push(` - [${usd2(f.wasteUsd)}] ${f.title}`);
|
|
2343
|
+
lines.push(` - [${a.brand(usd2(f.wasteUsd))}] ${a.bold(f.title)}`);
|
|
2316
2344
|
lines.push(` ${f.action}`);
|
|
2317
|
-
if (f.basis) lines.push(` Evidence: ${f.basis}`);
|
|
2345
|
+
if (f.basis) lines.push(a.dim(` Evidence: ${f.basis}`));
|
|
2318
2346
|
}
|
|
2319
2347
|
}
|
|
2320
2348
|
if (otherIssues.length > 0) {
|
|
2321
2349
|
lines.push("");
|
|
2322
|
-
lines.push("Other issues to tighten:");
|
|
2350
|
+
lines.push(a.bold("Other issues to tighten:"));
|
|
2323
2351
|
for (const f of otherIssues) {
|
|
2324
2352
|
lines.push(` - ${f.title}`);
|
|
2325
|
-
if (f.basis) lines.push(` ${f.basis}`);
|
|
2353
|
+
if (f.basis) lines.push(a.dim(` ${f.basis}`));
|
|
2326
2354
|
}
|
|
2327
2355
|
}
|
|
2328
2356
|
if (meta.skipped.length > 0) {
|
|
2329
2357
|
lines.push("");
|
|
2330
|
-
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.`));
|
|
2331
2359
|
}
|
|
2332
2360
|
const gapLine = unassessedLine(record.pillarScores);
|
|
2333
2361
|
if (gapLine) {
|
|
2334
2362
|
lines.push("");
|
|
2335
|
-
lines.push(gapLine);
|
|
2363
|
+
lines.push(a.dim(gapLine));
|
|
2336
2364
|
}
|
|
2337
2365
|
return lines.join("\n");
|
|
2338
2366
|
}
|
|
@@ -2721,7 +2749,8 @@ async function runAudit(opts) {
|
|
|
2721
2749
|
process.stderr.write(`Could not save the audit snapshot: ${err instanceof Error ? err.message : String(err)}
|
|
2722
2750
|
`);
|
|
2723
2751
|
}
|
|
2724
|
-
|
|
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);
|
|
2725
2754
|
const notices = [];
|
|
2726
2755
|
if (snapshotNotice) notices.push(snapshotNotice);
|
|
2727
2756
|
if (opts.html) {
|
|
@@ -3737,14 +3766,16 @@ function planFlag(args) {
|
|
|
3737
3766
|
return value;
|
|
3738
3767
|
}
|
|
3739
3768
|
function parseAuditFlags(args) {
|
|
3740
|
-
const
|
|
3769
|
+
const json = args.includes("--json");
|
|
3770
|
+
const htmlExplicit = args.includes("--html");
|
|
3771
|
+
const html = args.includes("--no-html") ? false : htmlExplicit || !json;
|
|
3741
3772
|
const card = args.includes("--card");
|
|
3742
3773
|
return {
|
|
3743
3774
|
path: getFlag(args, "--path"),
|
|
3744
3775
|
claudeMdPath: getFlag(args, "--claude-md"),
|
|
3745
|
-
json
|
|
3776
|
+
json,
|
|
3746
3777
|
html,
|
|
3747
|
-
htmlPath:
|
|
3778
|
+
htmlPath: htmlExplicit ? optionalPathAfter(args, "--html") : void 0,
|
|
3748
3779
|
card,
|
|
3749
3780
|
cardPath: card ? optionalPathAfter(args, "--card") : void 0,
|
|
3750
3781
|
plan: planFlag(args)
|
|
@@ -3758,14 +3789,14 @@ function parseBadgeFlags(args) {
|
|
|
3758
3789
|
};
|
|
3759
3790
|
}
|
|
3760
3791
|
function cliVersion() {
|
|
3761
|
-
return true ? "0.
|
|
3792
|
+
return true ? "0.5.0" : "0.0.0-dev";
|
|
3762
3793
|
}
|
|
3763
3794
|
function helpText() {
|
|
3764
3795
|
return [
|
|
3765
3796
|
"CostClaw - privacy-first Claude Code cost and setup audit",
|
|
3766
3797
|
"",
|
|
3767
3798
|
"Usage:",
|
|
3768
|
-
" 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]]",
|
|
3769
3800
|
" costclaw diff [<baseline.json> <current.json>] [--json]",
|
|
3770
3801
|
" costclaw badge [--path <dir>] [--claude-md <file>] [--out <file>]",
|
|
3771
3802
|
" costclaw optimize [--path <dir>] [--claude-md <file>] [--project <dir>] [--out <dir>] [--write <file>] [--apply-settings [file]] [--force]",
|
|
@@ -3775,8 +3806,9 @@ function helpText() {
|
|
|
3775
3806
|
"",
|
|
3776
3807
|
"audit reads your Claude Code logs from ~/.claude/projects (or --path) on this",
|
|
3777
3808
|
"machine and prints a cost report plus a six-pillar setup score. It is free.",
|
|
3778
|
-
"
|
|
3779
|
-
"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.",
|
|
3780
3812
|
"--card writes a shareable 600x315 score card SVG (default: costclaw-card.svg):",
|
|
3781
3813
|
"score, band, recoverable spend, cache hit rate, and your strongest pillar.",
|
|
3782
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": {
|