← ~/pillars / deterministic-policy/
Deterministic guardrails
Why hooks, permission policy, linters, and CI gates beat prompt-pleading, and how to layer them so the model can't forget.
by Paul Grycuk
updated 2026-07-01 6 artifacts 6 patterns
How do we stop the agent skipping the rule when it matters?
- standard
- If a rule must always hold, enforce it in code, not prose: hook > check > prompt.
- check
- A PreToolUse hook that exits 2 blocks the action before it runs.
- skill
- Permission-policy design across the four enforcement surfaces: hook, permission, sandbox, CI.
- metric
- Rule-compliance under session pressure, code-graded: prose ~70–90% vs hooks 100%.
- failure mode
- A model under pressure eventually skips the step you asked it nicely to remember.
PostToolUse hook: Checkstyle gate
Runs Checkstyle after every Java edit and feeds violations back to Claude as a blocking error, so style findings are fixed in-session rather than in CI.
✓ verified 2026-06-10
PostToolUse hook: format Java on edit
Runs Spotless on any Java file Claude Code edits, so formatting is never a review comment.
✓ verified 2026-06-10
PreToolUse hook: block production config edits
Hard-denies any Edit or Write to Terraform, CI workflow, dotenv, and Spring production-profile paths, with the reason fed back to Claude.
✓ verified 2026-06-10
Cautious permission profile for a Java/AWS team
A reviewed .claude/settings.json: acceptEdits with narrow allows, deny rules for credential paths and destructive git/AWS operations, and sandbox denyRead as the second wall.
✓ verified 2026-06-10
Settings: standards enforcement for a Java service
The .claude/settings.json that wires the standards stack: Spotless format hook, Checkstyle gate, build-tool allows, and deny rules for generated output.
✓ verified 2026-06-10
Required checks for agent PRs
A GitHub Actions workflow exposing four named status checks, plus the ruleset configuration that requires them on every PR, agent-authored or human.
✓ verified 2026-06-10
Copy-paste-complete files, each verified against the primary docs on the date shown.
// patterns
The reading behind the artifacts, one pattern per page.