claude-memory/graph/fixes/fix-claude-code-posttooluse-hook-correct-json-format-be0bda.md
2026-03-01 20:20:38 -06:00

2.2 KiB

id type title tags importance confidence created updated relations
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:20:38.872040+00:00
target type direction strength edge_id
62ee21e8-2b56-4d38-a73d-47e2724f08c6 BUILDS_ON outgoing 0.78 98dd95aa-3b6e-4b89-aa90-5877eb37e1a2
target type direction strength edge_id
ba189013-3890-4464-a22d-cdc3d68d8068 BUILDS_ON outgoing 0.86 0b72d209-d461-463c-a720-cf8d47ef5fe8
target type direction strength edge_id
e9e6a15a-bec3-4b62-98c9-4a70a5165348 RELATED_TO outgoing 0.81 d1f29f3c-3be1-48f8-9ea1-aea48bbacf3a
target type direction strength edge_id
a2d02aea-07fd-4528-8158-f2f42a23a2dd RELATED_TO outgoing 0.8 ceebc50e-6db0-444e-b31d-36344913dc12
target type direction strength edge_id
a2d02aea-07fd-4528-8158-f2f42a23a2dd SOLVES outgoing 0.95 b5623458-9ace-43ae-ae7e-101d465498ee

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