PulseAugur
中
实时 10:04:25
English(EN) Claude Code Hook Exit Codes: exit 1 Let 19 'Blocked' Commands Run

Claude Code Hooks 出现错误时未正确阻止,阻止需要退出码 2

用户发现 Claude Code 的 PreToolUse hooks 在以错误码 1 退出时默认不阻止命令。相反,Claude Code 仅将退出码 2 识别为阻止错误,允许工具调用继续执行,同时显示错误消息。为确保安全 hooks 正确运行,用户必须明确将其配置为在任何阻止条件下退出码为 2,或实现一个机制来捕获其他非零退出码并将其转换为退出码 2。这一点至关重要,因为崩溃的 hook 或具有非阻止错误码的 hook 将会失败并打开,允许潜在的有害命令执行。 AI

影响 Claude Code 的用户必须调整其安全 hook 配置,以确保命令被正确阻止。

排序理由 用户在特定产品功能中发现的行为。

在 dev.to — Claude Code tag 阅读 →

AI 生成摘要 · Google Gemini · 来自 1 个来源。 我们如何撰写摘要 →

Claude Code Hooks 出现错误时未正确阻止,阻止需要退出码 2

报道来源 [1]

  1. dev.to — Claude Code tag TIER_1 English(EN) · jidonglab ·

    Claude Code Hook 退出码:exit 1 允许 19 个“被阻止”的命令运行

    <p>My guard hook printed <code>BLOCKED: rm -rf outside project</code> nineteen times in three weeks. I felt great about it. Then I lined the hook log up against the session transcripts and found that all nineteen commands had run anyway.</p> <p>The hook did exactly what I told it…