If you place a rule that cannot be skipped only in CLAUDE.md or a prompt, Claude Code may or may not follow it. Limits on agent actions and checks that must always run belong in the layers the runtime evaluates on every call.

📑Table of Contents
  1. Prompts cannot enforce the rule
  2. Close the permission surface first
  3. Put non-negotiable rules in hooks
  4. Split guides from sensors
  5. First-week checklist
  6. FAQ
  7. Summary

The split is simple. CLAUDE.md is a guide. Permission rules set hard limits on what the agent can do. Hooks are sensors that run every time. Block destructive work with deny or ask-first rules, then move only the remaining mandatory checks into PreToolUse, PostToolUse, or Stop.

Official permissions versus prompts

Anthropic’s Configure permissions states that prompts and CLAUDE.md shape what Claude attempts but do not change what is allowed. For enforcement, start with the Hooks reference and Automate actions with hooks.


Prompts cannot enforce the rule

Instructions versus runtime

Writing “always lint” in an instruction file is only a hope. Instruction files ask the model to comply. The runtime actually evaluates permissions and hooks.

Official permissions documentation keeps that boundary explicit. Independent write-ups make the same distinction.


Independent write-ups

  • Blake Crosley puts must-run lint, format, and security checks in hooks because hooks run regardless of model behavior, while prompts do not.
  • Vibehackers treats CLAUDE.md as advisory—followed roughly 80% of the time in their secondary observation—and says that is not enough for “never force-push main” or “lint after every edit.”

How to use the 80% report

Treat 80% as a field report, not an official metric. Design against “does this run every time?”


Mechanical checkers as the gate

Kaa-kun’s review of Interface, September 2026 makes a sharper quality-gate claim: use mechanical checkers such as tests and static analysis, not another AI review, as the gate. Reader rule: if the requirement is “every time,” do not leave it in a prompt.

This is what stays in CLAUDE.md versus what moves to the machine.

  • Style and priority can stay in CLAUDE.md.
  • Secret-file reads, destructive git, and ship-blocking tests move to the machine.

For how to keep CLAUDE.md short, see CLAUDE.md design patterns.


Close the permission surface first

Evaluation order and first pass

Add hooks only after you shrink what the agent can do. Official evaluation order is deny, then ask, then allow. The first match wins. A narrow allow does not punch a hole in a wider deny. Bash(aws s3 ls) cannot exempt you from Bash(aws *).

Here is a safe first pass.

  1. Run /permissions and note which file owns each rule.
  2. Put destructive git, deletion, and production deploys on scoped deny or ask. Bash(rm *) is the usual example. A bare Bash deny removes the tool from context. Keep the tool and block only matching calls with a specifier.
  3. Deny Read(./.env). Extra working directories add file access only. Hook discovery still uses cwd .claude/ plus user and managed sources.

Modes and persistent approvals

Permission modes set the upper limit.

  • default / manual prompts on first use
  • acceptEdits auto-approves in-repo edits and a few file operations
  • plan stays read-heavy
  • auto uses a classifier
  • dontAsk rejects anything not pre-allowed
  • bypassPermissions skips prompts, but the hard blocks for rm -rf / and rm -rf ~ remain

Write prompts for .git and .claude do not. That mode is for containers and VMs, not a default laptop. Managed settings can set permissions.disableBypassPermissionsMode to disable bypass and auto.


Persistent Bash approvals

Persistent Bash approvals land in the git-root .claude/settings.local.json from Claude Code v2.1.211. If home is the repo root, or the folder is not a git repo, they land in the launch directory. Keep personal exceptions out of the shared project file.

Data Studios describes permissions as least-privilege feedforward control over read, edit, and command execution. Destructive git, deletion, and deploy stay on deny or an explicit prompt. The first team decision is not “which command should we discuss in chat.” It is “which operation must be impossible.”


Put non-negotiable rules in hooks

After permissions limit how far damage can spread, hooks handle the remaining checks that would ship a defect if skipped. The official guide calls hooks deterministic control: the action happens whether or not the model chooses it. They run in three layers.

  • session: SessionStart / SessionEnd
  • turn: UserPromptSubmit / Stop / StopFailure
  • tool: PreToolUse / PostToolUse

Minimum setup

Here is the minimum setup.

  1. Add hooks to shared .claude/settings.json and confirm with /hooks. The menu is read-only; edit the JSON.
  2. Match PreToolUse on Bash, add if: Bash(rm *) (or your protected path), and deny with JSON or exit 2.
  3. Match PostToolUse on Edit|Write, run lint or format, and return failures so Claude can fix immediately.
  4. Use a Stop hook or existing CI for format, lint, build, and test. Takumi’s harness comparison reports that Spotify Honk runs those checks in a Claude Code stop hook and refuses to open a PR if any verifier fails. You do not need that product. You need “do not ship if it fails.”

Exit codes and timeouts

Exit codes are easy to get wrong.

  • Exit 0 is not approval; it is “no decision.” Without valid JSON, the normal permission flow continues.
  • Only exit 2 blocks by code alone.
  • Exit 1 and other codes are non-blocking errors unless valid JSON says otherwise.
  • Enforce policy with exit 2 or PreToolUse permissionDecision: "deny".
  • Combined hook priority is deny > defer > ask > allow.

Timeouts

Timeouts matter.

  • command / http / mcp_tool default to 600 seconds
  • UserPromptSubmit drops that to 30 seconds
  • Agent hooks default to 60 seconds and at most 50 tool turns
  • SessionEnd is 1.5 seconds overall, extendable to 60
  • Notification permission_prompt fires after about 6 seconds of no input
  • idle_prompt after about 60 seconds

A slow lint on UserPromptSubmit will time out and look like it never ran.


Limits and unreviewed clones

Keep three limits in mind.

  • PostToolUse cannot undo work that already ran; blocking belongs in PreToolUse.
  • PreToolUse deny / exit 2 still runs in bypassPermissions. A hook allow cannot override a settings deny or ask.
  • claude -p on an unreviewed clone treats the folder as trusted, so project hooks run immediately. Prefer --bare or disableAllHooks first.

A user-level disableAllHooks: true can be overwritten by project settings. Managed hooks remain unless the managed policy also disables them.


Event-to-job mapping

Event Use it for On failure
PreToolUse Destructive commands and protected-path edits Stop before the tool runs with exit 2 or JSON deny
PostToolUse Lint / format after Edit or Write Cannot undo; feed the result back to the model
Stop Ship-blocking test / build Hold the turn, or share the gate with CI
UserPromptSubmit Short checks at prompt time 30-second default; do not park heavy jobs here

Related reading

Sources: Hooks reference, Hooks guide (as of August 2026)

The earlier Claude Hooks field guide covers a wider automation surface. This article is only about which layer owns the rule, and how to add the first hook without creating a false sense of safety. If you want a repo scan that proposes hooks, start from the Claude Code Setup plugin, then keep only the non-negotiable items.


Split guides from sensors

Keep short commitments in CLAUDE.md, put procedures in Skills, and put completion checks in hooks, tests, and linters. If every rule lives in the instruction file, a summarized context window can drop the rule that mattered.

Layer mapping

PALO IT maps the layers as follows.

  • CLAUDE.md to an always-on guide
  • Skills to conditional guides
  • Hooks to sensors

Guides versus sensors

Guides steer work before it starts. Sensors judge whether the work is done. Checks that must pass cannot be reasoned around, so “no force-push” and “do not skip tests” belong in hooks. Kaa-kun’s Interface review makes the same distinction: keep CLAUDE.md short, auto-run lint and tests in hooks, and feed failures back for correction.

Decide this way: if missing the rule would cause an incident, use a hook. If missing the rule only produces slightly messier prose, keep it in CLAUDE.md.


Layer comparison

Layer Role Force Fits
CLAUDE.md / prompts Guide Model-dependent Voice, priorities, explanation density
Permission rules Feedforward Runtime-enforced Read / edit / command scope
Hooks Sensor / gate Runs every time Lint, protected paths, destructive commands, pre-ship tests

Sources: Hooks reference, Configure permissions, PALO IT (as of August 2026)


First-week checklist

Hook everything and you will stall on slow checks and false positives. Automate only the checks that cannot be skipped in week one.

  • Close destructive git, deletion, and secret files with deny / ask
  • Block protected paths and dangerous Bash in PreToolUse with exit 2
  • Return lint / format after Edit / Write in PostToolUse
  • Make test / build a ship condition in Stop or CI
  • Share .claude/settings.json; keep personal exceptions in settings.local.json
  • Check how managed hooks and disableAllHooks override each other
  • Launch unreviewed clones with --bare or hooks off

Add one control at a time

Add one control at a time.

  1. inspect /permissions
  2. add one deny or ask
  3. add one PreToolUse hook
  4. add one PostToolUse lint hook
  5. decide whether Stop or existing CI is the ship gate

Skip agent hooks and HTTP hooks until that loop is boring.


FAQ

Is “always lint” in CLAUDE.md enough?

No. Official docs separate instructions from permission. Must-run work belongs in hooks. Independent sources make the same contrast: prompts do not guarantee execution.


Does bypassPermissions disable hooks?

No. PreToolUse deny / exit 2 still blocks under bypass. A hook allow still cannot loosen a settings deny or ask.


Can exit 1 stop a dangerous command?

Usually not. Code-only blocking is exit 2. Exit 1 is a non-blocking error unless valid JSON says otherwise.


Where should hooks live?

Shared team policy goes in .claude/settings.json. Personal exceptions go in .claude/settings.local.json. All machines use ~/.claude/settings.json. Organizations use managed policy. Plugin hooks/hooks.json and skill / agent front matter are additional slots.


Can PostToolUse undo a dangerous action?

No. Stop it in PreToolUse. Post is for lint and feedback after the fact.


Related articles:

Summary

Close what the agent can do with permissions, then put only the remaining non-negotiable rules in hooks. Leave CLAUDE.md as a guide. Use mechanical checkers as the quality gate.

Do four things today:

  1. open /permissions
  2. deny or ask the destructive operations
  3. add one PreToolUse hook
  4. add one PostToolUse lint hook

Move the ship gate to Stop or existing CI so a failed check cannot leave the branch.

krona23

Author

krona23

Over 20 years in the IT industry, serving as Division Head and CTO at multiple companies running large-scale web services in Japan. Experienced across Windows, iOS, Android, and web development. Currently focused on AI-native transformation. At DevGENT, sharing practical guides on AI code editors, automation tools, and LLMs in three languages.

DevGENT about →

Leave a Reply

Trending