@useanvil/claude-code 0.8.1 → 0.9.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/CHANGELOG.md +217 -1
- package/dist/claude-conditions.js +6 -6
- package/dist/claude-hook-core.js +84 -82
- package/dist/claude-hook.js +37 -35
- package/dist/claude-meter.js +55 -35
- package/dist/claude-sync.js +26 -24
- package/dist/cli/claude-main.js +7873 -1373
- package/docs/coding-agents/YOUR-RULES.md +293 -49
- package/package.json +1 -1
|
@@ -95,6 +95,7 @@ Can't yet, and the closest rule offered:
|
|
|
95
95
|
| `hold Gmail and Slack changes` | One app per rule. | `hold: Gmail changes` and `hold: Slack changes` |
|
|
96
96
|
| `hold Strype changes` | No app called "Strype" is connected here. | `hold: Stripe changes` |
|
|
97
97
|
| `never more than 5 Stripe refunds a day` | A rule doesn't count, a cap does. | `cap: at most 5 Stripe refunds a day` |
|
|
98
|
+
| `never more than 100 deploys a day` | A rule doesn't count, a cap does (typed; a line written by hand in rules.md keeps the rule on every deploy). | `cap: at most 100 deploys a day` |
|
|
98
99
|
| `hold deploys to staging` | Anvil holds by production, not staging. | `hold: deploy` |
|
|
99
100
|
| `hold Zorblax invoices` | Anvil doesn't know an app called "Zorblax", and none by that name is connected here: connect it to Claude Code, then add the rule. | none |
|
|
100
101
|
| `hold Stripe reads` | Anvil holds what Stripe changes: its reads always run. | none |
|
|
@@ -118,6 +119,51 @@ Claude posts in #general" watch. "Without asking" or "without my OK" makes a rul
|
|
|
118
119
|
OK" keeps it a block. Only the asking is taken off: an amount, a recipient, a part or a time said inside it is read
|
|
119
120
|
as it would be said plainly, never dropped.
|
|
120
121
|
|
|
122
|
+
#### Enter reads it back, part by part
|
|
123
|
+
|
|
124
|
+
Where Claude Code is installed, enter reads what you typed back before anything is saved. "Block deploys. Publishes
|
|
125
|
+
too." is two rules; a part Anvil can't make a rule of is listed as "Not covered yet" beside your own words. Enter again
|
|
126
|
+
adds the rules (`e` edits, `a` adds one more, esc drops it). The box reads each part itself, and asks your Claude Code
|
|
127
|
+
(Haiku, through your own login) only for a part it can't read. One rule the box reads whole, with nothing else said,
|
|
128
|
+
is added at once.
|
|
129
|
+
|
|
130
|
+
On two fresh sealed sets of plain speech it read 71 and 68 of 90 right, against 40 and 32 for the box alone, and left
|
|
131
|
+
far fewer parts unsaid. `ANVIL_READBACK=0` turns it off; with no Claude Code, or `--no-model`, the box answers on its
|
|
132
|
+
own as before.
|
|
133
|
+
|
|
134
|
+
#### When the box can't say it: your Claude Code rewrites it (held, not on yet)
|
|
135
|
+
|
|
136
|
+
Held: on two fresh sealed sets of plain speech the step made no rule lost or softer, but read too few right (66/90 and
|
|
137
|
+
32/90; the bar is 79), and attacks still find softer rewrites it would offer. `ANVIL_REWRITE_STEP=1` turns it on to try
|
|
138
|
+
it; without it, enter reads the words back (above) or the box answers as before, tab adds nothing, and `rules import` uses neither
|
|
139
|
+
the step nor the box's reading (below; it writes each line in the box's words, the asking taken off). What it does
|
|
140
|
+
when on:
|
|
141
|
+
|
|
142
|
+
Enter on words the box answers ? **Can't yet** for, can't place, or isn't sure it read whole asks your own Claude Code
|
|
143
|
+
(Haiku, through your own login: one call, no tools, from an empty folder) to say them as one rules.md line. The box says
|
|
144
|
+
"Your Claude Code is rewriting it" while it waits; esc stops it. The line it writes is read by the box itself, as if you
|
|
145
|
+
had typed it, and shown with what it will do before anything is added: "✓ Your Claude Code rewrote it: hold: slack
|
|
146
|
+
posts in #deploys", then "Slack posts in #deploys wait for your OK", enter adds it.
|
|
147
|
+
|
|
148
|
+
It is offered only when it is no softer than what you typed. The box's own answer stays when the line would:
|
|
149
|
+
- weaken the verb you said ("never stop blocking …" and "I'll never approve …" stay blocks; "let me cancel them first"
|
|
150
|
+
stays a hold), or keep a hold where no reader can tell how you asked;
|
|
151
|
+
- leave out, turn around or add a condition: over stays over, outside stays outside, who it goes to never becomes who
|
|
152
|
+
sends it, what it mentions or whose people they are; "or" between two conditions never becomes both at once;
|
|
153
|
+
- be narrower than your words: an example, an exception or what you let through made the rule ("hold every Stripe
|
|
154
|
+
change over $500, think refunds"), a rule you said holds every one narrowed ("whatever the amount — over $500 is what
|
|
155
|
+
scares me"), one more thing you added left out ("payouts are just as bad");
|
|
156
|
+
- name another app, change, kind, part or target, or a part your words only relate to ("billing-api forks");
|
|
157
|
+
- keep an amount of something else ("refunds on any order over $500"), a total ("over $500 in a given week") or a rough
|
|
158
|
+
amount as one change's, a time said in another zone or place ("after 6pm pacific"), or a span of days as single days.
|
|
159
|
+
|
|
160
|
+
What it left out must be a story or a reason. A closest it gives for words it can't say whole is offered only when it is
|
|
161
|
+
broader than the words and no wider than the box's own. With no Claude Code here, the box answers as before.
|
|
162
|
+
|
|
163
|
+
The box also looks twice at what it reads by itself: where its own reading would be refused had your Claude Code
|
|
164
|
+
written it ("it keeps posting in the deploys channel on slack" read as every deploy; "over $500 or after 6pm" read as
|
|
165
|
+
both at once), it says "Anvil isn't sure it read all of that", enter asks your Claude Code, and tab adds what the box read.
|
|
166
|
+
|
|
121
167
|
### Conditions: an amount
|
|
122
168
|
|
|
123
169
|
A rule on a money app's money changes (refunds, charges, payments, payouts, transfers) can hold only the big ones.
|
|
@@ -225,18 +271,23 @@ Every screen that shows a limit says what it does now, or why it can't: "can't b
|
|
|
225
271
|
| Limit | Needs | Where it can't work, the screens say |
|
|
226
272
|
|---|---|---|
|
|
227
273
|
| your rules, caps, a helper's model | Claude Code 2.1.295 or later | |
|
|
228
|
-
| a model rule (`model: opus for deploys`) | Claude Code 2.1.304 or later
|
|
229
|
-
| a budget that refuses the next message, a task budget
|
|
274
|
+
| a model rule (`model: opus for deploys`) | Claude Code 2.1.304 or later records each request's model; before it, only the reply that carries the call is read, where it is written as it streams (the desktop app, headless runs), never in the terminal | "under Claude Code 2.1.300 (its path) it can't hear the model in the terminal, only where replies are written as they stream" |
|
|
275
|
+
| a budget that refuses the next message, a task budget | Claude Code 2.1.153 or later, on every Claude Code `anvil claude on` finds | an older one, by version and path, and "update it, then run anvil claude on" |
|
|
276
|
+
| `model: never …` refusing a switch | Claude Code 2.1.251 or later (PreModelSwitch); a message on that model is refused from 2.1.153 | "refused: a message on it, and a switch to it except under Claude Code 2.1.200 (its path)", with its update command |
|
|
277
|
+
| a cap on helpers at once | Claude Code 2.1.318 or later (it reports helpers starting and stopping) | "except under Claude Code 2.1.300 (its path)", with its update command |
|
|
230
278
|
| a plan budget (`80% of my weekly limit`) | a reading of your plan: Claude Code's status line, or its `/usage`, which Anvil asks | why there is none, and the fix (below) |
|
|
231
279
|
|
|
232
|
-
- **An older Claude Code
|
|
233
|
-
|
|
234
|
-
|
|
280
|
+
- **An older Claude Code skips what it doesn't know.** Every Claude Code measured from 2.1.153 on skips a settings
|
|
281
|
+
entry for an event it doesn't know and runs the rest (IMPROVEMENTS-TO-90 §3, probe 2), so `on` adds the entries a
|
|
282
|
+
budget, a helper cap and a `never` rule listen to wherever every Claude Code it finds is 2.1.153 or later. An older
|
|
283
|
+
one there, or one whose version can't be read, keeps them all out; the screens name it. Each event is heard from the
|
|
284
|
+
release that runs it, and `on` and Home name a Claude Code too old for one, with the command that updates it.
|
|
235
285
|
- **The desktop app** reads the same settings, so every rule, cap and budget works there, a plan budget included: with
|
|
236
286
|
no status line there, Anvil asks Claude Code's own `/usage` for your plan's use, in the background.
|
|
237
|
-
- **The Claude Code plugin** (instead of `anvil claude on`) checks actions
|
|
238
|
-
|
|
239
|
-
|
|
287
|
+
- **The Claude Code plugin** (instead of `anvil claude on`) checks actions, refuses a message on a model your rules
|
|
288
|
+
say never and a `/model` switch to it (Claude Code 2.1.251 or later), and starts task budgets; helpers at once can't
|
|
289
|
+
be counted under it. Where `anvil claude on` also runs in a session, the plugin steps aside for each event `on`'s
|
|
290
|
+
entries hear, so each is answered once.
|
|
240
291
|
|
|
241
292
|
## The file: `.anvil/rules.md`
|
|
242
293
|
|
|
@@ -288,7 +339,8 @@ Every screen that shows a limit says what it does now, or why it can't: "can't b
|
|
|
288
339
|
It refuses three kinds of line, each by line number and with the reason:
|
|
289
340
|
- a kind Anvil can't see ("hold: tidy commit messages");
|
|
290
341
|
- a floor rule that a `watch:` or `off:` line would weaken ("protected is always on");
|
|
291
|
-
- a cap it can't count exactly
|
|
342
|
+
- a cap it can't count exactly: two numbers for one window ("2 deploys and 3 publishes a day"), one window twice, or
|
|
343
|
+
money said in words ("two thousand dollars of Stripe refunds").
|
|
292
344
|
|
|
293
345
|
It also explains lines that need it:
|
|
294
346
|
- A line owned by a stronger one in the same file says so ("deploy is held by line 8").
|
|
@@ -343,8 +395,25 @@ Every screen that shows a limit says what it does now, or why it can't: "can't b
|
|
|
343
395
|
- running `rules add`, `rules import` or `rules remove`;
|
|
344
396
|
- running the bare `anvil claude` (Home) or `anvil claude rules edit` (the screen).
|
|
345
397
|
- **Imports and removal.**
|
|
346
|
-
- `rules import`
|
|
347
|
-
|
|
398
|
+
- `rules import` reads your CLAUDE.md files (Anvil's CLAUDE.md reader decides which lines are rules, with your
|
|
399
|
+
Claude Code unless `--no-model`) and shows each rule beside its line, said as rules.md makes of the line it writes
|
|
400
|
+
(what `sync` shows): `→ block: force push · blocks every force-push`, or `▲ hold: deploying to production · holds
|
|
401
|
+
deploys to production` with rules.md's catch ("a deploy that doesn't say where it goes waits for your OK too").
|
|
402
|
+
A line rules.md can't take as written ("name the repository") is `?` with rules.md's reason and takes the closest
|
|
403
|
+
rule (`block: push-main`), as the box offers one. Never ✓: Anvil doesn't claim a line asked for exactly that. Then
|
|
404
|
+
it asks `↵ hold these N now
|
|
405
|
+
· w watch first · q save nothing`. Enter writes their own `block:` and `hold:` lines, in force at once; `w` writes
|
|
406
|
+
`watch:` lines; `q` saves nothing. Anvil's validator checks them before it asks. With no terminal it saves nothing
|
|
407
|
+
and says how; `--yes` writes `watch:` lines (a script never holds unasked). Each rule once: the same words on two
|
|
408
|
+
lines with the stronger verb; a rule on a whole kind covers a narrower one of the same verb, and the skipped line
|
|
409
|
+
names the one that covers it; a line that gives a block and a hold adds both; one already in rules.md is never added
|
|
410
|
+
again, and one there with a weaker verb is named, to change there. After `w`, a rule rules.md reads narrower than its
|
|
411
|
+
kinds is held by changing `watch:` to `hold:` and `sync`, never `enforce` (that holds the whole kind). Lines that
|
|
412
|
+
are advice stay in CLAUDE.md, counted ("Not enforced: N lines are guidance").
|
|
413
|
+
- Reading each CLAUDE.md line with the rules box instead (✓ ▲ ?, narrowed to what the line names: "Never delete or
|
|
414
|
+
edit anything in `migrations/`." as a rule on that folder) is held, not on yet: on 40 real CLAUDE.md files it found
|
|
415
|
+
too few of their rules and made some weaker. `ANVIL_REWRITE_STEP=1` turns it on to try it.
|
|
416
|
+
- `rules add "…"` writes a `watch:` line into rules.md, so Anvil watches what it would stop first, and applies it.
|
|
348
417
|
- An older `rules.json` moves into rules.md on the first write or apply.
|
|
349
418
|
- `rules remove <id>` removes the line that makes that rule in the file as it is now.
|
|
350
419
|
|
|
@@ -376,23 +445,54 @@ A cap lets the agent do something, just not too often or too much.
|
|
|
376
445
|
|
|
377
446
|
| Kind | Written | Counts | Resets |
|
|
378
447
|
|---|---|---|---|
|
|
379
|
-
| Count | `cap: at most 3 deploys a day` · `cap: 1 release a week` |
|
|
448
|
+
| Count | `cap: at most 3 deploys a day` · `cap: 1 release a week` | each action of those kinds a call runs that Anvil let run | local midnight; Monday 00:00 |
|
|
380
449
|
| Burst | `cap: 20 deletes a minute` · `cap: 3 force-pushes an hour` | the same, in a rolling window | rolling |
|
|
381
450
|
| Paid compute | `cap: 2 GPU hours a day` · `cap: 4 cloud machines at once` · `cap: $50 a day of paid compute, GPU hour = $2` | what paid-compute starts name | local midnight |
|
|
382
451
|
| Money | `cap: at most $2,000 of Stripe refunds a day` · `cap: no more than €1,000 in Stripe payouts per week` | what each call moves, in the cap's currency, read as a rule's amount is (Conditions: an amount) | local midnight; Monday 00:00 |
|
|
452
|
+
| Two limits | `cap: 2 deploys a day and 1 an hour` · `cap: 3 force-pushes a day, 10 a week` | each limit on its own, as two caps | each its own |
|
|
383
453
|
|
|
384
|
-
A money cap catches many small refunds that add up to a lot, which a threshold can't.
|
|
385
|
-
refund, another currency, a variable) holds the call, saying
|
|
386
|
-
so what is left is never overstated. The screens say it in
|
|
454
|
+
A money cap catches many small refunds that add up to a lot, which a threshold can't. It adds every amount a line
|
|
455
|
+
moves, each refund once. An amount it can't read (a full refund, another currency, a variable) holds the call, saying
|
|
456
|
+
so, and takes no place; one you OK counts the whole cap, so what is left is never overstated. The screens say it in
|
|
457
|
+
money ("$1,200 of $2,000 used"), never as an estimate.
|
|
387
458
|
|
|
388
459
|
- **What counts.**
|
|
389
|
-
- Counted: a call
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
460
|
+
- Counted: each capped action Anvil reads in a call. `vercel --prod && vercel --prod` is 2 deploys, and so is the
|
|
461
|
+
same pair joined by `;`, `&` or `||`, inside `bash -c` or `ssh`, or a literal list (`for e in a b`). A call let
|
|
462
|
+
through, an approved one, and a prompt answered Yes all count. A command that runs another several times in a way
|
|
463
|
+
Anvil doesn't read counts as written (What it doesn't do).
|
|
464
|
+
- A line that would cross a cap partway is held whole, saying what it adds: "cap reached: 2 deploys a day (1 used
|
|
465
|
+
today + 2 in this call; resets at midnight)".
|
|
466
|
+
- What can't be counted is held, saying so, and takes no place: a line of 16 actions or more (Anvil lists 16 in one
|
|
467
|
+
line, so it can't tell 16 from more); a line that repeats what it runs a number of times Anvil can't read (a `for`
|
|
468
|
+
loop over a list it can't list, like `{1..50}`, `$(…)`, a glob or a variable; `while`, `until`, `select`, zsh's
|
|
469
|
+
`repeat`, `xargs`, `parallel`, `watch`, `find -exec`; a function written `name() { … }` that calls itself), also
|
|
470
|
+
inside what a shell runs from a quoted word (`bash -c '…'`, `eval`, `ssh host '…'`), even when the loop isn't around
|
|
471
|
+
the capped part; and an MCP tool's shell line of several commands. One you OK counts the whole cap.
|
|
472
|
+
- Not counted: a call held with a code. One asked in Claude Code's prompt counts until it is answered.
|
|
473
|
+
- Freed: a call Claude Code refused gives its place back. That is a No at its prompt (Anvil's hold or its own
|
|
474
|
+
question, in the terminal, the desktop app, or headless's "needs approval"), a deny by a permission rule or another
|
|
475
|
+
hook, or auto mode's refusal.
|
|
476
|
+
- It is read from the fields Claude Code writes beside the call's result (`toolDenialKind`), never from its words,
|
|
477
|
+
which a command can print. That refusal must be the call's only result. A helper agent's call is read in its own
|
|
478
|
+
file; one whose file isn't there keeps its place.
|
|
479
|
+
- It is read before the next tool call of its own session runs (its main thread's or a helper's), and at other
|
|
480
|
+
sessions' calls too (up to 4 more session files a check for places given back and 4 for counts, the newest
|
|
481
|
+
first). Claude Code writes a call's result
|
|
482
|
+
before then, so a call that ran is settled as run before a later call of its session could change its record. The
|
|
483
|
+
place comes back when the refused call's own thread (its session, or its helper agent) makes its next call: then
|
|
484
|
+
it isn't running.
|
|
485
|
+
- Only where Claude Code can still refuse: under Bypass nothing of its own asks, so a call counts as it runs, even
|
|
486
|
+
one a deny rule or another hook refuses there.
|
|
487
|
+
- A place given back is checked again for 6 hours. If Claude Code then writes another result for the call, the call
|
|
488
|
+
counts again.
|
|
489
|
+
- A count with no answer after 6 hours keeps its place (an Anvil hold asked in the prompt is read while its window
|
|
490
|
+
lasts). A Yes read after midnight still counts on the day the call ran.
|
|
491
|
+
- **Two limits on one line** are two caps. `cap: 2 deploys a day and 1 an hour` counts each limit; a hold names the
|
|
492
|
+
one reached, or both. A limit that names nothing counts what the one beside it does ("1 an hour" counts deploys).
|
|
493
|
+
One window twice is refused. Helper agents at once stay on a line of their own.
|
|
494
|
+
- **Numbers.** Digits ("1,000") or words ("a hundred", "twenty-five", "a dozen"). Money is written in digits ("$2,000"):
|
|
495
|
+
in words it is refused, never read as that many calls.
|
|
396
496
|
- **Held for another reason.** A call held by another rule that would also go over a cap names both in the one reason
|
|
397
497
|
("…; and cap reached: 1 deploy a day"), so one OK covers both, and the approved call counts.
|
|
398
498
|
- **Safe across sessions.**
|
|
@@ -408,16 +508,18 @@ so what is left is never overstated. The screens say it in money ("$1,200 of $2,
|
|
|
408
508
|
- **Paid-compute caps are estimates and say so.** Anvil sees the command that starts compute, never the bill.
|
|
409
509
|
- It reads the machines (`--count`, `--num-nodes`, gcloud's instance names), the hours (`--max-run-duration`,
|
|
410
510
|
`--hours`), and a GPU (`--gpus`, `--accelerator`, a GPU machine type).
|
|
411
|
-
- What a start doesn't state counts as 1.
|
|
511
|
+
- What a start doesn't state counts as 1. A line with several starts counts each, at the line's largest figures
|
|
512
|
+
(never fewer). The cap's line in `status` says "an estimate".
|
|
412
513
|
- A GPU cap counts every paid-compute start. Anvil can't tell from a command that a machine has no GPU (a type it
|
|
413
514
|
doesn't know, like p4d, g5 or ND, may have one), so it never assumes so: it holds sooner, never later.
|
|
414
515
|
- A dollar cap needs your own price ("GPU hour = $2"). Without one it is refused: Anvil never guesses a price.
|
|
415
516
|
- "At once" is counted per day for machines, and the line says so (helper agents at once are counted live: below).
|
|
416
517
|
- **Where caps show.**
|
|
417
|
-
- `status` shows each cap that applies where it runs (yours, and that project's), its use and when it resets
|
|
418
|
-
`/anvil` shows yours.
|
|
419
|
-
- Replay replays each cap over your history in time order
|
|
420
|
-
have waited for your OK"
|
|
518
|
+
- `status` shows each cap that applies where it runs (yours, and that project's), its use and when it resets: a line
|
|
519
|
+
with two limits shows two. `/anvil` shows yours.
|
|
520
|
+
- Replay replays each cap over your history in time order, counting a line's actions as the hook does for count and
|
|
521
|
+
money caps: "cap 2 force-pushes a day: reached on 1 day, 1 call would have waited for your OK". Paid compute counts
|
|
522
|
+
once there for a call that leads with a start (1 machine or hour, or one at your price), whatever it names.
|
|
421
523
|
|
|
422
524
|
## Budgets
|
|
423
525
|
|
|
@@ -478,8 +580,11 @@ yours, so it lives in `~/.anvil/rules.md`: a project's file can't hold one, and
|
|
|
478
580
|
spends can't be known until it ends, so a budget can still end a little over, by about a reply. A plan's share
|
|
479
581
|
needs no reserve: a few replies are a hundredth of a point of a week. Other sessions running at the same time are
|
|
480
582
|
not counted in a session's reserve.
|
|
583
|
+
- **A model Anvil has no price for still counts.** It is priced at the newest model of its family (a new Opus at Opus
|
|
584
|
+
5.5's prices), else at the most expensive Anvil knows, and every total and hold says so: "~$3.30 of $1
|
|
585
|
+
(claude-opus-6: estimated at Opus 5.5's prices)". A dollar budget never stops counting because a model is new.
|
|
481
586
|
- **What can't be measured is said, and never enforced.** A plan's share Claude Code can't report here (an API key,
|
|
482
|
-
a Claude Code without `/usage`), a
|
|
587
|
+
a Claude Code without `/usage`), a meter that can't be read: Claude Code shows "your budget … can't be measured here: … ·
|
|
483
588
|
not enforced" once a session, and `rules add`, Home, `report`, `anvil claude rules` and the rules screen say it too,
|
|
484
589
|
with the fix, never "Claude stops". A task budget counts from the message that starts a task: one set mid-task says
|
|
485
590
|
it counts from your next message. A false stop costs more trust than a missed one.
|
|
@@ -501,9 +606,9 @@ yours, so it lives in `~/.anvil/rules.md`: a project's file can't hold one, and
|
|
|
501
606
|
what Claude would feed them is made up. An agent that copies Anvil's files elsewhere, or reads its seal key, can still
|
|
502
607
|
forge what they record: the integrity design accepts that, and budgets are a spending guard, not a security floor.
|
|
503
608
|
- **Your messages are never read.** The message hook reads the session's id, its file and its folder, never the
|
|
504
|
-
message.
|
|
505
|
-
and Claude learns of an OK only from you. The
|
|
506
|
-
|
|
609
|
+
message. Where a Claude Code older than 2.1.153 is found, `on` writes no message hook: a spent budget holds the next
|
|
610
|
+
action only, an OK lasts an hour, and Claude learns of an OK only from you. The Claude Code plugin has the message
|
|
611
|
+
hook too (from this release).
|
|
507
612
|
- **The kill switch** leaves budgets counting but stopping nothing, as it does caps.
|
|
508
613
|
- **Where budgets show.** Home's state line (`On · $12 of $50 today · 9 checked today`; past it, with an OK still
|
|
509
614
|
running, "going on with your OK until 4:12 PM"), `anvil claude report` and `anvil claude rules` (each limit with what
|
|
@@ -532,8 +637,9 @@ The agents Claude launches (the Agent tool) have rules of their own:
|
|
|
532
637
|
- Where your own permission rules deny helper launches, Anvil adds nothing; where they ask first, the switch rides on
|
|
533
638
|
that ask, and the at-once cap still counts the launch: past it, it is held with the cap's reason. Under the kill
|
|
534
639
|
switch nothing is switched.
|
|
535
|
-
- The at-once count needs Claude Code 2.1.318 or later (it reports helpers starting and stopping).
|
|
536
|
-
the plugin alone, Anvil says it can't count,
|
|
640
|
+
- The at-once count needs Claude Code 2.1.318 or later (it reports helpers starting and stopping). Under an older one,
|
|
641
|
+
and under the plugin alone, Anvil says it can't count, and never holds; `on` and Home name the older one with the
|
|
642
|
+
command that updates it. A launch put to you in Claude Code's prompt keeps
|
|
537
643
|
its place until you answer (a No gives it back; 30 minutes at most). A workflow's helpers count too. A helper that
|
|
538
644
|
never reports stopping (stopped with Esc, a crash) stops counting 30 minutes after it last did anything.
|
|
539
645
|
- Only a launch's type and model are read, never its prompt or a helper's reply. Each switch is kept 40 days for Proof.
|
|
@@ -559,19 +665,30 @@ holds an action made on the wrong model, or refuses a switch:
|
|
|
559
665
|
|
|
560
666
|
Switch with `/model opus` and ask Claude to try again: the next try runs. Or let it run once on the model it is on:
|
|
561
667
|
Yes in Claude Code's prompt, or `anvil claude allow <code>` where the hold has a code (the desktop app, Bypass).
|
|
562
|
-
- **Which model made the call** is read from Claude Code's session file: its latest request line, written as
|
|
563
|
-
request goes out (Claude Code 2.1.304 or later),
|
|
564
|
-
|
|
565
|
-
|
|
668
|
+
- **Which model made the call** is read twice from Claude Code's session file: its latest request line, written as
|
|
669
|
+
each request goes out (Claude Code 2.1.304 or later), and the reply, which names the model that answered and the
|
|
670
|
+
request it answers. In the desktop app and a headless run, the reply carrying the call lands a moment after the check
|
|
671
|
+
starts, and Anvil waits for it (half a second at most); in the terminal it is written after the check, so there a
|
|
672
|
+
request line written right after another with no reply between must name the same model, unless a change is recorded
|
|
673
|
+
or heard (`/model`, Claude Code's fallbacks, plan mode, a switch Anvil heard); after a reply, the request alone is the
|
|
674
|
+
reading, since the model changes between replies in ways Claude Code records nowhere first. Two readings that differ
|
|
675
|
+
hold the call, and the hold names both. With no request line, the reply is read (Claude Code 2.1.304 or later, its
|
|
676
|
+
record off; before 2.1.304 only the reply that carries the call, where it streams).
|
|
677
|
+
With neither, the call isn't held: every call the rule names says Anvil can't hear the model, and so do the rules
|
|
678
|
+
screen, Home and the status line, for a week. A helper agent's call is judged by the helper's model, from its own
|
|
679
|
+
file. (MODELS.md has the measurements.)
|
|
566
680
|
- **A switch refused** is refused wherever Claude Code switches: `/model` in the terminal, the desktop app's model
|
|
567
681
|
picker, an SDK's `set_model`. Claude Code says "Model switch blocked by a PreModelSwitch hook" with the rule. It
|
|
568
|
-
needs Claude Code 2.1.
|
|
569
|
-
the screens say a `never`
|
|
682
|
+
needs Claude Code 2.1.251 or later, and the switch entry, which `anvil claude on` adds where every Claude Code it finds
|
|
683
|
+
is 2.1.153 or later (and the plugin carries from this release): elsewhere `rules add` and the screens say a `never`
|
|
684
|
+
isn't refusing yet, and name the Claude Code to update.
|
|
570
685
|
- **A session already on a model your rules say never** (it started there: no hook can stop that) is told at its first
|
|
571
686
|
action: "this session runs on Opus 1M, which your rules say never · switch with /model".
|
|
572
687
|
- **What the words cover.** A model rule holds the kinds its words name, and `rules add` says which: "pushes need
|
|
573
688
|
Opus" covers a push or merge to main and a force-push; a push to a feature branch isn't a kind Anvil checks, so it
|
|
574
689
|
runs on any model. `anvil claude rules` lists each rule by its kinds.
|
|
690
|
+
- **Two rules no one model meets** (`model: opus for deploys` and `model: sonnet for pushes to main`: a call that does
|
|
691
|
+
both is held on any model) are said as the second is added, by `rules add` and the box.
|
|
575
692
|
- **Rules:** one model rule per kind, and one `never` per model. A `never` that forbids what a guard needs is refused,
|
|
576
693
|
with the line it contradicts. A model rule names a model as `/model` does: `opus`, not one version
|
|
577
694
|
(`never claude-opus-4-8` is refused, since a rule on Opus would also refuse the Opus you run), and for an action
|
|
@@ -582,12 +699,129 @@ holds an action made on the wrong model, or refuses a switch:
|
|
|
582
699
|
kinds always stopped can't take one. The kill switch leaves model rules stopping nothing, and the screens say so.
|
|
583
700
|
- **Where they show:** `anvil claude rules` (with caps and budgets, each with what it does now), the rules screen
|
|
584
701
|
(⌫ twice removes one, the box adds one), Proof (`your model rule`) and `report`.
|
|
585
|
-
- **
|
|
586
|
-
|
|
587
|
-
|
|
702
|
+
- **Claude's writes to its session files are held.** A write to a session's file, a helper's, or the folders holding
|
|
703
|
+
them (a redirect, `tee`, `sed -i`, `cp` or `mv` onto one, `rm`, a pattern of them, a variable an `ls` or `find` there
|
|
704
|
+
fills, a writer `xargs` or `find -exec` hands them, `node -e` or `python -c` naming one or handed one, `sh -c`
|
|
705
|
+
handed one by position, an archive
|
|
706
|
+
unpacked into their folder, the Write and Edit tools) is a change to the agent's controls, held from the first call.
|
|
707
|
+
Memory notes, reading, copying out and month-old housekeeping stay open. Code or a script that finds the path itself
|
|
708
|
+
can still write one, as it can any file; the two readings then still have to agree, so one forged line no longer flips
|
|
709
|
+
a guard.
|
|
588
710
|
- **Helpers versus the main chat.** `model: haiku for exploring` switches helper agents (Claude Code lets a hook
|
|
589
711
|
rewrite a launch). `model: opus for deploys` never switches anything: it holds.
|
|
590
712
|
|
|
713
|
+
## Locked folders, smart spend and a second opinion
|
|
714
|
+
|
|
715
|
+
Three more things a rule can say. Write the line, or say it in your own words: `rules add` and the rules box read both,
|
|
716
|
+
show the line it becomes and what it does, and save nothing until you say yes. `anvil claude off` takes each one out
|
|
717
|
+
again and puts every settings byte back.
|
|
718
|
+
|
|
719
|
+
| Say | It becomes | What it does |
|
|
720
|
+
|---|---|---|
|
|
721
|
+
| "never touch ~/Documents" | `block: edits to ~/Documents/` | the hook blocks writes there, and the OS refuses Bash writes there too |
|
|
722
|
+
| "use smart spend", "Sonnet does the work, Opus advises" | `model: smart` | new terminal sessions: Sonnet works, Opus advises |
|
|
723
|
+
| "get a second opinion before deploys", "check with Opus before publishing" | `second opinion: deploys` | Claude asks the advisor before the first deploy in a task |
|
|
724
|
+
|
|
725
|
+
Who approves decides. "Ask me before deploys" and "get my OK before deploys" stay a hold: you approve, not the advisor.
|
|
726
|
+
"Use opus for deploys" is a model rule (`model: opus for deploys`), "never use opus" is `model: never opus`, and "keep
|
|
727
|
+
spending under $50 a day" is a budget. Words that mention the advisor or Opus that Anvil can't place are never saved as
|
|
728
|
+
a watch: Anvil offers the exact line ("Did you mean second opinion: deploys?") and saves nothing without it. Where your
|
|
729
|
+
Claude Code is here, `rules add` asks it about such a line first (Haiku, through your login); it can choose between
|
|
730
|
+
the two forms, never add a kind your words don't name.
|
|
731
|
+
|
|
732
|
+
### A rule on a folder locks it
|
|
733
|
+
|
|
734
|
+
```
|
|
735
|
+
- block: edits to ~/Documents/
|
|
736
|
+
```
|
|
737
|
+
|
|
738
|
+
Nothing to turn on. A `block:` on a file or folder is kept twice: the hook blocks every write to it that it can read, and
|
|
739
|
+
Claude Code's sandbox makes the operating system refuse a write there from Bash that the hook can't read, such as a
|
|
740
|
+
script that builds its path while it runs. Proof names the rule: `locked by your rule: <rule> · the sandbox refused a
|
|
741
|
+
write to <path>`.
|
|
742
|
+
|
|
743
|
+
- **Approval prompts stay as they were**, in every permission mode. Anvil turns off Claude Code's "auto-allow inside the
|
|
744
|
+
sandbox" and adds no folder to its write list (Claude Code would take one as leave to change files there unasked). A
|
|
745
|
+
command that writes outside the project and its temp folders (a global install, a cache in your home folder) is
|
|
746
|
+
refused in the sandbox, then rerun outside it and asked as any command is (bypass mode just reruns). The hook judges
|
|
747
|
+
each rerun: one right after a refusal on a locked path is held.
|
|
748
|
+
- **The rules listing says, per rule,** `locked`, `partly locked: <why>`, or `held by Anvil, not locked: <why>`.
|
|
749
|
+
- **What stays with the hook alone:** a pattern (`*.lock`, `migrations/` at any depth), a `hold:` (a lock would refuse
|
|
750
|
+
the write your OK lets run), a `watch:` or a rule with a condition, a folder at a project's root in your own file,
|
|
751
|
+
native Windows, and a sandbox you turned off yourself (it stays off, and the screens say so).
|
|
752
|
+
- **Linux needs bubblewrap and socat**, and on Ubuntu an AppArmor that lets bubblewrap run: the screens say which is
|
|
753
|
+
missing, and what to install. Without them the hook still blocks what it can read.
|
|
754
|
+
- **Network, git, Docker and localhost work as before.** The sandbox covers Bash and what it starts; Read, Edit, Write
|
|
755
|
+
and MCP tools are the hook's.
|
|
756
|
+
- **A project with its own sandbox settings.** Where they turn the sandbox off, your locks hold there by the hook alone
|
|
757
|
+
(`held by Anvil only in this project`). Where it has a sandbox of its own, Anvil's open network settings merge into it
|
|
758
|
+
(Claude Code adds every file's allowed sites together): the screens there say so, and how to keep it as set.
|
|
759
|
+
|
|
760
|
+
### `model: smart`: Sonnet works, Opus advises
|
|
761
|
+
|
|
762
|
+
```
|
|
763
|
+
- model: smart
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
Anvil writes `model: "sonnet"` and `advisorModel: "opus"` into Claude Code's settings. Claude Code's advisor tool then
|
|
767
|
+
lets Sonnet ask Opus mid-task. Anthropic's figure: about 12% cheaper per coding task, and slightly better than Sonnet
|
|
768
|
+
alone.
|
|
769
|
+
|
|
770
|
+
- **New sessions only.** A session running now keeps its model.
|
|
771
|
+
- **Your own file only.** In a project's rules.md it is refused, as a budget is, and so is a `model: never sonnet` or
|
|
772
|
+
`never opus` beside it.
|
|
773
|
+
- **The desktop app keeps its own model.** It starts every session on the model picked in its menu, so there smart can't
|
|
774
|
+
make Sonnet work: pick Sonnet in the app. The advisor setting still reaches it, and the screens say so.
|
|
775
|
+
- **Never "on" before a session shows it.** Until one does, every screen says `advisor: Opus · set: seen at your next
|
|
776
|
+
session`; after a session with the advisor, `advisor: Opus · on`.
|
|
777
|
+
- **When Claude Code doesn't attach the advisor** for your account (its rollout, your plan's credits, or a telemetry
|
|
778
|
+
setting), the next session from your terminal, the desktop app or an editor shows it, and from then on every screen
|
|
779
|
+
says "Claude Code didn't attach the advisor for this account: smart runs Sonnet alone", with how to have your own
|
|
780
|
+
model back. Anvil never switches it back for you. A `claude -p` or Agent SDK run can show it on, never off.
|
|
781
|
+
- **A setting that keeps it off is named** on `/anvil` and the status line: `DISABLE_TELEMETRY` or
|
|
782
|
+
`CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC` (any value, "0" too), `DO_NOT_TRACK`, `CLAUDE_CODE_DISABLE_FEATURE_FLAGS`
|
|
783
|
+
or `DISABLE_GROWTHBOOK` (each measured live), and `CLAUDE_CODE_DISABLE_ADVISOR_TOOL`,
|
|
784
|
+
`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS` or a cloud that doesn't offer it.
|
|
785
|
+
- **What it replaced is said.** Over a stronger model of yours: `Was Opus: Sonnet works now, Opus advises; remove the
|
|
786
|
+
line to get Opus back.` A project whose own `.claude/settings.json` sets `model` wins in that project, and the screens
|
|
787
|
+
there say the one way that works: take `model` out of that file.
|
|
788
|
+
- **What it costs is counted.** The meter counts the advisor's tokens at Opus's rates, so budgets include them; Proof's
|
|
789
|
+
Spend line and `report` show its share (`· advisor $0.12`).
|
|
790
|
+
- **Removing the line gives your own values back**, byte for byte when nothing else changed the file. A value you change
|
|
791
|
+
yourself after Anvil set it (`/model` saves one) is yours from then on.
|
|
792
|
+
- A `budget:` or `model:` line, and a budget's 80% note, suggest it in one line where it isn't on. It is never a switch.
|
|
793
|
+
|
|
794
|
+
### `second opinion: <kind>`: ask the advisor before a risky action
|
|
795
|
+
|
|
796
|
+
```
|
|
797
|
+
- second opinion: deploys
|
|
798
|
+
```
|
|
799
|
+
|
|
800
|
+
Any kind Anvil names: deploys, publishing, deletes, database changes, pushes to main, force-pushes, sudo, and the rest
|
|
801
|
+
`anvil claude rules` lists. The first such action in a task is refused, and Claude reads: "Ask the advisor about this
|
|
802
|
+
deploy first. If it advises against it, don't rerun: tell the user. Nothing ran." The rerun runs only once Claude Code's
|
|
803
|
+
own record of the session shows the advisor asked, and answering, after the refusal; then that kind is done for the
|
|
804
|
+
task, and a new message is a new task. A rerun without the advisor's answer is refused once more, then waits for your
|
|
805
|
+
OK, with a one-time code. Each thread is its own: a helper agent's question to the advisor never lets the main
|
|
806
|
+
session's deploy through, nor the other way round.
|
|
807
|
+
|
|
808
|
+
- **In the terminal, every such action waits for your OK.** The terminal writes Claude's reply only after Anvil checks
|
|
809
|
+
the call, so Anvil can't see the advisor's answer before the rerun: Claude is told to ask the advisor and tell you
|
|
810
|
+
what it advises, and you decide. The desktop app, `claude -p` and the SDK write the reply as it streams: there Anvil
|
|
811
|
+
sees the answer.
|
|
812
|
+
- **No advisor in the session** (a reason above): each such action waits for your OK too. You are the second opinion.
|
|
813
|
+
- **Your budget comes first.** Before Claude is sent to the advisor, Anvil prices the ask: the advisor reads the whole
|
|
814
|
+
conversation uncached, about $0.64 at 150K tokens with Opus advising, twice that with Fable. A budget already spent,
|
|
815
|
+
or one that ask would pass (with what's running), holds the action by the budget, and Claude is told not to ask. A
|
|
816
|
+
plan's share (a % of your week) doesn't count the advisor's price.
|
|
817
|
+
- **A hold on the same kind still holds.** A second opinion decides no kind's verb: beside `hold: deploys`, Claude asks
|
|
818
|
+
the advisor first, and the deploy then waits for your OK. `rules add`, adding a hold on deploys, publishing, database
|
|
819
|
+
changes or pushes to main, suggests a second opinion on it in one line, once for each kind.
|
|
820
|
+
- **In the exact line, name the kind as Anvil does** (`database changes`, not `migrations`); in your own words,
|
|
821
|
+
`rules add` maps it for you. If no advisor is set, the rule sets Opus; one you set yourself stays.
|
|
822
|
+
- Proof lists each rerun as `advisor asked, then let through`, and each rerun without it as `rerun without the advisor:
|
|
823
|
+
held`. The pause before it is no stop: no count of what Anvil stopped includes it.
|
|
824
|
+
|
|
591
825
|
## The screen: `anvil claude rules edit`
|
|
592
826
|
|
|
593
827
|
This is real output, at 80×24 (redesigned 2026-11-17): your own `~/.anvil/rules.md` holding `hold: push or merge to
|
|
@@ -644,8 +878,9 @@ main`, `block: force-pushes`, `budget: $50 a day` and `cap: at most 3 deploys a
|
|
|
644
878
|
- **Changing a kind:** space cycles off → watch → hold → off.
|
|
645
879
|
- **Removing:** with the box empty, ⌫ on a line you wrote asks; ⌫ again removes it. Only a line in the file the screen
|
|
646
880
|
edits (the project's when there is one): a line in your own file says to change it there.
|
|
647
|
-
- **Importing CLAUDE.md:** type `import` and press enter. When a CLAUDE.md
|
|
648
|
-
|
|
881
|
+
- **Importing CLAUDE.md:** type `import` and press enter. When a CLAUDE.md has rules Anvil can hold and your rules.md
|
|
882
|
+
has none, Home's "Get started" offers "Import N rules from your CLAUDE.md" too; the import shows each rule beside its
|
|
883
|
+
line and asks before it saves anything (above).
|
|
649
884
|
- **Edited outside the screen:** when the file has changes nobody has applied, the box says so, and enter applies them
|
|
650
885
|
as `sync` does. Until then a change that would write that file saves nothing, and says why.
|
|
651
886
|
- **Where your rules live** is named in the footer: a link to the file in terminals that open one (iTerm2, VS Code,
|
|
@@ -678,11 +913,20 @@ main`, `block: force-pushes`, `budget: $50 a day` and `cap: at most 3 deploys a
|
|
|
678
913
|
|
|
679
914
|
## What it doesn't do
|
|
680
915
|
|
|
681
|
-
- **A
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
- **
|
|
685
|
-
|
|
916
|
+
- **A line with a loop in it holds a cap's call.** Anvil can't tell from the text whether the loop is around the capped
|
|
917
|
+
part, so `for f in *.yml; do lint "$f"; done && vercel deploy` waits for your OK too. A literal list (`for e in a b`)
|
|
918
|
+
counts each.
|
|
919
|
+
- **A capped action that runs only if another fails still counts.** `a || a` is two: Anvil can't know which runs.
|
|
920
|
+
- **A place comes back on Claude Code's own record of the refusal.** That record is in Claude Code's session file,
|
|
921
|
+
which Anvil can't seal. It is read before the session's next call, but something that rewrites the file before then
|
|
922
|
+
can make a call that ran read as refused: a command already running when the result is written (left running in the
|
|
923
|
+
background, or a helper's call still running), or another session's call while 4 or more other session files (a
|
|
924
|
+
helper's file is one) have newer counts waiting, or newer places given back (Self-protection's open items).
|
|
925
|
+
- **Some commands that repeat another aren't read as repeating.** `fd … --exec`, workspace runners (`pnpm -r exec`,
|
|
926
|
+
`npm exec --workspaces`, `lerna exec`, `git submodule foreach`), a function written `function name { … }`, functions
|
|
927
|
+
that call each other, and a self-call after any `}` in the function's body (a `${VAR}` included) are counted as Anvil
|
|
928
|
+
reads the line: once, a few times, or not at all (`lerna exec` and `git submodule foreach` hide the command they
|
|
929
|
+
run), never held for repeating. A cap on what they run counts them low.
|
|
686
930
|
- **Paid-compute caps are estimates.** Anvil reads the command that starts compute, never the bill. "At once" is
|
|
687
931
|
counted per day for machines, and a GPU cap counts every paid-compute start.
|
|
688
932
|
- **A cap or a model rule is per kind.** Words after its kind ("3 deploys a day for prod only") aren't read: it counts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@useanvil/claude-code",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Anvil for Claude Code on its own: it checks every action Claude Code takes and stops the risky few before they run. Its own command, `anvil-claude`, so it installs beside @useanvil/sdk (`anvil`) and never takes the SDK's.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|