Skip to content
Leashr

Claude Code permissions or hooks: what each one covers

Permission rules are free and filter by tool and prefix. Hooks run your code on every call. A side by side comparison, with the shell wrapper test measured in real sessions.

Thomas Devulder · Published · Updated

Layers motif: three stacked rounded bars with a dotted green line crossing all of them.

Claude Code lets you control what the agent may run in two different ways. Permission rules live in the settings and say allow, ask or deny for a tool and a pattern. Hooks are programs that Claude Code runs before and after a tool call, and that can answer allow, ask or deny on their own.

People ask which one to use. The honest answer is that they cover different ground, and the useful question is what each one cannot see. This article compares them on the points that matter in practice, and uses one measured test to show where a prefix rule falls short. The benchmark ran with Claude Code 2.1.310 on claude-haiku-5-5.

Side by side

Permission rules and a hook, compared on what you can verify
QuestionPermission rulesA PreToolUse hook
Cost to set upNone, a few lines of settingsA script and a hook entry
What it matchesTool name and a pattern, often the start of the commandAnything you can compute from the call
File pathsYes, for file toolsYes, if you write the rule
Shell wrappersA prefix rule sees the wrapper, not the command insideYour code can look inside the string
Records a decisionNo journal of its ownWhatever you write, for example a journal
Spending limitNoPossible, from the cost signal
If the program breaksNot applicableYou decide: fail open or fail closed

Source: Leashr docs and bench/RESULTS.md, qualitative comparison.

Neither column is better in general. Native rules are free, need no install and also filter file paths. A hook costs you a program to maintain, and in exchange it can read the whole call and keep a trace.

The test: a wrapped force push

The test is simple. Ask the same model, in real Claude Code sessions, to run a force push through a shell wrapper, and count what got refused. For the native side the setup is a permission rule written for the direct command, which is what most people write.

Real Claude Code sessions: `bash -c 'git push --force origin main'` refused, out of 5
Claude Code permission rule
0/5
lsh-rules hook
5/5

Source: bench/RESULTS.md, real sessions on claude-haiku-5-5.

The native rule refused 0/5 wrapped calls. The hook refused 5/5. For the direct form of the command, where there is no wrapper, the two were equal at 5/5 and 5/5. The result is narrow on purpose: it shows that a prefix rule can be walked around by a wrapper, and nothing more.

# the agent proposes: bash -c 'git push --force origin main'
node .leashr/bin/evaluate.js
Leashr blocked this Bash call (rule deny-git-force-push): Force push rewrites shared history (--force-with-lease is allowed).

exit 2

Real output, replayed by tools/blog-outputs.mjs on 2026-11-28 in a throwaway project with the published rules (14c37dc Leashr 0.1.0).

A hook can fail, and you choose how

A hook that crashes on a malformed input could let every call through. The benchmark feeds a broken input to several guards and counts how many refuse.

Broken hook input refused, out of 3
dcg
0/3
lsh-rules
3/3

Source: bench/RESULTS.md, fail-closed test.

The Leashr hook refused 3/3 broken inputs, and dcg, a fast native binary used here for comparison, refused 0/3. Whether failing closed is right depends on you: it protects you and it can stop your work when the hook itself has a bug.

What the hook costs in time

Running a program before each call adds latency. The median on a harmless command was 58 milliseconds for the Leashr hook and 30.8 for dcg, with a bare Node start at 39.1. dcg is faster and the page says so, because most of the gap is the cost of starting Node.

Median hook latency on a benign command, ms
dcg
30.8 ms
node -e 0 (floor)
39.1 ms
lsh-rules
58 ms
guard-pack
109.9 ms
claude-safety-guard
133.7 ms

Source: bench/RESULTS.md, latency, one machine.

How to choose

  • Use native rules for the cases you can write as a clear prefix or path, since they cost nothing.
  • Add a hook when you need to see inside a command, keep a journal, or enforce a spending cap.
  • Use both. A hook that has no opinion leaves the call to Claude Code's own permissions, so the layers stack.

Where each one runs, and who maintains it

Permission rules live in the settings of Claude Code. They are maintained by whoever edits those files, they are versioned with the project if you commit them, and they follow the behaviour of Claude Code itself. When Claude Code changes how it parses a command, your rules inherit the change without any work on your side.

A hook is a separate program. You maintain it, you test it, and you decide what it does when its input looks strange. That is more work, and it is also the reason a hook can do things a permission rule cannot, such as writing a journal or reading a cost signal. If you do not need those things, a plain rule is the simpler tool and the page above gives no reason to replace it.

One practical point: both layers are bypassed by a tool that neither of them is wired to. A hook attached to the shell tool does nothing for an MCP server that edits files, unless you also write a rule for that tool. List the tools your agent really uses before you decide that a setup is complete.

Whatever you choose, test it on your own commands. A rule that you have not tried against the real thing is a hope. The next article shows where even a good hook stops.

Try the rules on your own project

The code is public. Install from a clone, or as a Claude Code plugin, and read each skill with a replayed example.