← ~/pillars / deterministic-policy / guide

Deterministic guardrails

Why hooks, permission policy, linters, and CI gates beat prompt-pleading, and how to layer them so the model can't forget.

updated 2026-07-01 ~2 min read

← back to deterministic-policy/

on this page

Prompts are advisory. Context gets compacted, instructions drift, and a model under pressure will eventually skip the step you asked it nicely to remember. Deterministic policy components (hooks that block, permission rules that deny, sandboxes that confine, CI gates that fail) do not drift, because they are not suggestions.

The hierarchy this pillar develops: hook > check > prompt. If a rule must always hold, enforce it with code; reserve prompt-space (CLAUDE.md, skills) for judgment calls that genuinely need intelligence. The test is simple: if the rule can be stated as “when this observable command, file, or artifact has this property, block it”, it belongs in a hook or a check. If it requires interpreting intent or weighing trade-offs, it stays in prompt-space, and you accept that it will sometimes be missed.

The enforcement surfaces

Claude Code gives you three enforcement layers inside the session, and GitHub gives you one outside it:

  1. Hooks: user-defined commands that fire at lifecycle events (hooks reference). A PreToolUse hook that exits 2 stops a tool call before it runs, even when a permission rule would have allowed it. This is your real-time veto.
  2. Permission rules: allow/ask/deny rules that merge across five settings scopes (permissions reference). The load-bearing fact: a deny at any scope beats an allow at every scope.
  3. OS sandboxing: macOS Seatbelt or Linux bubblewrap confining Bash subprocesses at the kernel boundary (sandboxing reference). This is the only layer that binds child processes the model spawns, not just the tools it calls directly.
  4. CI gates: GitHub rulesets with required status checks and CODEOWNERS, applied to every PR regardless of who or what authored it (rulesets reference).

Each layer catches what the previous one cannot see. Hooks see individual tool calls; permission rules see classes of action; the sandbox sees every syscall descendant processes make; CI sees the finished change. Use all four.

Applied to Java on AWS

Three findings matter disproportionately for a Bedrock or otherwise AWS-credentialled environment:

The sandbox reads your credentials by default. Sandbox filesystem isolation restricts writes to the working directory, but the default read policy is the entire filesystem, including ~/.aws/credentials and ~/.ssh/ (sandboxing docs). Enabling the sandbox without explicit denyRead entries for credential paths gives you a false sense of containment. Every profile in this pillar adds them.

Argument-level Bash deny rules are fragile. A rule like Bash(aws iam *) can be dodged by flag reordering, variables, or wrapper commands. The security docs warn about exactly this. Treat argument-pattern denies as friction, not enforcement; the enforcement is a narrow allow list plus the sandbox.

Credentials leak through the environment, not just the disk. Subprocesses inherit environment variables, including cloud credentials, by default. Set CLAUDE_CODE_SUBPROCESS_ENV_SCRUB to strip Anthropic and cloud credentials from spawned processes (sandboxing docs).

And one outer-gate habit: in a repo where agents have write access, put pom.xml, terraform/, and src/main/resources/application*.yml behind CODEOWNERS-required review. Dependency declarations and production configuration are where an agent mistake is cheapest to make and most expensive to ship.

// sources