Skip to content

Commit 6f2140e

Browse files
ankurdotbclaude
andcommitted
fix: correct Claude Code hooks schema to use nested hooks array with jq stdin parsing
The hooks were using an invalid flat command format and nonexistent $CLAUDE_FILE_PATH env var. Fixed to use the required nested hooks array structure and parse file_path from stdin JSON via jq. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 181aa50 commit 6f2140e

3 files changed

Lines changed: 875 additions & 909 deletions

File tree

.claude/settings.json

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
{
2-
"hooks": {
3-
"PreToolUse": [
4-
{
5-
"matcher": "Edit|Write",
6-
"command": "echo \"$CLAUDE_FILE_PATH\" | grep -qE '(package-lock\\.json|src/database/migrations/)' && echo 'BLOCK: Do not edit generated files (lock files, migrations)' && exit 1 || exit 0"
7-
}
8-
],
9-
"PostToolUse": [
10-
{
11-
"matcher": "Edit|Write",
12-
"command": "npx prettier --write \"$CLAUDE_FILE_PATH\" 2>/dev/null || true"
13-
}
14-
]
15-
}
2+
"hooks": {
3+
"PreToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "FILE=$(jq -r '.tool_input.file_path') && echo \"$FILE\" | grep -qE '(package-lock\\.json|src/database/migrations/)' && echo 'BLOCK: Do not edit generated files (lock files, migrations)' && exit 1 || exit 0"
10+
}
11+
]
12+
}
13+
],
14+
"PostToolUse": [
15+
{
16+
"matcher": "Edit|Write",
17+
"hooks": [
18+
{
19+
"type": "command",
20+
"command": "jq -r '.tool_input.file_path' | xargs npx prettier --write 2>/dev/null || true"
21+
}
22+
]
23+
}
24+
]
25+
}
1626
}

0 commit comments

Comments
 (0)