Hooks, Permissions and the Locked Policy

By Engineering Team•November 29, 2026•6 min read

Written rules tell the assistant what not to do. These controls enforce it. The reasoning is in ADR-AI-003.

Files

File Role
.claude/settings.json Deny list and hook registration. The reviewed source of the policy
.claude/hooks/protect-env.js Env-guard: blocks secret access
.claude/hooks/scope-guard.js Scope-guard: asks before reaching outside the workspace
.claude/hooks/start-guard.js Start-guard: refuses prompts in a session not started at the workspace root
.devcontainer/shared/install-claude-policy.sh Builds the managed policy from the two files above when the container is created
/etc/claude-code/managed-settings.json, /etc/claude-code/hooks/ The installed policy, root-owned, in the dev container

1. The deny list

permissions.deny refuses a tool call that matches a pattern before any hook runs:

  • Read and Edit of .env variants, and Read of *.pem, *.key, *.crt, *.p12, *.pfx, service-account and Firebase admin JSON, and /proc/**.
  • Bash environment dumps: printenv, env, set, export -p, declare -p, cat /proc/*/environ.
  • Keychain retrieval (security find-*, dump-keychain, export).
  • Every op subcommand except run (read, item, inject, document, vault, signin, whoami, …).
  • docker exec, docker inspect, docker top, docker compose exec, which could reach another user’s process or environment.

2. Env-guard — blocks

Registered on Read|Grep|Glob|Bash. It reads the tool call as JSON on stdin and checks the path, the search pattern and the full command text:

Blocks What it means
Secret files and key material Environment files, service-account and key files, and any path or command that names a secret
Another process’s environment Reading what another process was started with
Environment dumps Any command or one-liner that prints the whole environment
Sensitive variable reads Reading the value of a password-manager, provider or engine variable
op misuse Any op command other than the one runner around tofu and wrangler, and never inside command substitution

Two forms are allowed on purpose:

# presence check only, never the value
[ -n "${SOME_VAR:+x}" ] && echo set || echo missing

# the one allowed runner, as the host wrapper starts it for a layer
op run --environment <environment-id> -- tofu plan

A block exits with code 2 and prints the reason and the allowed form. Claude Code returns that message to the assistant, which changes its approach.

3. Scope-guard — asks

Registered on Bash. It never blocks. It returns permissionDecision: "ask" with a reason, and the person decides:

Asks before Reason shown
git clone, git push Clones a repository / pushes to a remote
ssh, scp, sftp, rsync Opens a remote connection
curl, wget Downloads from or sends to a remote host
gh commands other than read-only pr view/list/status/checks/diff, run view/list/watch, repo view, issue view/list, workflow view/list, auth status Not read-only
git fetch/pull/ls-remote/remote/submodule on a repository outside the workspace root Outside the workspace

It follows cd and git -C <dir> through the command. When it cannot work out a path, it asks.

4. Start-guard — sessions run at the workspace root

Claude Code reads its project configuration from the folder it starts in. A session started inside a project folder would run without the workspace’s rules, skills and graphify hooks. Two pieces prevent that in the dev container:

Piece What it does
claude shell function Sourced from /etc/bash.bashrc. Typing claude in any folder starts Claude Code at the workspace root, in a subshell, so your terminal stays where it was
start-guard.js, on UserPromptSubmit Runs before each prompt. If the session’s project folder ($CLAUDE_PROJECT_DIR) is not the root recorded in /etc/claude-code/workspace, it refuses the prompt with exit code 2 and tells you to restart.

5. Graphify hook-guard

graphify hook-guard search (on Bash|Grep) and graphify hook-guard read (on Read|Glob) remind the assistant to query the knowledge graph before a broad search or read. They are a cost control, not a security control. They are still part of the managed policy, because the container ignores every hook that is not managed. They call /usr/local/bin/graphify, which is root-owned. See Graphify in the Workspace.

6. The locked policy in the dev container

install-claude-policy.sh runs as root during post-create.sh, once, when the container is built, before vscode loses sudo:

  1. Copies every script in .claude/hooks/ to /etc/claude-code/hooks/ (root-owned, mode 644).
  2. Records the workspace root in /etc/claude-code/workspace, and installs the claude shell function as /etc/claude-code/claude-root.sh, sourced from /etc/bash.bashrc.
  3. Copies the whole of .claude/settings.json into the managed policy. Every hook command is pointed at its root-owned copy, and graphify at /usr/local/bin/graphify. The build stops if a hook would still run a file in the workspace, or if the env-guard, scope-guard or start-guard entry is missing.
  4. Adds three managed-only locks and writes /etc/claude-code/managed-settings.json:
Key Effect
allowManagedHooksOnly: true Hooks from user, project, local settings and plugins are blocked. Only the managed hooks run
allowManagedPermissionRulesOnly: true Allow, ask and deny rules from user, project and local settings, and from --allowedTools, are ignored. The “always allow” choice is hidden and no new rule is saved
permissions.disableBypassPermissionsMode: "disable" The mode that skips every permission check cannot be entered

Managed settings outrank the command line and every settings file, and disableAllHooks outside managed settings cannot switch managed hooks off. Inside the container, .claude/settings.json is therefore only the reviewed source for the next build: editing it, or .claude/hooks/, changes nothing at runtime. A change reaches the running policy only after review, merge and a container rebuild.

On a host machine with no dev container there is no managed policy. The project hooks still run, but they are ordinary files the user, and so the assistant, can edit. Use the dev container for real work.

7. Testing a hook

Hooks read JSON on stdin, so you can test them in your own terminal without the assistant:

# env-guard: expect "[env-guard] Blocked ..." and exit=2
echo '{"tool_name":"Bash","tool_input":{"command":"printenv"}}' \
  | node .claude/hooks/protect-env.js; echo "exit=$?"

# env-guard: a harmless call, expect no output and exit=0
echo '{"tool_name":"Read","tool_input":{"file_path":"README.md"}}' \
  | node .claude/hooks/protect-env.js; echo "exit=$?"

# scope-guard: expect a JSON "ask" decision
echo '{"tool_name":"Bash","tool_input":{"command":"git push origin main"},"cwd":"."}' \
  | node .claude/hooks/scope-guard.js

# start-guard: the optional argument points at a test root record
printf '%s\n' "$PWD" > /tmp/root-record
echo '{}' | CLAUDE_PROJECT_DIR="$PWD" node .claude/hooks/start-guard.js /tmp/root-record; echo "exit=$?"            # 0
echo '{}' | CLAUDE_PROJECT_DIR="$PWD/<project>" node .claude/hooks/start-guard.js /tmp/root-record; echo "exit=$?"  # 2

Run these yourself. The env-guard is designed to block the assistant from running a command line that names a secret pattern, even one meant only as a test.

8. Changing a hook or the deny list

  1. Edit .claude/hooks/<hook>.js or .claude/settings.json in the workspace repository.
  2. Test with the commands above, including a case that must still pass. You cannot try a change by editing the running container’s settings: the managed policy ignores them.
  3. Open a pull request. Hooks are security code: review them as such.
  4. After the merge, rebuild the dev container so install-claude-policy.sh installs the new version.

Keep one hook per purpose. Add a pattern to the existing env-guard rather than adding a second secret hook. Prefer blocking for anything that could expose a secret, and asking for anything a person may legitimately want.