10 October 2026
خلّ حماية Claude Code تفشل بشكل مغلق مع onFailureMake Claude Code Hooks Fail Closed with onFailure Block
Set up a Claude Code hook that blocks risky commands, and make it fail closed so a broken hook can never let a command through.
Who this guide is for
Founders and developers who run Claude Code on real projects and want a safety net.
Key terms
- Hook
- A script Claude Code runs automatically at a set moment, for example before it uses a tool.
- PreToolUse
- The hook moment that fires just before Claude runs a tool such as Bash. Your script can allow or block the call.
- Fail open
- If the hook itself breaks, the action still runs. This is the default.
- Fail closed
- If the hook breaks, the action is blocked. This is what onFailure block gives you.
The steps
Step 1
Check your version
The onFailure option needs Claude Code 2.1.295 or later. Run the command below in your terminal. If the number is lower, update Claude Code first.
Older versions ignore the option, so the hook would still fail open and you would not know.
PromptVersion checkclaude --version
5 more steps wait for you after access
With the ready prompts and the takeaway
Bought this before? Restore your access
Your access is tied to your email. Enter it here and the content opens right away, any time, on any device
Most value
Start building with me now
We sit together, break down your problem, and I build the AI solution with you step by step
- A private session with you
- Real building during the session
- Results you take with you when we finish
100% free
A free consultation about your problem