claude-memory/graph/fixes/fix-claude-code-posttooluse-hook-correct-json-format-be0bda.md

1.4 KiB

id type title tags importance confidence created updated
be0bda86-d893-4f86-97c4-0ca4e1073121 fix Fix: Claude Code PostToolUse hook correct JSON format
sba-scouting
rust
claude-code
hooks
configuration
fix
0.8 0.8 2026-03-02T02:08:35.272129+00:00 2026-03-02T02:08:35.272129+00:00

Claude Code PostToolUse Hook Correct Format

Problem

Claude Code hooks were not firing because the configuration used incorrect field names and structure.

Root Cause

  • Used PostToolCall instead of PostToolUse
  • Used matcher as an object with tool_name/file_glob fields instead of a plain regex string
  • File glob filtering is NOT supported in the matcher field — must be done in the shell command itself

Solution

The correct format for .claude/settings.json:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "if echo \"$TOOL_INPUT\" | grep -q '\\.rs'; then cargo check --message-format=short 2>&1 | grep '^src/' | head -20; fi"
          }
        ]
      }
    ]
  }
}

Key Rules

  • Event key: PostToolUse (not PostToolCall)
  • matcher: plain regex string matching tool names
  • hooks: array of objects with type: "command" and command string
  • File filtering: must be done inside the shell command using $TOOL_INPUT env var