Claude Hook Configuration: settings.json#
The PostToolUse hook is registered in the .claude/settings.json file. This configuration tells Claude which tools should trigger the hook and what command to execute.
Configuration Details#
{
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/after_edit.sh"
}
]
}
]
}
}
Key Elements:#
-
PostToolUse: This hook runs after a tool has been executed but before the result is returned to the model (if it's a blocking hook). -
matcher: "Write|Edit": This regex-like matcher ensures the hook only triggers when Claude uses tools likewrite_to_fileoredit_file. -
type: "command": Specifies that the hook will run an external shell command. -
command: The absolute path to the shell script. Using$CLAUDE_PROJECT_DIRmakes the path relative to the project root, ensuring portability.