critical severityclaude-code

    .claude/settings.json Invalid Hook Event — Why Hooks Fail Silently & Auto-Fix

    Silent Failure: Your .claude/settings.json guardrail hook never executes — zero error message shown.

    Direct-Answer Fix Summary

    Claude Code matches exact PascalCase hook event names (PreToolUse, PostToolUse, Stop, SessionStart, SessionEnd, UserPromptSubmit, Notification, PreCompact, SubagentStop). Over 35 misspelled hook keys appear across real public repos because unknown keys fail silently. Always validate JSON syntax, use exact PascalCase names, set an explicit matcher, and double-quote $CLAUDE_FILE_PATHS.

    Broken vs. Fixed Configuration

    Broken: Misspelled events + missing matcher + unquoted var
    {
      "hooks": {
        "BeforeToolUse": [
          {
            "hooks": [{ "type": "command", "command": "npx eslint $CLAUDE_FILE_PATHS" }]
          }
        ],
        "sessionStart": [
          { "hooks": [{ "type": "command", "command": "git status" }] }
        ]
      }
    }
    Fixed: Exact PascalCase + matcher + quoted variable
    {
      "hooks": {
        "PreToolUse": [
          {
            "matcher": "Edit|Write",
            "hooks": [{ "type": "command", "command": "npx eslint \"$CLAUDE_FILE_PATHS\"" }]
          }
        ],
        "SessionStart": [
          { "hooks": [{ "type": "command", "command": "git status -sb" }] }
        ]
      }
    }

    Why This Happens

    Developers guess camelCase or Git-style names like preCommit, postEditHook, BeforeToolUse, or sessionStart. Because Claude Code ignores unrecognized keys in hooks, teams believe security or lint hooks are guarding every edit when they have never fired once.

    Step-by-Step Fix

    1. 01
      Validate exact PascalCase event keys (Rule H1)

      Replace typos like BeforeToolUse -> PreToolUse, postEditHook -> PostToolUse, and sessionStart -> SessionStart.

    2. 02
      Add explicit tool matchers (Rule H2)

      Scope PreToolUse and PostToolUse with matcher strings like Edit|Write or Bash so hooks don't fire on harmless Read calls.

    3. 03
      Quote shell variables to prevent injection

      Always wrap "$CLAUDE_FILE_PATHS" and "$CLAUDE_TOOL_INPUT" in double quotes so filenames with spaces or semicolons cannot execute arbitrary commands.

    4. 04
      Run 1-Click Auto-Fix in the Hook Validator

      Paste your .claude/settings.json into AgentLint's Hook Validator to repair casing, matchers, and quoting instantly.

    Automated AgentLint Checks That Catch This

    Frequently Asked Questions

    What are all official Claude Code hook event names?

    PreToolUse, PostToolUse, PostToolUseFailure, Notification, Stop, SubagentStart, SubagentStop, UserPromptSubmit, PreCompact, SessionStart, SessionEnd, and PermissionRequest.

    Why does AgentLint rule H3 warn on Stop hooks without a circuit breaker?

    If a Stop hook blocks completion whenever tests fail without checking stop_hook_active, Claude Code can enter an infinite retry loop burning tokens.

    Related Troubleshooting Guides