Govern Claude Code's built-in tools
Check Claude Code's shell, file and MCP tool calls with Thoth before they run, using a PreToolUse hook.
The MCP proxy checks the tool calls of MCP servers that run
behind it. Claude Code's own tools do not pass through it: Bash, Edit,
Write, Read and the rest are built in. The Thoth hook is a command that
Claude Code runs before each tool call (a PreToolUse hook). It sends the call
to the Thoth enforcer and turns the answer into Claude Code's response.
What the hook does and does not cover
Built-in tool calls reach Thoth only while the hook is installed. It lives in Claude Code's settings file, and a developer can remove it or run Claude Code with different settings. Nothing at the operating-system level enforces it, and shell commands are classified best-effort (see below). The hook is built and tested against Anthropic's published hook documentation; it has not yet been exercised against a running Claude Code. It makes no conformance or coverage claim.
Install
The command adds one PreToolUse entry to .claude/settings.json in the
current directory and prints what it changed. Run it again and it reports that
nothing changed. It leaves every other setting and hook in the file alone,
keeps the file's permissions, and refuses to replace a file that is a symbolic
link.
| Option | Effect |
|---|---|
--print | Print the merged settings and write nothing. |
--scope local | Use .claude/settings.local.json (yours only). |
--scope user | Use ~/.claude/settings.json (every project). |
--project-dir DIR | Use another project directory. |
--skip-reachability-check | Write the hook even when the enforcer host does not resolve from this machine. See Where the hook works today. |
--runtime shared | Write the hook for Thoth's shared trial and self-serve runtime (thoth 0.4.2 and later). --runtime dedicated, the default, removes it. See The shared runtime. |
The project file is normally committed, so teammates would run the hook too, and
each of them needs thoth installed. The entry holds the absolute path of the
thoth binary that ran the install, which is specific to your machine, so
--scope local or --scope user is usually the better choice.
The entry is written in the exec form (command plus args, no shell). Claude
Code's documentation says: "Claude Code resolves command as an executable on
PATH and spawns it directly with args as the argument vector." In a test on
Claude Code 2.1.292 an absolute command path worked, and so did a bare command
found on PATH. The default is the absolute path. A bare thoth is searched for
on PATH, where a thoth earlier
in a directory you or the model can write to would run instead and become the
security hook. --bare-command writes the bare name, warns, and then
thoth hook doctor fails unless the thoth found on PATH is this binary (by
real location, links followed) and no directory searched before it is
relative, empty, inside the project, or writable by you or others. The hook also
refuses any write under the directory the running binary lives in: by Claude
Code's file tools (real location, through links, whatever characters the name
holds; a path that cannot be resolved is refused), by MCP tools unless their name
says they only read, and by shell commands that mention that directory, or the
file which, command -v or type -p finds for thoth, together with a command
that changes files.
The entry uses the matcher "*", which Claude Code's hooks documentation lists
(with "" and an omitted matcher) as matching every tool, so a tool Claude Code
adds later is checked too. A matcher with other characters is read as a regular
expression, so a list of tool names would leave other tools unchecked. The entry
also sets a 15-second timeout and "onFailure": "block". Claude Code 2.1.295
or later is required, and "onFailure": "block" is what makes a failing hook
fail closed. Observed on Claude Code 2.1.323: with "onFailure": "block" the
tool is blocked after the hook exits 1, crashes (SEGV) or times out, and when the
hook's executable is missing; without it all of those let the tool run. Invalid
JSON on exit 0 lets the tool run even with onFailure, so the hook writes nothing
to standard output, or one valid JSON object, and refuses with exit code 2 and the
reason on stderr, which Claude sees. Observed on 2.1.292: onFailure is ignored
(the field arrived in 2.1.295), so only an explicit exit code 2 blocks and a
crash, a timeout, exit 1 or a missing executable fail open. thoth hook install always writes onFailure: "block" and refuses to install,
and thoth hook doctor fails, when claude --version reports an older version or
cannot be run (--claude-version supplies it when it cannot). The doctor also
fails when an entry lacks onFailure: "block" or when its command does not exist
or does not resolve. The hook keeps its
own wait on the network to at most 8 seconds, well inside its 15-second timeout, so
it answers and blocks before Claude Code would have to time it out. The entry is written in the documented exec form (command plus
args, no shell).
thoth hook doctor reads the project, local and user settings files and reports
the effective matcher, handler type, command and onFailure, and any
disableAllHooks: true. It exits non-zero when the hook would not run for every
tool, so scripts and device-health checks can rely on it. It also reads the
managed settings file at Claude Code's documented location; it cannot see a
session started with --settings or other session-level overrides.
Where the hook works today
By default the hook talks to https://enforce.<tenant>.<apex domain>
(THOTH_ENFORCER_URL and --enforcer-url are ignored). So it works only where
that host exists and can be reached from the machine. As of thoth 0.4.2:
| Where your workspace runs | Does the hook work? | What to use |
|---|---|---|
A customer-hosted or dedicated stack, which has its own enforce.<tenant> host | Yes, from a machine that resolves and reaches that host (for a customer-hosted stack, its private DNS) | The hook, as described here |
| Thoth's shared trial or self-serve runtime | With --runtime shared, in 0.4.2 and later (see The shared runtime). In 0.4.1 and earlier there is no enforce.<tenant> host for the hook to reach, so every call is blocked | The hook with --runtime shared; on 0.4.1 or earlier, the SDK against the API (https://api.atensecurity.com) or the MCP proxy |
This is a statement about the released versions, not a promise about when a later one ships.
thoth hook install claude-code and thoth hook doctor check this before they
report success. They derive the enforcer host from THOTH_TENANT_ID and the apex
domain, resolve it, and complete a TLS handshake with it. No credential is read
or sent, no HTTP request is made, and no redirect or proxy is involved.
installrefuses to write the hook when that host does not resolve, because a hook that cannot reach its enforcer blocks every tool call, which is worse than none. The message says that the workspace may be on the shared runtime and what works instead.--skip-reachability-checkwrites the hook anyway. The check runs only whenTHOTH_TENANT_IDis set where you run the command (otherwise it says it was not checked), uses the--apex-domainyou give, else the default, and with--printonly warns. If the host resolves but a handshake fails,installwarns and still writes the hook.doctorexits non-zero with the same message when the host does not resolve, and when it resolves but the handshake fails. It takes the tenant fromTHOTH_TENANT_IDin your shell, else from theenvblock of the settings file that holds the hook, which is where the enterprise kit puts it. With neither, it prints a note and does not check.- On a customer-hosted stack, an unresolvable name usually means this machine is not on the customer's network (VPN or private resolver), and the message says so.
- A real tool call that fails with
enforcer_transport_errornow ends with "Runthoth hook doctorto check whether the enforcer host can be reached."
The shared runtime
Thoth's shared trial and self-serve runtime is reached at https://api.atensecurity.com, the host the
SDKs use. From thoth 0.4.2 the hook can talk to it:
--runtime shared writes --runtime shared into the hook's args, next to --apex-domain and the
other flags. The default, dedicated, is the behaviour described above and sends exactly what it always
sent; --runtime dedicated removes the argument. The mode is set only in the hook's arguments, never by an
environment variable.
Not yet run against a live workspace
This mode is built and tested against the enforcer's own request handling with mock servers. It has not been run end to end against a live shared workspace, and the tenant id that workspace's calls need has not been confirmed live.
- One fixed host. The shared host is compiled into the binary. Nothing in the environment, the settings file or the tenant can change it, and the hook never falls back to the other runtime: when a call fails it blocks, with the same rules as everywhere else (https only, no redirect, no proxy from the environment).
- A customer stack cannot be mixed in.
--runtime sharedcannot be combined with--apex-domainor--trust-bundle, andinstallrefuses to write the combination. The hook also refuses to run on a machine that holds an Aten trust bundle for the tenant, because a customer-hosted stack always has one: its credential is never sent to the shared host. A file at the bundle's location that cannot be read as a bundle refuses too, since a customer stack cannot then be ruled out. An administrator'shook-policy.jsonthat does not allow the default apex domain also blocks it, because the shared host is under that domain. - Register the agent first. The shared runtime refuses a call from an agent that is not registered in the
workspace. The hook's agent id is
claude-codeunless--agent-idsays otherwise. Register it in the dashboard (Setup or Agents) or through the Thoth MCP server (preview_agent_registration), then retry. The same requirement applies to every self-serve plan. - No device identity. On the shared runtime the hook sends no endpoint or fleet identity. The runtime treats a device named in a request as a claim it must check against a registered endpoint, and the SDKs send none. As a result, per-device (endpoint) quarantine does not apply to a hook on the shared runtime. The workspace kill switch, agent quarantine and session isolation are checked before any policy on every call, and still apply.
- Held actions. A held action is polled on the same host (
GET /v1/enforce/hold/<token>), with the same credential, so--wait-secondsuses that route. The enforcer's tests cover that the route answers on the shared host; a wait has not been run against a live workspace. doctorandinstall. Both reportruntime: shared, and both checkapi.atensecurity.comthe way they check an enforcer host (resolve, then a TLS handshake, no credential sent).install --runtime sharedrefuses when that host does not resolve, unless--skip-reachability-checkis given.doctoralso checks that this machine may use the shared runtime for the tenant (no customer trust bundle for it, and the administrator policy, if any, allows the default domain).
When the shared runtime refuses a call, the hook blocks it (exit code 2) and says why in its own words:
| The runtime says | What the hook tells you |
|---|---|
| The agent is not registered | Register the agent first, and where |
| The workspace's evaluation has ended | The evaluation period has ended; contact support to upgrade or extend |
| There is no active evaluation workspace for the tenant | The tenant has no active workspace on the shared runtime; if it has its own stack, install without --runtime shared, otherwise check THOTH_TENANT_ID |
| A billing condition pauses governed actions (HTTP 402) | Governed actions are paused for a billing reason (with its short code); open Settings, then Billing, in the dashboard |
| The key does not cover this agent | Use a key created for this agent or for the whole workspace |
| Anything else | The generic "could not get a decision" message with the HTTP status |
Nothing the server wrote is repeated in these messages, except a billing reason code when it is a short lower-case word, and no key is ever printed or logged.
A customer stack
Requirement. A custom apex domain needs a trust bundle that Aten signs for your tenant, which you receive from Aten; the default apex domain needs none. A custom apex domain is accepted on unix only (macOS and Linux); on other platforms the hook refuses it. A bundle for a customer apex must pin the enforcer's leaf key, and the hook checks the pin during the TLS handshake. Without a valid bundle the hook blocks the call.
The hook sends the tenant credential to https://enforce.<tenant>.<apex domain>. The apex domain
comes from --apex-domain in the hook's args; the environment never sets it. The command
thoth hook install claude-code --apex-domain thoth.atensecurity.com --trust-bundle /path/hook-trust.json writes those arguments. It grants nothing: the hook uses a domain other
than the default only when it is exactly thoth.atensecurity.com, THOTH_TENANT_ID is a single DNS
label, and a trust bundle that Aten signed for your tenant names that domain. THOTH_TENANT_ID must
be a single DNS label under the default apex domain too. The hook checks the
bundle before it reads your credential or contacts anything, and blocks the call (exit code 2) when
anything is wrong. It never follows a redirect and does not use proxy environment variables for this
connection. The bundle is read from --trust-bundle, else
/Library/Application Support/Thoth/hook-trust.json (macOS) or /etc/thoth/hook-trust.json (Linux).
An administrator can also provision a root-owned hook-policy.json in the same directory that
lists the domains allowed on that machine; it can only narrow what is trusted. thoth hook doctor
verifies the bundle, prints the derived enforcer host and the days left (and warns under 14), and
fails when the domain, tenant or signature is wrong. Pinning the hook entry in Claude Code's managed
settings keeps a project file from changing it; check Claude Code's documentation for the current
setting names, because this page has not verified them. A bundle for a customer apex must carry one to four leaf key pins; the hook checks them during the
TLS handshake and, on a mismatch, sends no credential. thoth hook verify-endpoint connects without
sending a credential and reports whether the endpoint's key matches your bundle. Aten holds the signing keys and issues each bundle; the
format is in docs/product/claude-code-hook-trust-bundle.md.
The hook signs in the way the proxy does: run thoth auth login, or configure a
runtime key as described in the proxy guide. It reads
THOTH_TENANT_ID and THOTH_USER_ID from the environment Claude Code starts
in. THOTH_AGENT_ID names the agent (default claude-code); register it before
you enforce. THOTH_HOOK_TIMEOUT_MS (default 4000) is how long the hook waits
for the enforcer.
What happens to each call
| Enforcer answer | The hook |
|---|---|
ALLOW | Prints nothing. Claude Code's own permission rules and prompts still apply; the hook never approves a call itself. |
STEP_UP | Denies the call and names the held action. A reviewer approves it, then you ask Claude Code to try again. By default the hook does not wait for approval; with thoth hook install --wait-seconds N it waits up to N seconds and continues only on an approval of exactly this call. |
BLOCK | Denies the call with the policy's reason. |
The messages the hook prints name the tool and the reason. They never include the command, its arguments or file contents.
For an agent in observe mode the enforcer records what it would have decided and lets the action run, so the hook adds no decision; see observe and enforce.
Failures block the call
If the hook cannot get a decision, it blocks the call: it exits with code 2 and
writes the reason to stderr. Claude Code's documentation says exit code 2 blocks,
that any other exit code, and exit 0 with output it cannot parse, is a
non-blocking error that lets the call go ahead (unless onFailure is "block"),
so every refusal uses exit code 2, policy refusals included. That covers no Thoth configuration, no credential, an
unreachable or slow enforcer, an HTTP error, an answer the hook cannot read, a
session history it cannot read or update, a panic, and a decision it could not
write. A policy decision (BLOCK, a refused file path) blocks the same way. If the hook
cannot write its answer (standard output closed), it exits 2 too. A command too
deeply nested, or with too many actions, for the hook to read completely is
blocked, not partly classified.
There is no setting, flag or environment variable that lets a call through when
the enforcer is unreachable or the hook is misconfigured. The hook always talks
to an https enforcer, it ignores THOTH_APEX_DOMAIN (an edited shell profile must
not redirect the hook and its credential), and nothing a developer sets changes
the enforcement mode it reports. The only way to run Claude Code without the check is to remove the
hook (see above).
Shell commands
The hook always asks the enforcer about the generic Bash tool (class
execute) with the command itself, so the default step-up and the local checks
(plain-http URLs, destructive commands, sensitive file names) still run. It also
reads the command text and, in addition, sends the actions it recognises, so a
policy can treat a git push differently from ls. It does not read a command
for file paths.
| Command | Tool name sent |
|---|---|
git push | git_push (with the remote, when it is written out) |
git commit | git_commit |
git remote add, git remote set-url | git_remote_add |
git send-email, mail, mailx, sendmail, mutt, msmtp, swaks | send_email |
gh pr create, gh pr merge, gh release create, gh issue create, gh gist create, gh repo create, comments and reviews, gh api that writes | gh_pr_create, gh_pr_merge, gh_release_create, gh_issue_create, gh_gist_create, gh_repo_create, gh_comment, gh_api_write |
curl or wget with a body, upload or a method other than GET | http_post |
other curl or wget | http_get |
scp or rsync with a remote operand | remote_upload or remote_download |
aws s3 cp/mv/sync, gsutil cp, gcloud storage cp with a bucket | cloud_storage_upload or cloud_storage_download |
npm, pnpm, yarn, bun, cargo, gem, uv, poetry or twine publish | package_publish |
docker push, docker buildx build --push (also podman) | container_push |
It reads through sudo, env, time, timeout, nohup, quotes, pipes, &&,
;, $(...), backticks and bash -c "...". Each recognised action in a chain is
judged separately, and the strictest answer wins.
Recognition is deny-by-default. Each command has a strict list of options it may
carry. A command is marked unclassified (shell_opaque), and the arguments of
the actions in it are reported as uncertain, when it has:
- an option outside that list, or one that runs code, reads configuration, writes
a file or redirects traffic (
git -c,git --exec-path,curl -K,curl -o,wget -e,rsync -e,scp -o,aws --endpoint-url, and similar); - an assignment to a variable that changes how commands run or where they look
for programs and hosts (
PATH,HOME,GIT_*,LD_*,*_PROXY,*_COMMAND,BASH_ENV,NODE_OPTIONS,PYTHONPATHand similar; harmless variables such asNODE_ENVdo not count); - a command word that contains a path (
./curl), a value known only at run time (git $SUBCOMMAND), a substitution hidden inside${...}or$((...)), a heredoc delimiter built at run time, or a line continuation.
This is best-effort classification, not a guarantee. It cannot see shell aliases or functions, scripts a command runs, files it sources, symbolic links or anything computed at run time. A command that does something harmful under an innocent-looking name is only as safe as that name. Treat the hook as one control, not as containment.
Files, the web and MCP tools
File tools are sent with their path and the session's working directory. The
path always comes from the tool's file_path or notebook_path; a call that
names two different targets is refused. File contents and edit text are not sent
for built-in tools. MCP tools are sent under Claude Code's full name, for example
mcp__metabase__query, with all their arguments, as the proxy sends them.
Boundary objects are a separate piece of work: the hook sends the path, and
nothing here matches boundaries against it yet.
What the hook protects, and what it cannot
Without asking the enforcer, the hook refuses the model's tool calls that reach
two places: .thoth (the credential, session history and other state) and
Claude Code's settings files .claude/settings.json and
.claude/settings.local.json (which hold the hook). It checks:
- the file tools' targets (
file_path,notebook_path,path); - every string a
GreporGlobcall carries (pattern,glob,include,pathand the rest): a pattern or glob that names.thothor.claude, or that could expand to them under your home directory, is refused, and so is a search rooted at or above the directory that holds.thoth(your home directory,/), so search from a project directory; - MCP tool arguments that look like paths, at any depth;
- shell command text, conservatively: any mention of
.thoth, and any mention of.claudetogether with a settings name, a wildcard, a redirection,cdorpushd, or a tool that changes files or directories (cp,mv,rm,ln,sed -i,tee,find, and similar). A plain read of an unrelated file, or a file that is merely namedmy.claude-notes.md, passes; - the directory a
GreporGlobeffectively starts in, taken from the literal prefix of its pattern or glob; and writes through a symbolic link.
Paths are compared as text, case-insensitively, with / and \ treated alike,
.. collapsed and ~, $HOME and %USERPROFILE% expanded; a search root is
also compared in its canonical form. This protects only against tool calls the
model makes that the hook can see.
Security beats noise here, so the check refuses some harmless commands. Known
noise, refused because they name a protected path or could reach one:
ls ~/.??* and du -sh ~/.c* (a hidden-name wildcard could match .thoth),
echo .thoth >> .gitignore, git add .claude/settings.json, git show HEAD:.claude/settings.json, any compound command (a && b) that names a protected
path, and any MCP argument, such as an issue body, that mentions ~/.thoth/....
Only these are allowed to name a protected path: the value of -m/--message of
a single git commit (whatever its length), and the search pattern of a single
grep, rg, ag or ack with no option that takes a file or a glob. A glob that
starts with .. (a sibling project) is allowed, and is judged by where it leads.
Globs are also resolved against the real filesystem: the directory the literal
prefix names, and every entry its first pattern component could match, are followed
through links, and a glob that leads into .claude or .thoth (cl/*, [t]/*) is
refused. A file named thoth in any directory on PATH (relative and empty entries
resolved against the session's directory) and the running binary's directory are
protected the same way as the settings files.
The hook's doctor, its PATH and binary-directory checks and the hard-link check are
verified on macOS and Linux only. Windows is untested: the code compiles there, and a
tool call the hook cannot judge is denied, but those checks have not been run on it,
and a hard link to a protected file is not detected.
thoth hook doctor prints the binary the hook command resolves to (and its real
location), runs it with --version, and fails unless it reports this thoth's
version.
Recursive shell commands (grep -r, rg, ag, ack, find, tar, zip,
cp -r, rsync, du, ls -R, tree) get the same root check as Grep and
Glob: a directory operand that is your home directory, above it (~, $HOME,
.., /) or . when the session is in the home directory is refused, as is an
operand only known at run time. Project directories pass. A nested Claude Code
session is held however it is started: claude, a path to a claude binary, or
through npx, bunx, pnpm dlx, yarn dlx or npm exec. codex exec and other
agent command lines are not held (known gap).
Common searches pass: **/*.rs and **/*.ts work in a project that has the hook's
.claude/settings.json, because the check refuses a glob that could match a settings
file (**/*.json, **/settings*, .claude/**), not the mere presence of the
.claude directory.
A glob that reaches below the first level walks the tree and resolves every symbolic
link it finds, through chains. A link that points inside the project (the links in
node_modules/.bin) passes. A link that resolves outside the project, into or above
.thoth or .claude, back to its own directory, or cannot be resolved is refused.
More noise: a Glob over a directory with more than 10,000 entries (for example
node_modules/*) is refused unread, and so are links that point outside the project
(for example a pnpm store linked from outside it).
thoth hook doctor also fails on a disableAllHooks that is not a JSON boolean (a
string or a number might be read as true), a permissions or hooks that is not an
object, and a hook timeout that is not a positive number.
Known gaps in this check (reported by the reviewers, not closed):
- A shell command that goes through a link that already exists (
cat t/credentialswheret -> ~/.thoth); creating such a link is refused, but a command cannot be followed through the filesystem. - Names built at run time:
$'..'splicing and an interpreter that assembles a path from strings (python -c,node -e). - MCP
get_file_info "..", andsearch_filesordirectory_treeover a directory that holds a protected link. - Whether
grep -randrgfollow links depends on the tool and its options. codex execand other agent command lines.- Negated or extended globs (
!**/*.rs,**/@(settings).json) return names only. AGrepglob such as!*.rs, orrg --hidden, can read.claude/settings.json, which holds configuration, not a credential. - Shells other than
sh,bash,zsh,dashandksh, and some forms of those:bash -c -- '...',fish,csh,su -c,script -c, and a command piped intobash. - Wrappers that are not looked through:
env -S,watch,parallel.fd --search-path ~and--base-directory ~as separate words are not judged.locateandmdfindlist names only;fd -H -x catcan read contents. tar -C$X, a directory attached to the option and built at run time.- A recursive command fed by a pipe (
echo ~ | xargs grep -r x). - A nested session started through another program (
node $(which claude) -p).
Anything else the reviewers find goes to a follow-up and is a known gap: this check is defence in depth, not a boundary.
This is not a security boundary. A text check on a shell command cannot be one: a shell can build any name at run time, and a script can open any file. The hook cannot stop a developer, another process, or a command whose file name is assembled from variables from reading or editing those files.
Use Claude Code's own controls for the real protection
What is confirmed in Anthropic's documentation at the time of writing (code.claude.com/docs/en/settings and /en/permissions):
- Managed settings sit at the top of the settings precedence. Nothing in user,
project or local settings, and not
--settings, overrides a managed key. permissions.denyrules such asRead(./.env)stop Claude Code's built-in file tools. They also apply to the redirection targets and file commands (cat,head,tail,sed,tee) that Claude Code can recognise in a Bash command, and not to a command that reads files without naming them or to a script that opens files itself.- For enforcement that does not depend on the command text, the documentation points to sandboxing, which restricts shell commands' filesystem access at the operating-system level.
- An
allowManagedPermissionRulesOnlysetting exists; it stops lower-level permission rules from applying.
So, for the hook's files and .thoth, deploy managed settings with deny rules for
them (and the sandbox, if you use it) rather than relying on this hook.
Not confirmed, so not claimed: whether a managed setting can stop a developer
from removing the hook (an allowManagedHooksOnly-style key is not in the pages
checked), the exact deny-rule syntax for paths under your home directory, and
the sandbox's setting names. Check Claude Code's current documentation before
relying on any of them.
Decisions use server-confirmed tool declarations. A tool name that has not been
declared is unknown and steps up, so declare the names you want to treat
differently from the default: Bash, Read, Edit, Write, the MCP tool names
and the shell action names above. See
Profiles and action classes.
If an MCP server is also wrapped by the proxy, its calls are checked twice, once under the server's own tool name and once under Claude Code's. The proxy speaks stdio only; the hook also sees Claude Code's HTTP MCP servers.
Sequences across a session
Each hook run is a separate process. To let the enforcer judge a sequence, such
as reading sensitive data and then publishing it, the hook keeps the names of the
session's recent tool calls (never their arguments) in
~/.thoth/hook-sessions/, readable by you only, and sends them with each call.
The file is locked while it is read and appended to, so parallel calls neither
lose nor reorder entries. If the history cannot be read, the call is blocked
rather than judged as if the session had just started. Files older than a week
are removed. The session identifier is Claude Code's session_id.
Remove it
Delete the Thoth entry from the settings file you installed it into. Until you do, every call goes through it, and a misconfigured environment blocks calls rather than allowing them.
What was checked
Read from code.claude.com/docs/en/hooks on 23 November 2026:
- Matchers:
"*",""or omitted match all; only letters, digits,_,-, spaces,,and|is an exact list; any other character makes a JavaScript regular expression, unanchored. onFailure:"continue"or"block", Claude Code 2.1.295 or later.- Exec form: with
argspresent,commandis resolved as an executable onPATHand spawned without a shell. - Exit codes: 0 applies the JSON; 2 blocks; any other exit code, or output it
cannot parse, is non-blocking unless
onFailureis"block". PermissionRequestruns when Claude Code is about to ask for permission and can allow or deny throughhookSpecificOutput.decision.behavior.
Run against a real Claude Code with stub hooks (2.1.292 and 2.1.323 only):
- The matchers
"*",".*"and"Bash"all invoked the hook. - Exit code 2 blocked the tool and Claude saw the stderr reason; JSON
permissionDecision: "deny"with exit 0 also blocked. - Exec-form
argsworked with an absolutecommandand with a bare command onPATH. - 2.1.323: with
onFailure: "block"the tool was blocked after exit 1, a crash, a timeout and a missing executable; without it all four let the tool run. Invalid JSON on exit 0 let the tool run even withonFailure. - 2.1.292:
onFailure: "block"made no difference; exit 1, a crash, a timeout and invalid JSON on exit 0 let the tool run.
Not verified, so not relied on: behaviour on versions between 2.1.295 and 2.1.323 other than what the field's introduction implies;
whether the interactive permission dialog stays open while a PermissionRequest
hook runs; whether a nested claude -p session inherits these hooks; and a
managed-settings option that stops a developer removing a hook.