← All posts
§ Blog

Guard precedence

A guard only holds if nothing ahead of it can say yes first. Claude Mods and prose hooks that failed open show the order of checks is the real policy.


Guard precedence

A platform lead writes a guard in plain English. Block commands that touch production. It goes into the hooks file, it reads well in review, and everyone relaxes.

Two doors down, a developer installs a plugin that makes the terminal nicer. It also approves tool calls, so the developer is asked less often.

Neither of them did anything wrong. And yet the question that matters is no longer what the guard says. It is who gets asked first.

That is the object of this note. Not whether you have guards. The order they run in.

Two changes in one week

Both of these come from Anthropic’s Claude Code changelog, a week apart.

On 1 October, version 2.1.287 “Added Claude Mods: plugins may now modify deeper behavior”. The mods overview is direct about what that means. A mod is JavaScript or TypeScript that runs inside Claude Code and can “watch the event, change it, or take it over”. “A mod is code that runs with your permissions.” “Mods aren’t sandboxed.” Mods are on by default.

On 8 October, version 2.1.294 shipped this fix. “Fixed prompt and agent hooks written as instructions (such as “Block commands that…”) allowing what they should block”.

Read those together. One is a new layer that can say yes before your guard is asked. The other is a guard that could say yes when it was written to say no.

Precedence is the policy

The first question is whether Claude Code’s built-in guard loads at all. It loads when the machine has managed settings, or when the session signs in with a Team or Enterprise plan. “A user who authenticates with an API key” gets it “only on a machine that has managed settings.” A session on a long-lived CLAUDE_CODE_OAUTH_TOKEN does not count as that sign-in either.

Where the guard loads, the admin page for mods is now plain. “Permission rules and PreToolUse hooks take precedence over a user’s mod.” By default a user’s mod “can’t approve a call that a deny rule refuses or an ask rule prompts for, whichever settings file holds the rule. The mod can’t approve a call that any PreToolUse hook blocked, either.”

Where it does not load, the permissions page says the opposite. “The mod can approve a call that a deny rule refuses or a PreToolUse hook blocked.” You are not prompted for an ask rule the mod approved, and your --permission-prompt-tool or canUseTool callback “isn’t asked about a call the mod approves, either.”

A correction belongs here. When this note went out on 26 October, I quoted an earlier version of the admin page, which said a user’s mod could approve past an ask rule, or past a PreToolUse hook outside managed settings, even with the guard loaded. The page has changed since. The table follows the current docs, read on 29 October.

ControlGuard loadedNo guard (API key, no managed settings)
Deny rule, any settings fileHolds, unless an admin sets allowModsToOverrideDenyRulesA mod can approve past it
ask rule (the permission prompt)Still promptsA mod’s approval skips it
PreToolUse hook in managed settingsRuns before any mod, and its block is finalNone, there are no managed settings
PreToolUse hook in other settings files or from pluginsIts block holds, though it runs after the last modA mod can approve past its block
--permission-prompt-tool or canUseTool callbackStill askedNot asked about a call the mod approves
Auto mode classifierSkipped for a mod-approved call, unless the session uses one of those callbacksSkipped for a mod-approved call
A mod’s own file and process callsDeny rules do not cover themDeny rules do not cover them

Two things survive the correction. The first is order. Hooks from project files and plugins still run after the last mod, and “if a mod answers the tool call itself, the tool never runs and neither do those hooks.” The second is the last row, which is easy to miss. With Read(.env) denied, a mod “can still read that file with $.fs.read” or start a program that does.

So the same sentence in two files is still two different policies, just for a different reason. Managed settings decide whether the guard loads. So does a Team or Enterprise sign-in. On a machine where it does, a deny rule in a project file holds against a mod. On a machine where it does not, the same rule is advice that a mod can answer first.

Guard precedence: with the guard loaded vs without it, and where a mod can answer first

The order is still settling

The fixes in between tell you this model is new.

Between 3 and 6 October, 2.1.289 to 2.1.292 closed gaps where a deny or ask rule on a nested shell command failed over a mod’s approval on managed machines, where a user plugin could rewrite managed MCP sign-in tool descriptions, where a user mod could make an organisation’s guard skip its check, and where an organisation plugin unloaded when a user’s mod returned a colliding name.

It did not stop on 8 October. The same day, 2.1.295 fixed a mod’s hook being handed a deeply nested tool input cut short, “so a guard could pass content it never saw”. On 14 October, 2.1.299 fixed __proto__ keys being stripped in a way that “could skip a tool.check guard”, fixed plan mode running a write that a PreToolUse hook or a mod’s tool.check had allowed, and fixed a mod keeping a headless run going past --max-turns. On 19 October, 2.1.304 added decider: "person", so a mod can insist that only a human or the host’s callback approves a call.

And then the documented precedence itself moved, as the correction above shows.

None of this is a scandal. It is a vendor tightening a precedence model in public. The order you tested last week may not be the order you run this week, and the page you read last week may not say what it says today. Precedence is a versioned behaviour. Test it like one.

A prose guard is a judgement, not a rule

The 8 October fix deserves its own section, because the habit behind it is common.

A prompt hook sends your text and the event to a model, and the model returns ok true or false. Written as a question, that is a judgement call. Written as an order, Block commands that…, it could allow what it was written to block — until the 8 October fix.

The docs already hint at where this belongs. Agent hooks are marked experimental, with the line “For production workflows, prefer command hooks.”

I think the distinction is simple. A model is good at questions of judgement. Is the task finished? Does this summary match the diff? It is the wrong tool for must-never. A must-never belongs in a deny rule or a script that returns the same answer every time.

Instruction debt was about prose as context. This is prose as enforcement, which is worse, because nobody rereads a guard that seems to work.

Headless makes it quieter

A headless agent is a job, a machine and a schedule. Nobody watches the screen, so the permission prompt is already the weakest control in that setting.

The overview’s table says a mod’s hooks run in claude -p and the Agent SDK. Nothing is drawn there. A mod that approves a call in a scheduled job leaves no one to notice.

Now put that next to the right-hand column of the table. A build box running a job on an API key, with no managed settings, does not load the guard. On that box a mod can approve past deny rules, ask rules and project hooks. If the job runs on the Agent SDK, the canUseTool callback that was meant to fetch a human is not even asked about a call the mod approved.

This is where human in the loop stops being a phrase. The human prompt sits late in the order. If something earlier can answer, the SLA on that human is fiction, however fast they respond.

Steal this

  1. Draw the order for one real tool call, from managed hooks to the prompt. If nobody on the team can draw it, that is the finding.
  2. Move every must-never into a deny rule or a managed command hook. Keep prompt hooks for judgement, and phrase them as questions.
  3. Put managed settings on build and CI machines, not only on laptops. On an API-key box, managed settings are what load the guard, and a managed PreToolUse hook still runs before any mod sees the call.
  4. Decide your mod policy on purpose. allowManagedModsOnly keeps users’ mods from running their hooks. Allowing them should be a choice, not a default nobody read.
  5. Pin the Claude Code version on headless machines, and rerun one known-bad call after every upgrade. Guard behaviour changed in at least eight releases between 3 and 19 October, and the documented precedence changed after this note first went out.

Guards are cheap to write. Order is what makes them guards. Know who gets asked first, and write that down before the next upgrade does it for you.


Field note from the build-in-public log. NDA-safe, no client names, rounded figures only. If this matches what you are seeing, get in touch.

§

BELOW THE LINE

PODČÁRNÍK · SIDEWAYS GLANCE, NOT A SUMMARY

On the grandmother whose rule was never broken, at least not in the kitchen

This week I read that the strictest rule only holds if nobody gets asked before it. I thought of a weekend cottage.

At the cottage, grandmother had one rule. No sweets before lunch. She said it the way other people sign treaties. It hung on the fridge in capital letters, and in forty years nobody in that kitchen ever broke it.

Grandfather sat at the garden gate. That was his post. He read the paper there, he greeted the neighbours there, and the children passed him on the way in. He always had something in his pocket. A toffee, a liquorice stick, half a chocolate bar warm from the sun.

Over the summers the pocket grew. Then it became a tin. Then a folding table with a parasol, a little bell and a queue, because the neighbours’ children had heard about it too. By August there was a price list, payable in pine cones.

Grandmother noticed that nobody ate their soup. She took it as proof that her rule was working. Children who are not allowed sweets, she said, simply have small appetites.

One year she did find out. She did not shout. She wrote him a note, in her best hand, and pinned it to the gate. No sweets for the children before lunch, unless they have been good.

He read it out every morning, slowly, with real respect. Then he asked each child whether they had been good. Every child had. The table did better business than ever.

Her rule was never broken. Not once, in forty years. Not in the kitchen.

Companies now write their rules the same way, beautifully, in plain sentences, and keep them in the kitchen. Meanwhile a small program sits at the gate and says yes before the kitchen is even asked. On a job that runs at night, nobody sees the children walk in with chocolate on their faces. The log says the rule held.

ČESKY. ORIGINÁL PODČÁRNÍKU

O babičce, jejíž pravidlo nikdo nikdy neporušil, aspoň ne v kuchyni

Tenhle týden jsem četl, že i to nejpřísnější pravidlo platí, jen pokud se nikdo nezeptá dřív. Vzpomněl jsem si na chatu.

Na chatě měla babička jedno pravidlo. Žádné sladkosti před obědem. Říkala to tak, jak jiní podepisují mírové smlouvy. Viselo na lednici velkým písmem a za čtyřicet let ho v té kuchyni nikdo neporušil.

Děda seděl u branky. To bylo jeho stanoviště. Četl tam noviny, zdravil tam sousedy a děti kolem něj chodily dovnitř. V kapse měl vždycky něco. Karamelku, pendrek, půlku čokolády nahřátou od sluníčka.

Kapsa každé léto rostla. Pak z ní byla plechovka. Pak skládací stolek se slunečníkem, zvonkem a frontou, protože se to doneslo i dětem od sousedů. V srpnu visel ceník, platilo se šiškami.

Babička si všimla, že nikdo nejí polívku. Brala to jako důkaz, že pravidlo funguje. Děti, které nesmějí sladké, prý prostě nemají hlad.

Jednou na to přece přišla. Nekřičela. Napsala mu lísteček, tím nejhezčím písmem, a připíchla ho na branku. Dětem žádné sladkosti před obědem, pokud nebyly hodné.

Četl ho každé ráno nahlas, pomalu, s opravdovou úctou. Pak se každého dítěte zeptal, jestli bylo hodné. Hodné bylo každé. Stolek u branky nikdy nevydělával líp a u kuchyně byl z toho pěkný bordel od čokolády.

Babiččino pravidlo nikdo neporušil. Ani jednou, za čtyřicet let. V kuchyni ne.

Firmy dnes píšou pravidla stejně, krásně, celými větami, a nechávají je v kuchyni. Mezitím u branky sedí malý program a řekne ano dřív, než se kuchyně vůbec někdo zeptá. Když úloha běží v noci, nikdo nevidí děti, jak jdou dovnitř s čokoládou kolem pusy. A v logu stojí, že pravidlo platilo.