2.2 KiB
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 |
|
0.8 | 0.8 | 2026-03-02T02:08:35.272129+00:00 | 2026-03-02T02:20:38.872040+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
PostToolCallinstead ofPostToolUse - Used
matcheras an object withtool_name/file_globfields 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(notPostToolCall) matcher: plain regex string matching tool nameshooks: array of objects withtype: "command"andcommandstring- File filtering: must be done inside the shell command using
$TOOL_INPUTenv var