The Claude Code Changelog
All Episodes
Failing Closed with MCP Tool Hooks in Claude Code 2.1.328

Failing Closed with MCP Tool Hooks in Claude Code 2.1.328

0:00|0:00

Discover how Claude Code 2.1.328 lets you configure mcp_tool hooks to fail closed with "onFailure": "block", preventing unvalidated commands from executing when your security server goes down. We also cover auto mode updates for cloud providers, new environment variables, and essential bug fixes.


Chapter 1

Failing Closed with mcp_tool Hooks in 2.1.328

Lachlan Reed

Your security hook just went down at 2 a.m., and the agent ran the destructive command anyway. That's the default for MCP tool hooks, and version 2.1.328 gives you a way to change it. This is The Claude Code Changelog, brought to you by Jellypod AI. I'm Lachlan.

James Turner

And I'm James. So, 2.1.328 landed November 18 and 19, 2026, with 144 changes. We're picking one. You can now set "onFailure": "block" on mcp_tool hooks. Before, that option existed for shell command hooks and HTTP hooks, and in 2.1.317 for programmatic Agent SDK hooks. We covered that one in the episode on failing closed with Agent SDK hooks.

Lachlan Reed

Right, so this extends that same protection natively to MCP. Here's the default behavior. If your MCP hook hits a network error, times out, crashes, or returns something unparseable, Claude Code treats it as a non blocking error. The tool call goes ahead. That's failing open.

James Turner

And that matters because plenty of teams push compliance checks, data loss prevention, or audit logic into a central MCP server instead of local bash scripts. If that server restarts or throws an unhandled exception, your gate quietly disappears. A destructive bash command or an unauthorized write just runs, with no validation at all. Yeah.

Lachlan Reed

Setting it up is simple. In .claude/settings.json, or managed settings, or a plugin's hooks.json, you define a PreToolUse hook. Matcher is Bash. Inside, type is mcp_tool, server is, say, security-guard-server, tool is validate_command, timeout is 5, and onFailure is block. I'm reading JSON out loud, which is a bit like describing a pie chart over the phone, but that's the whole shape.

James Turner

Keep that timeout in mind. Failure includes connection timeouts, an unreachable server process, transport errors, and malformed JSON coming back from the tool handler. So a five second timeout means a slow server blocks the action after five seconds. Pick a number that's reasonable for your validator, not a guess.

Lachlan Reed

Now the caveats. First, blast radius. If you pair this with a broad matcher, like star, or even just Bash, then an MCP outage hard blocks every matched action. Your agent workflow stops completely. So scope the matcher tightly, and have a plan for who gets paged.

James Turner

Second, it only applies to events that can actually veto something. PreToolUse, UserPromptExpansion, PreModelSwitch. It won't block on events that can't veto, like Stop, SubagentStop, TaskCompleted, or async hooks. So don't expect it to be a universal kill switch.

Lachlan Reed

A few smaller things in the same release. Auto mode is now available for Opus 4.6 and Sonnet 4.6 on Amazon Bedrock, Google Cloud's Agent Platform, Microsoft Foundry, and the Claude apps gateway. Interactive sessions on those with no explicit permission mode now start in auto mode. You can turn that off with disableAutoMode.

James Turner

There's also a new env var, CLAUDE_CODE_DISABLE_DEFERRED_TOOL_RESUME. It lets host runners stop claude dash p with resume or continue from running a tool call a hook previously deferred. Zsh users get a fix too: commands starting with an equals sign, like echo and a row of equals signs, no longer throw not found from zsh's equals expansion.

Lachlan Reed

Two more worth knowing. A bug where a scheduled tasks file that failed to load, even from a typo, would wipe all saved project tasks on the next save is fixed. That hit third party providers or telemetry disabled setups. And /status and claude doctor now warn when an OpenTelemetry exporter has no endpoint, because traces and metrics would otherwise be silently dropped.

James Turner

So the takeaway: audit your mcp_tool hooks today. If one is a real security gate, add onFailure block, set a sane timeout, and narrow the matcher. Then go test it by turning the server off.