Skip to content

Commit 3d59dde

Browse files
committed
Tooling: Add post-edit autoformat hook for Claude
1 parent 122182d commit 3d59dde

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

.claude/hooks/post-edit-format.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# PostToolUse hook - auto-formats files after Claude edits them
3+
4+
input=$(cat)
5+
file_path=$(echo "$input" | jq -r '.tool_input.file_path // empty')
6+
7+
if [[ -z "$file_path" ]]; then exit 0; fi
8+
9+
case "$file_path" in
10+
*.ts|*.svelte|*.js|*.css)
11+
cd "$(dirname "$0")/../.." && pnpm exec prettier --write "$file_path" 2>/dev/null
12+
;;
13+
*.rs)
14+
rustfmt "$file_path" 2>/dev/null
15+
;;
16+
*.go)
17+
gofmt -w "$file_path" 2>/dev/null
18+
;;
19+
esac
20+
exit 0

.claude/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@
1515
}
1616
]
1717
}
18+
],
19+
"PostToolUse": [
20+
{
21+
"matcher": "Edit|Write",
22+
"hooks": [
23+
{
24+
"type": "command",
25+
"command": ".claude/hooks/post-edit-format.sh"
26+
}
27+
]
28+
}
1829
]
1930
}
2031
}

0 commit comments

Comments
 (0)