Skip to content

Commit c2a71fb

Browse files
committed
ai: add Claude Code hook to apply Prettier
1 parent eedcf9e commit c2a71fb

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

.claude/hooks/format-files.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Format files with Prettier after write/edit
3+
4+
file_path=$(jq -r '.tool_input.file_path' 2>/dev/null)
5+
6+
if [ -z "$file_path" ] || [ "$file_path" = "null" ]; then
7+
exit 0
8+
fi
9+
10+
# Run Prettier, suppress errors, always exit 0
11+
npx prettier --write "$file_path" 2>/dev/null || true

.claude/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Write|Edit",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/format-files.sh"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)