Purpose: Auto-format files after Claude edits them
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{
"type": "command",
"command": "jq -r '.tool_input.file_path' | { read file_path; if echo \"$file_path\" | grep -q '\\.ts$'; then npx prettier --write \"$file_path\"; fi; }"
}]
}]
}
}
.ts extensionGo files:
if echo "$file_path" | grep -q '\\.go$'; then gofmt -w "$file_path"; fi
Python files:
if echo "$file_path" | grep -q '\\.py$'; then black "$file_path"; fi
Multiple extensions:
if echo "$file_path" | grep -qE '\\.(ts|tsx|js|jsx)$'; then npx prettier --write "$file_path"; fi
../../lookup/hook-events.md - Hook events reference./protection-hook.md - File protection exampleReference: https://docs.anthropic.com/en/docs/claude-code/hooks