Hook Configuration in AI
From the Claude Code cheat sheet ยท Hooks System ยท verified Jul 2026
Hook Configuration
Setting up hooks in settings.json
json
# ~/.claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "jq -r '\"Running: \" + .tool_input.command' >> ~/.claude/log.txt"
}
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "python3 ~/.claude/hooks/validate_prompt.py"
}
]
}
]
}
}json
// EXAMPLE: Log all bash commands
{
"hooks": {
"PreToolUse": [{
"matcher": "Bash",
"hooks": [{
"type": "command",
"command": "date >> ~/.claude/bash.log && echo '{{tool_input.command}}' >> ~/.claude/bash.log"
}]
}]
}
}๐ Matcher filters by tool name
๐ Can run commands or scripts
๐ Access tool data via placeholders
hooksconfig