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:
parent
197848749d
commit
efebbc7a95
12
hooks/format-code.sh
Executable file
12
hooks/format-code.sh
Executable 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
|
||||
@ -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": [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user