ADR-AI-003 — Enforced Guardrails: Deny Rules, Hooks and a Locked Policy

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

Status: Accepted Date: 2026-11-29 Authors: Engineering Team

Context

An assistant can be asked, or misled by text it reads (a README, an issue, a web page), into printing a secret or contacting an outside system. Written rules such as “never read .env” lower the chance but do not remove it, because the model is not deterministic. The workspace holds one real secret in the environment, the password-manager service identity, and the projects contain environment files and key material. The assistant also runs git and shell commands that can reach other repositories and hosts.

Claude Code can enforce policy outside the model with permissions.deny (a tool call pattern is refused) and PreToolUse hooks (a script sees each tool call first and can block it, ask the person, or allow it). Settings come from several sources. Managed settings at /etc/claude-code/managed-settings.json outrank them all.

Decision Drivers (FRs & NFRs)

  • BRD-AI-001 BR-1.3, BR-1.4, BR-1.5.
  • SR-AI-001 SR-F-06 to SR-F-09, SR-NF-01 to SR-NF-03.
  • ADR-INFRA-013 — the locked assistant policy in the infrastructure dev containers.

Decision — How are the secret and scope rules enforced?

Option 1 — Written rules only

Pros:

  • No code to maintain.

Cons:

  • Nothing stops a misled or mistaken assistant.

Option 2 — Deny rules only

Pros:

  • Declarative and built in.

Cons:

  • Patterns match tool calls by prefix and glob. They cannot see a secret file named inside a longer command, an environment read through an interpreter, or a variable expansion.
  • A deny rule can only refuse. It cannot ask the person for approval.

Option 3 — Deny rules plus two hooks, locked as managed policy in the dev container (CHOSEN)

Pros:

  • Env-guard (protect-env.js, on Read|Grep|Glob|Bash) inspects paths, patterns and full command text. It blocks secret files, key material, environment dumps, reads of sensitive variables and every op use except op run -- tofu|wrangler <allowed subcommand>. It blocks with exit code 2 and tells the assistant the allowed form.
  • Scope-guard (scope-guard.js, on Bash) returns ask for clone, push, remote shells, downloads, GitHub CLI writes, and fetch or pull outside the workspace. These actions are sometimes wanted, so the person decides instead of a blanket refusal.
  • Deny rules remain as a first, simple layer.
  • install-claude-policy.sh copies the whole reviewed .claude/settings.json into managed settings, with every hook at a root-owned path. It sets allowManagedHooksOnly, allowManagedPermissionRulesOnly and disableBypassPermissionsMode, so hooks and permission rules from any other settings file are ignored. The assistant runs as vscode, so it cannot edit, remove or add to the running policy, even by changing the workspace’s own settings file.

Cons:

  • Hooks are pattern checks over command text, not a sandbox. They are one layer. The dev container’s user separation and reference-only secrets are the others, so the guard is not the only control.
  • False positives are deliberate. A path containing token, secret or credential is blocked even when it is a harmless doc.
  • On a host machine with no dev container, the hooks are project settings and are only as strong as the user’s own file permissions.

Final Decision

Deny rules and two hooks enforce the rules, and in the dev container they are installed as a managed policy the assistant cannot change. The secret hook blocks, because a leak cannot be undone. The scope hook asks, because reaching outside the workspace is sometimes the task. Written rules alone and deny rules alone were rejected as unenforced and too coarse. The cost accepted is pattern maintenance and occasional false-positive blocks that a person resolves by hand.