costclaw 0.10.0 → 0.12.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/README.md +326 -303
- package/dist/index.js +855 -127
- package/package.json +1 -6
package/README.md
CHANGED
|
@@ -1,303 +1,326 @@
|
|
|
1
|
-
# costclaw
|
|
2
|
-
|
|
3
|
-
A local cost and setup audit for [Claude Code](https://claude.com/claude-code).
|
|
4
|
-
Point it at your session logs and it shows where token spend leaks, scores your
|
|
5
|
-
setup across six pillars, and ranks fixes by the dollars they recover.
|
|
6
|
-
|
|
7
|
-
Your prompts never leave your machine. The audit parses the logs already on your
|
|
8
|
-
disk and prints a report. It uploads nothing.
|
|
9
|
-
|
|
10
|
-
## Use it
|
|
11
|
-
|
|
12
|
-
Requires Node 20+.
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
npx costclaw audit
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
That reads `~/.claude/projects` (override with `--path <dir>`) and prints:
|
|
19
|
-
|
|
20
|
-
```
|
|
21
|
-
CostClaw audit
|
|
22
|
-
Source: ~/.claude/projects (N sessions across M projects)
|
|
23
|
-
CLAUDE.md: ~/.claude/CLAUDE.md
|
|
24
|
-
|
|
25
|
-
Recoverable spend (cache-miss exposure): $XXX.XX
|
|
26
|
-
|
|
27
|
-
Spend analyzed: $X,XXX.XX Cache hit: 96.3% Active hours: XXX.X
|
|
28
|
-
Model spend: opus 71% / sonnet 24% / haiku 5%
|
|
29
|
-
|
|
30
|
-
Top projects by spend:
|
|
31
|
-
C--Projects-demo $XXX.XX 312 sessions cache 96.4% opus
|
|
32
|
-
|
|
33
|
-
Burn Clock (spend by day):
|
|
34
|
-
Monday [###########.........] $XXX.XX
|
|
35
|
-
...
|
|
36
|
-
Friday [####################] $X,XXX.XX
|
|
37
|
-
|
|
38
|
-
Friday is your most expensive day ($X,XXX.XX), about 2.0x an average day across
|
|
39
|
-
42 active days. Peak stretch: Friday morning.
|
|
40
|
-
|
|
41
|
-
Overall setup score: 91 / 100 (Dialed in)
|
|
42
|
-
CLAUDE.md quality [#################...] 85
|
|
43
|
-
Context hygiene [###################.] 95
|
|
44
|
-
Prompting patterns [##################..] 92
|
|
45
|
-
Session management [####################] 100
|
|
46
|
-
Tool and MCP config [####################] 100
|
|
47
|
-
Cost discipline [##############......] 70
|
|
48
|
-
|
|
49
|
-
Top fixes by recoverable spend:
|
|
50
|
-
- [$XXX.XX] Recover spend lost to cache misses
|
|
51
|
-
Your longest sessions started at 71% cache reuse and finished at 9%.
|
|
52
|
-
Compact or start a fresh session before the context outgrows the cache.
|
|
53
|
-
Evidence: XX% of input tokens missed the cache across N sessions.
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
The cache fix names the specific reason your cache is missing, picked from what
|
|
57
|
-
your logs actually show: sessions whose cache decayed as they ran, a `CLAUDE.md`
|
|
58
|
-
churning with dates and TODOs, or a project that keeps starting cold. Burn Clock
|
|
59
|
-
needs at least 7 active days of logs; below that it is left out rather than
|
|
60
|
-
guessed at.
|
|
61
|
-
|
|
62
|
-
## On a subscription? Declare your plan
|
|
63
|
-
|
|
64
|
-
Every dollar the audit prints is an API-equivalent price: what those tokens
|
|
65
|
-
would cost at pay-as-you-go rates. On a Claude subscription (Pro or Max) your
|
|
66
|
-
marginal token cost is zero, so those dollars are not money back - they measure
|
|
67
|
-
your rate-limit headroom.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
- `--
|
|
109
|
-
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
`
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
`
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
`
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
1
|
+
# costclaw
|
|
2
|
+
|
|
3
|
+
A local cost and setup audit for [Claude Code](https://claude.com/claude-code).
|
|
4
|
+
Point it at your session logs and it shows where token spend leaks, scores your
|
|
5
|
+
setup across six pillars, and ranks fixes by the dollars they recover.
|
|
6
|
+
|
|
7
|
+
Your prompts never leave your machine. The audit parses the logs already on your
|
|
8
|
+
disk and prints a report. It uploads nothing.
|
|
9
|
+
|
|
10
|
+
## Use it
|
|
11
|
+
|
|
12
|
+
Requires Node 20+.
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx costclaw audit
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
That reads `~/.claude/projects` (override with `--path <dir>`) and prints:
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
CostClaw audit
|
|
22
|
+
Source: ~/.claude/projects (N sessions across M projects)
|
|
23
|
+
CLAUDE.md: ~/.claude/CLAUDE.md
|
|
24
|
+
|
|
25
|
+
Recoverable spend (cache-miss exposure): $XXX.XX
|
|
26
|
+
|
|
27
|
+
Spend analyzed: $X,XXX.XX Cache hit: 96.3% Active hours: XXX.X
|
|
28
|
+
Model spend: opus 71% / sonnet 24% / haiku 5%
|
|
29
|
+
|
|
30
|
+
Top projects by spend:
|
|
31
|
+
C--Projects-demo $XXX.XX 312 sessions cache 96.4% opus
|
|
32
|
+
|
|
33
|
+
Burn Clock (spend by day):
|
|
34
|
+
Monday [###########.........] $XXX.XX
|
|
35
|
+
...
|
|
36
|
+
Friday [####################] $X,XXX.XX
|
|
37
|
+
|
|
38
|
+
Friday is your most expensive day ($X,XXX.XX), about 2.0x an average day across
|
|
39
|
+
42 active days. Peak stretch: Friday morning.
|
|
40
|
+
|
|
41
|
+
Overall setup score: 91 / 100 (Dialed in)
|
|
42
|
+
CLAUDE.md quality [#################...] 85
|
|
43
|
+
Context hygiene [###################.] 95
|
|
44
|
+
Prompting patterns [##################..] 92
|
|
45
|
+
Session management [####################] 100
|
|
46
|
+
Tool and MCP config [####################] 100
|
|
47
|
+
Cost discipline [##############......] 70
|
|
48
|
+
|
|
49
|
+
Top fixes by recoverable spend:
|
|
50
|
+
- [$XXX.XX] Recover spend lost to cache misses
|
|
51
|
+
Your longest sessions started at 71% cache reuse and finished at 9%.
|
|
52
|
+
Compact or start a fresh session before the context outgrows the cache.
|
|
53
|
+
Evidence: XX% of input tokens missed the cache across N sessions.
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
The cache fix names the specific reason your cache is missing, picked from what
|
|
57
|
+
your logs actually show: sessions whose cache decayed as they ran, a `CLAUDE.md`
|
|
58
|
+
churning with dates and TODOs, or a project that keeps starting cold. Burn Clock
|
|
59
|
+
needs at least 7 active days of logs; below that it is left out rather than
|
|
60
|
+
guessed at.
|
|
61
|
+
|
|
62
|
+
## On a subscription? Declare your plan
|
|
63
|
+
|
|
64
|
+
Every dollar the audit prints is an API-equivalent price: what those tokens
|
|
65
|
+
would cost at pay-as-you-go rates. On a Claude subscription (Pro or Max) your
|
|
66
|
+
marginal token cost is zero, so those dollars are not money back - they measure
|
|
67
|
+
your rate-limit headroom.
|
|
68
|
+
|
|
69
|
+
The first interactive run asks which one you are on and remembers the answer, so
|
|
70
|
+
usually there is nothing to do. To set it directly, or to change it later:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npx costclaw audit --plan max20x # or pro, max5x; --plan api switches back
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Piped runs, `--json` and CI are never asked and assume API rates, so a scripted
|
|
77
|
+
audit never blocks waiting for an answer.
|
|
78
|
+
|
|
79
|
+
The headline becomes recoverable usage - the share of your token consumption
|
|
80
|
+
you could win back - with the dollars demoted to API-equivalent context:
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
Recoverable usage (cache-miss exposure): 14.3% of analyzed usage ($1134.61 at API rates)
|
|
84
|
+
|
|
85
|
+
Usage analyzed (API-equivalent): $7921.99 Cache hit: 96.2% Active hours: 1889.7
|
|
86
|
+
Plan: max20x. Dollar figures are API-equivalent token value, not money back;
|
|
87
|
+
recovering them buys rate-limit headroom (more work per usage window).
|
|
88
|
+
Usage windows (5h, like your rate limit): median $8.10, busiest $34.20; busiest week $310.55 (API-equivalent)
|
|
89
|
+
Recovering 14.3% buys about 17% more work per window: up to ~42 extra minutes in a window like your busiest.
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The usage windows are modeled from your own activity timestamps, mirroring how
|
|
93
|
+
the limits actually work: a 5-hour window opens at your first activity, and a
|
|
94
|
+
weekly cap sits above it. Nothing is assumed about Anthropic's actual budgets;
|
|
95
|
+
everything is relative to your observed consumption ("busiest" is the 90th
|
|
96
|
+
percentile window, so one freak outlier does not set the bar).
|
|
97
|
+
|
|
98
|
+
The value is saved to `~/.costclaw/config.json`, so later runs (and `optimize`)
|
|
99
|
+
remember it. The findings and their ranking are identical either way; only the
|
|
100
|
+
unit is framed to match how you actually pay.
|
|
101
|
+
|
|
102
|
+
## Options
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
costclaw audit [--path <dir>] [--claude-md <file>] [--plan <plan>] [--json] [--html [file]] [--no-html] [--card [file]]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
- `--path <dir>` audit a specific projects directory (default `~/.claude/projects`).
|
|
109
|
+
- `--claude-md <file>` score a specific CLAUDE.md file's quality (by default the
|
|
110
|
+
audit scores `~/.claude/CLAUDE.md` when it exists).
|
|
111
|
+
- `--plan <api|pro|max5x|max20x>` declare how you pay for Claude (see above);
|
|
112
|
+
persisted for later runs.
|
|
113
|
+
- `--json` print the raw, derived `AuditRecord` instead of the human report.
|
|
114
|
+
- The HTML report is written and opened in your browser **by default**
|
|
115
|
+
(`costclaw-report.html` in the current directory). The file inlines
|
|
116
|
+
everything, so nothing is fetched and nothing is uploaded; the terminal
|
|
117
|
+
report still prints (in color on interactive terminals; set `NO_COLOR` to
|
|
118
|
+
disable). `--html <file>` picks the path; `--no-html` skips the file;
|
|
119
|
+
`--json` runs stay file-free unless `--html` is passed explicitly. Set
|
|
120
|
+
`COSTCLAW_NO_OPEN=1` to write reports without launching a browser (CI and
|
|
121
|
+
test runners are detected and never open one). The report ends with a
|
|
122
|
+
"What to do next" ramp: the commands to run next, how the optimize license
|
|
123
|
+
works, and a command reference.
|
|
124
|
+
- `--card [file]` also write a shareable score card SVG (default
|
|
125
|
+
`costclaw-card.svg`): your score, band, recoverable spend, cache hit rate, and
|
|
126
|
+
strongest pillar. A static file, no fonts or network calls.
|
|
127
|
+
|
|
128
|
+
Run `costclaw --version` (or `-v` / `costclaw version`) to print the installed
|
|
129
|
+
CLI version.
|
|
130
|
+
|
|
131
|
+
## Diff
|
|
132
|
+
|
|
133
|
+
Every audit run saves a snapshot of the derived record to `~/.costclaw/history`
|
|
134
|
+
(local, nothing uploaded). Run the audit again after you have made changes, then:
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
npx costclaw diff
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
That compares your latest two audits and shows the movement, so you can verify
|
|
141
|
+
the fixes actually recovered dollars:
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
CostClaw diff
|
|
145
|
+
Baseline: 2026-06-09 Current: 2026-07-09 (30 days)
|
|
146
|
+
|
|
147
|
+
Since the baseline:
|
|
148
|
+
New spend $842.10 across 210 new sessions
|
|
149
|
+
Marginal cache hit 97.1% (lifetime 96.2%)
|
|
150
|
+
Recoverable exposure +$96.40 (now $1131.61)
|
|
151
|
+
|
|
152
|
+
Overall setup score: 83 -> 86 (+3, Tight)
|
|
153
|
+
CLAUDE.md quality 69 -> 78 (+9)
|
|
154
|
+
...
|
|
155
|
+
|
|
156
|
+
Fixes resolved since the baseline:
|
|
157
|
+
- [$52.40] Use a cheaper model for 61 small sessions
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
The marginal cache hit rate covers only the period between the two audits, which
|
|
161
|
+
a lifetime average hides. You can also diff two explicit records saved with
|
|
162
|
+
`costclaw audit --json`: `costclaw diff baseline.json current.json`. Add `--json`
|
|
163
|
+
for the machine-readable diff. Free, like the audit. The history keeps the newest
|
|
164
|
+
50 snapshots and prunes older ones automatically.
|
|
165
|
+
|
|
166
|
+
## Badge
|
|
167
|
+
|
|
168
|
+
```bash
|
|
169
|
+
npx costclaw badge
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Runs a fresh audit and writes a shields.io-style badge SVG (default
|
|
173
|
+
`costclaw-badge.svg`): a "costclaw" segment and your overall score, colored by
|
|
174
|
+
its band. Drop it in a README with a plain image tag:
|
|
175
|
+
|
|
176
|
+
```markdown
|
|
177
|
+

|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
costclaw badge [--path <dir>] [--claude-md <file>] [--out <file>]
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Optimize
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
npx costclaw optimize
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Generates, for every project your audit saw, five artifacts: an optimized
|
|
191
|
+
`CLAUDE.md` scaffold, a prioritized fix playbook, a conservative,
|
|
192
|
+
project-derived `settings.suggested.json` permission allowlist, a
|
|
193
|
+
`HARNESS-UPGRADE.md` work order for your own Claude Code, and `costclaw.md`
|
|
194
|
+
(the generated sections as a standalone include). It never writes inside a
|
|
195
|
+
project; only `costclaw apply` does that, and only on an explicit command.
|
|
196
|
+
|
|
197
|
+
It also reviews the files themselves. The dashboard shows your global
|
|
198
|
+
`~/.claude/CLAUDE.md`, plus every file it imports with an `@path` line, and each
|
|
199
|
+
project's `CLAUDE.md` annotated line by line: what to remove (the generated
|
|
200
|
+
include now carries it, or the global file already says it), what to move out
|
|
201
|
+
(dated and status text, a paragraph that names only one project), and what to
|
|
202
|
+
add (a short, evidence-backed block, never a placeholder). Above that sits one
|
|
203
|
+
prompt, `UPGRADE-ALL.md`, covering the global file and every project at once:
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
claude "Follow ~/.costclaw/optimize/UPGRADE-ALL.md"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
It states each file's per-turn token total before and after the proposed
|
|
210
|
+
changes, and no target line count anywhere. A project with no `CLAUDE.md` of its
|
|
211
|
+
own now reports no "before" instead of comparing against your global file, which
|
|
212
|
+
was never that project's text.
|
|
213
|
+
|
|
214
|
+
By default it runs globally: it ranks your audited projects by spend,
|
|
215
|
+
generates for the top ones (cap 10; override with `--limit N`) into
|
|
216
|
+
`~/.costclaw/optimize/<project>/`, writes `UPGRADE-ALL.md` and one
|
|
217
|
+
`DASHBOARD.html` index at the root
|
|
218
|
+
listing every project with its receipt and apply line, plus a local
|
|
219
|
+
click-to-apply page you can use instead of the command line (Ctrl+C, the
|
|
220
|
+
page's Done button, or `--no-serve` to skip it). `--project <dir>` keeps the
|
|
221
|
+
single-project behavior, writing into `./costclaw-out` (or `--out <dir>`)
|
|
222
|
+
instead. `--no-dashboard` skips the HTML.
|
|
223
|
+
|
|
224
|
+
And it tells you what it actually did to the file that rides on every turn:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
Your CLAUDE.md: an estimated 5,266 tokens to 2,479 (52.9% smaller), paid on every turn.
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
costclaw never calls a model, so it does not rewrite your prose: your own sections
|
|
231
|
+
are carried through exactly as written. When that carried prose is most of what is
|
|
232
|
+
left, the receipt says so rather than presenting a small percentage as a win:
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
About 1,714 of those tokens are your own prose, carried through as written.
|
|
236
|
+
costclaw does not rewrite prose, so trimming it is judgment work: HARNESS-UPGRADE.md
|
|
237
|
+
ranks your heaviest sections and flags the dated lines to move into docs/.
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
`HARNESS-UPGRADE.md` is the fourth artifact: a work order you hand to your own
|
|
241
|
+
Claude Code (`claude "Follow costclaw-out/HARNESS-UPGRADE.md"`). It carries the
|
|
242
|
+
merge and permission tasks plus evidence-conditional ones, and when your carried
|
|
243
|
+
prose is heavy it ranks it so the trimming is a worklist instead of a guess:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
Heaviest carried sections, largest first:
|
|
247
|
+
|
|
248
|
+
- Core Philosophy: est. 1,382 tokens.
|
|
249
|
+
- How to Work: est. 1,267 tokens, 2 dated lines.
|
|
250
|
+
- Communication and Output: est. 550 tokens, 3 dated lines.
|
|
251
|
+
|
|
252
|
+
The remaining 6 carried sections account for the other 1,880 tokens.
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Those rows plus the remainder line add up to the stated total, the same way the
|
|
256
|
+
playbook's per-project table reconciles. costclaw sets no target line count
|
|
257
|
+
anywhere: it measures what your sections cost and which lines carry dates, and
|
|
258
|
+
leaves the keep-or-move judgment to you.
|
|
259
|
+
|
|
260
|
+
The playbook breaks the recoverable headline down by project, so you can see
|
|
261
|
+
which repo owes which dollars and at what cache hit rate:
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
### Where that money is
|
|
265
|
+
|
|
266
|
+
| Project | Recoverable | Cache hit | Main sessions |
|
|
267
|
+
| --- | --- | --- | --- |
|
|
268
|
+
| some-app | $490.43 | 98% | 229 |
|
|
269
|
+
| another-app | $312.43 | 99% | 131 |
|
|
270
|
+
|
|
271
|
+
39 smaller projects account for the remaining $172.06.
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
The rows plus that remainder line always add up to the headline figure above
|
|
275
|
+
them, so the breakdown reconciles rather than approximating.
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
costclaw optimize [--path <dir>] [--claude-md <file>] [--project <dir>] [--out <dir>] [--limit <n>] [--no-dashboard] [--no-serve] [--force]
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Apply
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
npx costclaw apply
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The only command that writes inside a project, and only additively. Run it
|
|
288
|
+
from inside the project, or pass a directory:
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
costclaw apply [<dir>] [--remove] [--replace] [--apply-settings [file]] [--from <dir>] [--force]
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
- Default mode writes the generated sections to `.claude/costclaw.md` and adds
|
|
295
|
+
one `@.claude/costclaw.md` import line (Claude Code's memory import syntax)
|
|
296
|
+
to your `CLAUDE.md`. Every line you wrote stays exactly as it was. Idempotent:
|
|
297
|
+
running it again rewrites the include and leaves the import line alone.
|
|
298
|
+
- `--remove` undoes it: deletes `.claude/costclaw.md` and `.claude/costclaw/`,
|
|
299
|
+
and strips the import line (only that exact generated line).
|
|
300
|
+
- `--replace` is the old wholesale rewrite. It requires a git repository (a
|
|
301
|
+
`.git` directory in the project), so the undo is `git checkout -- CLAUDE.md`;
|
|
302
|
+
outside git it refuses. It still keeps a `.bak` as a second net, refusing to
|
|
303
|
+
overwrite an existing one without `--force`.
|
|
304
|
+
- `--apply-settings [file]` additively merges the derived permission allowlist
|
|
305
|
+
into your Claude Code settings. Opt-in: it only touches
|
|
306
|
+
`permissions.allow` and `permissions.deny` (a deduped union that keeps your
|
|
307
|
+
existing entries and orders them first) and never removes or changes any other
|
|
308
|
+
key. The default target is the project's `.claude/settings.json`; pass
|
|
309
|
+
`[file]` to target another. It backs up the previous file to `<target>.bak`,
|
|
310
|
+
prints a diff, then writes pretty JSON. A missing target is created; a file it
|
|
311
|
+
cannot `JSON.parse` (for example JSONC with comments) is refused and left
|
|
312
|
+
untouched.
|
|
313
|
+
- `--from <dir>` points at a specific artifacts folder instead of looking one
|
|
314
|
+
up by project. Without it, `apply` finds artifacts from the last `optimize`
|
|
315
|
+
run, or generates them cold (into `./costclaw-out`) if none exist yet.
|
|
316
|
+
- `--force` allows overwriting an existing `.bak` backup for `--replace` and
|
|
317
|
+
`--apply-settings`.
|
|
318
|
+
|
|
319
|
+
`optimize` and `apply` need a one-time license (`costclaw activate <key>`);
|
|
320
|
+
`audit` is free.
|
|
321
|
+
|
|
322
|
+
## Privacy
|
|
323
|
+
|
|
324
|
+
The only thing the tool produces is a derived `AuditRecord`: totals and generated
|
|
325
|
+
prose, no prompt text, no file paths, no secrets. A hosted dashboard is on the
|
|
326
|
+
roadmap and would receive only that derived record, never your logs.
|