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
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.
- Run
/permissionsand note which file owns each rule. - Put destructive git, deletion, and production deploys on scoped deny or ask.
Bash(rm *)is the usual example. A bareBashdeny removes the tool from context. Keep the tool and block only matching calls with a specifier. - 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 /andrm -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.
- Add
hooksto shared.claude/settings.jsonand confirm with/hooks. The menu is read-only; edit the JSON. - Match PreToolUse on
Bash, addif: Bash(rm *)(or your protected path), and deny with JSON or exit 2. - Match PostToolUse on
Edit|Write, run lint or format, and return failures so Claude can fix immediately. - 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_promptfires after about 6 seconds of no input idle_promptafter 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 -pon an unreviewed clone treats the folder as trusted, so project hooks run immediately. Prefer--bareordisableAllHooksfirst.
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 insettings.local.json - Check how managed hooks and
disableAllHooksoverride each other - Launch unreviewed clones with
--bareor hooks off
Add one control at a time
Add one control at a time.
- inspect
/permissions - add one deny or ask
- add one PreToolUse hook
- add one PostToolUse lint hook
- 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:
- open
/permissions - deny or ask the destructive operations
- add one PreToolUse hook
- add one PostToolUse lint hook
Move the ship gate to Stop or existing CI so a failed check cannot leave the branch.
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.
🔥 Most Popular
- Claude Code CLI vs Web vs Desktop: Essential 2026 Guide
- Agent Loops and Harnesses: Key Design Points for AI Development with Claude Code
- AI Code Editor Comparison 2026: 6 Tools Tested, Why I Use Zed + Claude Code
- Install OpenClaw: Node 24 or 26 (November 2026)
- 12 Workflow Improvements Switching Claude Code from CLI to Desktop














Leave a Reply