kerf-cli 0.1.4 → 0.2.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/ARCHITECTURE.md +198 -0
- package/CHANGELOG.md +66 -11
- package/LAUNCH-POST.md +173 -0
- package/README.md +236 -52
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +13 -2
- package/USAGE.md +0 -644
package/README.md
CHANGED
|
@@ -5,13 +5,14 @@
|
|
|
5
5
|
> *kerf (n.) — the width of material removed by a cutting tool. Every token operation has a kerf.*
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/kerf-cli)
|
|
8
|
+
[](https://github.com/dhanushkumarsivaji/kerf-cli/actions/workflows/ci.yml)
|
|
8
9
|
[](LICENSE)
|
|
9
10
|
[]()
|
|
10
11
|
[]()
|
|
11
12
|
|
|
12
13
|
```
|
|
13
14
|
┌──────────────────────────────────────────────────────────────┐
|
|
14
|
-
│ kerf watch | session: a3f8c2d1... | 47 messages
|
|
15
|
+
│ kerf watch | session: a3f8c2d1... | 47 messages │
|
|
15
16
|
├──────────────────────────────────────────────────────────────┤
|
|
16
17
|
│ >> $4.82 / ~$15.00 window | $0.18/min | ~56m remaining │
|
|
17
18
|
│ [████████████░░░░░░░░░░░░░░░░░░] 38% | 76K / 200K tokens │
|
|
@@ -26,22 +27,88 @@
|
|
|
26
27
|
|
|
27
28
|
---
|
|
28
29
|
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
npx kerf-cli@latest init # Set up hooks & database
|
|
34
|
+
npx kerf-cli@latest watch # Real-time cost dashboard
|
|
35
|
+
npx kerf-cli@latest audit # Find ghost token waste
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
After global install (`npm i -g kerf-cli`), use the shorter `kerf` command:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
kerf watch
|
|
42
|
+
kerf estimate 'refactor auth'
|
|
43
|
+
kerf audit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> Both `kerf` and `kerf-cli` work as command names.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
29
50
|
## The Problem
|
|
30
51
|
|
|
31
52
|
> "20x Max plan exhausted in 19 minutes"
|
|
32
53
|
|
|
33
|
-
|
|
54
|
+
Claude Code sessions burn through tokens fast — context overhead, MCP tools, bloated CLAUDE.md files — and there's no way to see it in real time. kerf fixes that with live dashboards, pre-flight estimates, budgets, and ghost token auditing.
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# No install needed — run directly via npx
|
|
62
|
+
npx kerf-cli@latest --help
|
|
63
|
+
|
|
64
|
+
# Or install globally for the shorter 'kerf' command
|
|
65
|
+
npm install -g kerf-cli
|
|
66
|
+
kerf --help
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### First-time setup
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
kerf init
|
|
73
|
+
```
|
|
34
74
|
|
|
35
|
-
|
|
75
|
+
Creates `~/.kerf/` directory, initializes the SQLite database, and optionally installs Claude Code hooks for automatic tracking.
|
|
36
76
|
|
|
37
77
|
---
|
|
38
78
|
|
|
39
|
-
##
|
|
79
|
+
## Using With Claude Code
|
|
80
|
+
|
|
81
|
+
### Live monitoring (most common workflow)
|
|
82
|
+
|
|
83
|
+
Run Claude Code in one tab, kerf in another:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
Terminal Tab 1 (Claude Code): Terminal Tab 2 (kerf):
|
|
87
|
+
┌──────────────────────────┐ ┌──────────────────────────┐
|
|
88
|
+
│ $ claude │ │ $ kerf watch │
|
|
89
|
+
│ │ │ │
|
|
90
|
+
│ > Fix the auth bug in │ │ >> $1.20 / ~$8.00 window │
|
|
91
|
+
│ src/auth/login.ts │ │ [████░░░░░░] 18% │
|
|
92
|
+
│ │ │ │
|
|
93
|
+
│ I'll fix the auth bug... │ │ 10:30:02 2.1K $0.08 │
|
|
94
|
+
│ │ │ 10:30:45 3.4K $0.15 │
|
|
95
|
+
└──────────────────────────┘ └──────────────────────────┘
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Auto-detects the active session. Press `q` to quit, `b` to toggle budget view.
|
|
99
|
+
|
|
100
|
+
### Before starting work
|
|
40
101
|
|
|
41
102
|
```bash
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
103
|
+
kerf estimate 'refactor the auth module'
|
|
104
|
+
kerf budget show
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### End-of-day review
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
kerf report
|
|
111
|
+
kerf report --sessions
|
|
45
112
|
```
|
|
46
113
|
|
|
47
114
|
---
|
|
@@ -50,47 +117,92 @@ npx kerf-cli@latest audit # Find ghost token waste
|
|
|
50
117
|
|
|
51
118
|
### Real-Time Dashboard — `kerf watch`
|
|
52
119
|
|
|
53
|
-
Live cost monitoring
|
|
120
|
+
Live cost monitoring with burn rate, context usage, and projected costs. Refreshes every 2 seconds.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
kerf watch # auto-find active session
|
|
124
|
+
kerf watch --session abc123 # specific session
|
|
125
|
+
kerf watch --interval 5000 # slower refresh
|
|
126
|
+
```
|
|
54
127
|
|
|
55
|
-
### Pre-Flight Estimation — `kerf estimate
|
|
128
|
+
### Pre-Flight Estimation — `kerf estimate`
|
|
56
129
|
|
|
57
|
-
Know
|
|
130
|
+
Know what a task will cost before you start.
|
|
58
131
|
|
|
59
132
|
```bash
|
|
60
|
-
$
|
|
133
|
+
$ kerf estimate 'refactor auth module'
|
|
61
134
|
|
|
62
135
|
╭──────────────────────────────────────────────────────────╮
|
|
63
|
-
│ kerf estimate: 'refactor auth module'
|
|
136
|
+
│ kerf-cli estimate: 'refactor auth module' │
|
|
64
137
|
│ │
|
|
65
|
-
│ Model:
|
|
138
|
+
│ Model: sonnet │
|
|
66
139
|
│ Estimated turns: 15-40 (expected: 25) │
|
|
67
140
|
│ Context overhead: 62.7K tokens (ghost tokens) │
|
|
68
141
|
│ │
|
|
69
142
|
│ Estimated Cost: │
|
|
70
|
-
│ Low: $2.
|
|
71
|
-
│ Expected: $5.80 │
|
|
72
|
-
│ High: $12.40 │
|
|
143
|
+
│ Low: $1.60 Expected: $2.62 High: $4.43 │
|
|
73
144
|
│ │
|
|
74
|
-
│ -> Using Opus would cost ~$
|
|
145
|
+
│ -> Using Opus would cost ~$13.11 (5x more) │
|
|
75
146
|
╰──────────────────────────────────────────────────────────╯
|
|
76
147
|
```
|
|
77
148
|
|
|
149
|
+
Compare all models side by side:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
$ kerf estimate --compare 'add feature'
|
|
153
|
+
|
|
154
|
+
Model Turns Low Expected High
|
|
155
|
+
----------------------------------------------------------
|
|
156
|
+
sonnet 5-15 $0.67 $1.05 $1.45
|
|
157
|
+
opus 5-15 $3.35 $5.24 $7.26
|
|
158
|
+
haiku 5-15 $0.18 $0.28 $0.39
|
|
159
|
+
|
|
160
|
+
Cheapest: haiku at $0.28
|
|
161
|
+
Priciest: opus at $5.24
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Task complexity is auto-detected from keywords:
|
|
165
|
+
|
|
166
|
+
| Complexity | Keywords | Estimated Turns |
|
|
167
|
+
|-----------|----------|-----------------|
|
|
168
|
+
| Simple | typo, rename, delete | 2-5 |
|
|
169
|
+
| Medium | fix, add, update | 5-15 |
|
|
170
|
+
| Complex | refactor, rewrite, build, implement, migrate | 15-40 |
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
kerf estimate 'fix bug' --model opus # specific model
|
|
174
|
+
kerf estimate 'add auth' --files 'src/auth/*' # with file context
|
|
175
|
+
kerf estimate 'fix bug' --json # JSON output
|
|
176
|
+
```
|
|
177
|
+
|
|
78
178
|
### Per-Project Budgets — `kerf budget`
|
|
79
179
|
|
|
80
|
-
Set spending limits
|
|
180
|
+
Set spending limits with automatic warnings.
|
|
81
181
|
|
|
82
182
|
```bash
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
183
|
+
kerf budget set 50 --period weekly # set budget
|
|
184
|
+
kerf budget show # check status
|
|
185
|
+
kerf budget list # all projects
|
|
186
|
+
kerf budget remove # remove budget
|
|
187
|
+
```
|
|
188
|
+
|
|
86
189
|
```
|
|
190
|
+
kerf-cli budget
|
|
191
|
+
|
|
192
|
+
Period: weekly (2026-03-31 to 2026-04-06)
|
|
193
|
+
Budget: $50.00
|
|
194
|
+
Spent: $42.30
|
|
195
|
+
[████████████████░░░░] 84.6%
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
With hooks installed, you get warnings at 80% and alerts at 100%.
|
|
87
199
|
|
|
88
200
|
### Ghost Token Audit — `kerf audit`
|
|
89
201
|
|
|
90
|
-
Find
|
|
202
|
+
Find invisible token waste eating your context window.
|
|
91
203
|
|
|
92
204
|
```bash
|
|
93
|
-
$
|
|
205
|
+
$ kerf audit
|
|
94
206
|
|
|
95
207
|
Context Window Health: B (62% usable)
|
|
96
208
|
|
|
@@ -106,23 +218,89 @@ $ npx kerf-cli audit
|
|
|
106
218
|
2. [MED] Disable unused 'playwright' MCP server
|
|
107
219
|
```
|
|
108
220
|
|
|
221
|
+
**Grades:** A (>70% usable) | B (50-70%) | C (30-50%) | D (<30%)
|
|
222
|
+
|
|
223
|
+
**Ghost tokens** are context consumed before your conversation starts: system prompt, built-in tools, MCP tools (~600 tokens each), CLAUDE.md, and autocompact buffer.
|
|
224
|
+
|
|
225
|
+
**CLAUDE.md attention curve:** Claude's attention is U-shaped. Rules at 0-30% and 70-100% get high attention. The 30-70% middle is a "dead zone." kerf flags critical rules (NEVER, ALWAYS, MUST) stuck there.
|
|
226
|
+
|
|
227
|
+
```bash
|
|
228
|
+
kerf audit --claude-md-only # per-section breakdown with attention zones
|
|
229
|
+
kerf audit --mcp-only # MCP server analysis
|
|
230
|
+
kerf audit --json # machine-readable output
|
|
231
|
+
```
|
|
232
|
+
|
|
109
233
|
### Historical Reports — `kerf report`
|
|
110
234
|
|
|
111
|
-
Track spending over time with
|
|
235
|
+
Track spending over time with hourly charts and model breakdowns.
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
$ kerf report
|
|
239
|
+
|
|
240
|
+
kerf-cli report -- Sat, Apr 4, 2026
|
|
241
|
+
|
|
242
|
+
Total Cost: $12.77
|
|
243
|
+
Total Tokens: 906 in / 84.1K out
|
|
244
|
+
Cache Hit Rate: 100.0%
|
|
245
|
+
Sessions: 3
|
|
246
|
+
|
|
247
|
+
Hourly:
|
|
248
|
+
Apr 4, 2 AM █████░░░░░░░ $2.27
|
|
249
|
+
Apr 4, 1 PM █░░░░░░░░░░░ $0.50
|
|
250
|
+
Apr 4, 2 PM ████░░░░░░░░ $1.75
|
|
251
|
+
Apr 4, 6 PM ████████████ $5.64
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
kerf report --period week # weekly
|
|
256
|
+
kerf report --period month # monthly
|
|
257
|
+
kerf report --sessions --model # per-session + per-model breakdown
|
|
258
|
+
kerf report --csv > costs.csv # export CSV
|
|
259
|
+
kerf report --json # export JSON
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Hooks — Automatic Tracking
|
|
263
|
+
|
|
264
|
+
Claude Code hooks run automatically during sessions:
|
|
265
|
+
|
|
266
|
+
- **Notification hook:** Logs token usage to `~/.kerf/session-log.jsonl`
|
|
267
|
+
- **Stop hook:** Checks budget and warns at 80%, alerts at 100%
|
|
112
268
|
|
|
113
269
|
```bash
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
npx kerf-cli report --sessions # Per-session breakdown
|
|
270
|
+
kerf init # install hooks for current project
|
|
271
|
+
kerf init --global # install globally
|
|
272
|
+
kerf init --no-hooks # database only, skip hooks
|
|
118
273
|
```
|
|
119
274
|
|
|
120
275
|
---
|
|
121
276
|
|
|
122
|
-
##
|
|
277
|
+
## All Commands
|
|
278
|
+
|
|
279
|
+
| Command | Description |
|
|
280
|
+
|---------|-------------|
|
|
281
|
+
| `kerf watch` | Real-time cost dashboard (default) |
|
|
282
|
+
| `kerf estimate <task>` | Pre-flight cost estimation |
|
|
283
|
+
| `kerf estimate --compare <task>` | Compare Sonnet vs Opus vs Haiku |
|
|
284
|
+
| `kerf budget set <amt> --period weekly` | Set project budget |
|
|
285
|
+
| `kerf budget show` | Check budget status |
|
|
286
|
+
| `kerf budget list` | List all project budgets |
|
|
287
|
+
| `kerf budget remove` | Remove budget |
|
|
288
|
+
| `kerf audit` | Ghost token & CLAUDE.md audit |
|
|
289
|
+
| `kerf audit --claude-md-only` | CLAUDE.md section analysis |
|
|
290
|
+
| `kerf audit --mcp-only` | MCP server analysis |
|
|
291
|
+
| `kerf report` | Today's cost report |
|
|
292
|
+
| `kerf report --period week` | Weekly report |
|
|
293
|
+
| `kerf report --csv` | Export as CSV |
|
|
294
|
+
| `kerf init` | First-time setup |
|
|
295
|
+
|
|
296
|
+
> All commands work with both `kerf` and `kerf-cli`.
|
|
297
|
+
|
|
298
|
+
---
|
|
299
|
+
|
|
300
|
+
## Why kerf?
|
|
123
301
|
|
|
124
|
-
| Feature | kerf
|
|
125
|
-
|
|
302
|
+
| Feature | kerf | RTK | ccusage | token-optimizer |
|
|
303
|
+
|---------|------|-----|---------|-----------------|
|
|
126
304
|
| Real-time dashboard | Yes | No | No | No |
|
|
127
305
|
| Pre-flight estimation | Yes | No | No | No |
|
|
128
306
|
| Per-project budgets | Yes | No | No | No |
|
|
@@ -133,40 +311,46 @@ npx kerf-cli report --sessions # Per-session breakdown
|
|
|
133
311
|
|
|
134
312
|
**RTK compresses. ccusage tracks. kerf predicts.**
|
|
135
313
|
|
|
314
|
+
Works alongside RTK, ccusage, and ECC.
|
|
315
|
+
|
|
136
316
|
---
|
|
137
317
|
|
|
138
|
-
##
|
|
318
|
+
## Tips
|
|
139
319
|
|
|
140
|
-
- **
|
|
141
|
-
- **
|
|
142
|
-
- **
|
|
320
|
+
- **Use Sonnet for implementation, Opus for planning** — check with `kerf estimate --compare`
|
|
321
|
+
- **Keep CLAUDE.md under 200 lines** — audit with `kerf audit --claude-md-only`
|
|
322
|
+
- **Disable unused MCP servers** — each tool costs ~600 tokens
|
|
323
|
+
- **Monitor cache hit rate** — high rates (>80%) mean efficient context reuse
|
|
324
|
+
- **Set weekly budgets** — enough flexibility without runaway costs
|
|
143
325
|
|
|
144
326
|
---
|
|
145
327
|
|
|
146
|
-
##
|
|
328
|
+
## Troubleshooting
|
|
147
329
|
|
|
148
|
-
|
|
|
149
|
-
|
|
150
|
-
|
|
|
151
|
-
|
|
|
152
|
-
|
|
|
153
|
-
| `npx kerf-cli
|
|
154
|
-
|
|
|
155
|
-
|
|
|
156
|
-
| `npx kerf-cli audit --fix` | Auto-apply safe optimizations |
|
|
157
|
-
| `npx kerf-cli report` | Historical cost reports |
|
|
158
|
-
| `npx kerf-cli init` | Set up kerf (hooks, database) |
|
|
330
|
+
| Problem | Solution |
|
|
331
|
+
|---------|----------|
|
|
332
|
+
| "No active session found" | Ensure Claude Code is running and has sent a message |
|
|
333
|
+
| Dashboard shows no data | Send a message in Claude Code, wait for response |
|
|
334
|
+
| Costs seem wrong | kerf uses `total_cost_usd` from logs when available; estimates use heuristic |
|
|
335
|
+
| Command not found | Use `npx kerf-cli@latest` or `npm install -g kerf-cli` |
|
|
336
|
+
| Database errors | `rm ~/.kerf/kerf.db && kerf init` |
|
|
337
|
+
| Watch crashes | Must run in an interactive terminal, not piped |
|
|
159
338
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
339
|
+
---
|
|
340
|
+
|
|
341
|
+
## Architecture
|
|
342
|
+
|
|
343
|
+
See [ARCHITECTURE.md](ARCHITECTURE.md) for project structure, design decisions, data flow, and technology choices.
|
|
344
|
+
|
|
345
|
+
## Changelog
|
|
346
|
+
|
|
347
|
+
See [CHANGELOG.md](CHANGELOG.md) for version history.
|
|
164
348
|
|
|
165
349
|
---
|
|
166
350
|
|
|
167
351
|
## Contributing
|
|
168
352
|
|
|
169
|
-
Contributions welcome! Please open an issue first
|
|
353
|
+
Contributions welcome! Please open an issue first.
|
|
170
354
|
|
|
171
355
|
```bash
|
|
172
356
|
git clone https://github.com/dhanushkumarsivaji/kerf-cli.git
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/cli/index.ts
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
4
|
import { Command } from "commander";
|
|
6
5
|
|
|
7
6
|
// src/cli/commands/watch.ts
|
|
@@ -1783,10 +1782,8 @@ function installHooks(settingsPath) {
|
|
|
1783
1782
|
}
|
|
1784
1783
|
|
|
1785
1784
|
// src/cli/index.ts
|
|
1786
|
-
var require2 = createRequire(import.meta.url);
|
|
1787
|
-
var pkg = require2("../../package.json");
|
|
1788
1785
|
var program = new Command();
|
|
1789
|
-
program.name("kerf-cli").version(
|
|
1786
|
+
program.name("kerf-cli").version("0.2.0").description("Cost intelligence for Claude Code. Know before you spend.");
|
|
1790
1787
|
registerWatchCommand(program);
|
|
1791
1788
|
registerEstimateCommand(program);
|
|
1792
1789
|
registerBudgetCommand(program);
|