HOW-TO GUIDE

How to make a Claude Code hook actually block a command with exit 2

Based on a guide by jidonglab on DEV Community · Nov 29, 2026

You'll end with: A PreToolUse guard hook that blocks with exit 2, sends its reason to Claude, and fails closed when it crashes.

Why it's worth having: Exit 1 is a non-blocking error in Claude Code, so the author's hook logged BLOCKED 19 times in three weeks while all 19 commands ran.

At a glance

WHO IT'S FOR
IT and OT engineers and developers who rely on Claude Code hooks as safety guards.
LEVEL
Intermediate
COST
Free. The hooks are bash or Python scripts that run in Claude Code.
YOU NEED
Claude Code · A PreToolUse hook in .claude/settings.json · bash or Python · jq

The method, in short

  1. 1Exit 2 to block a PreToolUse call and write the reason to stderr for Claude; any other non-zero code lets the command run.
  2. 2Turn every crash into exit 2 with an ERR trap in bash or a top-level try and except in Python, and block when jq is missing.
  3. 3Use one channel: exit 2 with stderr, or exit 0 with a JSON permissionDecision of deny, since the JSON is ignored on other exits.
  4. 4Pipe a blocked command, a safe command, and malformed input into the hook, and expect exit 2, 0, and 2.

The post has the exit code table, the fixed bash and Python hooks, and the three test commands.

More from The Feed

HOW-TO GUIDE

How to run Claude Code on a local Ollama model in a throwaway worktree

You'll end with: Claude Code driving qwen3-coder:30b on your own machine through Ollama, tested in a git worktree for tool calls, context, and speed.

WHO IT'S FOR
IT and OT engineers and developers at plants that keep code and data on their own hardware.
LEVEL
Advanced
COST
Free. Ollama and the model are free downloads; the 30b model is a 19GB download.
YOU NEED
Claude Code · Ollama v0.14.0 or later · qwen3-coder:30b · Git

Based on a guide by Gabriel Anhaia on DEV Community · Nov 28, 2026

TOOL

NVIDIA SkillSpector scans agent skills for injection before install

Engineers who install Claude Code, Codex, or MCP skills can scan each one for prompt injection, data exfiltration, and supply-chain risk before it runs.

WHAT IT DOES
An open-source scanner with 71 vulnerability patterns across 17 categories that checks agent skills and MCP servers before you install them.
WHO IT'S FOR
IT and OT engineers, security teams, and AI operations staff who vet third-party skills.
HOW TO START

Needs Python 3.12 or 3.13; an LLM provider is optional, and --no-llm runs the static checks only.

python -m pip install --upgrade skillspector

Then run skillspector scan on a skill folder, or add its MCP server so your agent gates skill installs on the result.

COST
Free under the Apache-2.0 license; LLM analysis uses your own provider account.
WHY IT MATTERS
In the 31,132-skill research subset in NVIDIA's README, 26.1% of skills contain vulnerabilities and 5.2% show likely malicious intent.
Source: GitHub
TOOL

GitHub MCP Server 2.3.0 lets agents dismiss or reopen security alerts

Software teams at industrial firms can have Claude, Copilot, or another MCP client dismiss or reopen Dependabot, code scanning, and secret scanning alerts.

WHAT IT DOES
GitHub's official MCP server, which gives AI agents tools for repos, issues, pull requests, Actions, and security alerts.
WHO IT'S FOR
Software engineers, IT teams, and security staff who triage GitHub alerts.
HOW TO START

Needs an MCP host such as VS Code 1.101 or later, and GitHub sign-in through OAuth or a personal access token.

https://api.githubcopilot.com/mcp/

Then ask the agent to review open alerts and dismiss each false positive with a reason and a comment.

COST
Free under the MIT license; the hosted server signs in with your GitHub account.
WHY IT MATTERS
Version 2.3.0 adds update_dependabot_alert, update_code_scanning_alert, and update_secret_scanning_alert, so triage no longer stops at reading alerts.
Credit: GitHub
Source: GitHub