Add PostToolUse hook for auto-formatting Python with uvx black

- New hooks/format-code.sh: reads file path from stdin JSON, dispatches
  by extension (*.py → uvx black, *.js/ts → prettier)
- Updated settings.json: PostToolUse hook on Edit/Write/MultiEdit

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-14 21:49:54 -06:00
parent 197848749d
commit efebbc7a95
2 changed files with 24 additions and 0 deletions

12
hooks/format-code.sh Executable file
View File

@ -0,0 +1,12 @@
#!/bin/bash
# Read tool input from stdin (JSON with tool_input.file_path)
FILE=$(jq -r '.tool_input.file_path // empty' 2>/dev/null)
[ -z "$FILE" ] && exit 0
case "$FILE" in
*.py)
uvx black --quiet "$FILE" ;;
*.js|*.ts|*.jsx|*.tsx)
prettier --write "$FILE" 2>/dev/null ;;
esac

View File

@ -103,6 +103,18 @@
},
"effortLevel": "medium",
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit",
"hooks": [
{
"type": "command",
"command": "/home/cal/.claude/hooks/format-code.sh",
"timeout": 10
}
]
}
],
"SessionEnd": [
{
"hooks": [