From 930919d97d7102869dadfd6240da67b67423e2ce Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Fri, 1 May 2026 14:38:33 -0500 Subject: [PATCH 1/2] chore: add prettier auto-format hook for Claude Code Adds .claude/settings.json with a PostToolUse hook that runs prettier on files after Write/Edit/MultiEdit/NotebookEdit operations. Ensures code is formatted automatically rather than relying on the agent to follow the "format with prettier before committing" instruction in CLAUDE.md (which was missed in PR #1036). Co-Authored-By: Claude Opus 4.7 (1M context) --- .claude/settings.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .claude/settings.json diff --git a/.claude/settings.json b/.claude/settings.json new file mode 100644 index 000000000..9d01d6687 --- /dev/null +++ b/.claude/settings.json @@ -0,0 +1,16 @@ +{ + "hooks": { + "PostToolUse": [ + { + "matcher": "Write|Edit|MultiEdit|NotebookEdit", + "hooks": [ + { + "type": "command", + "command": "jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; case \"$f\" in \"$PWD\"/*) npx --no-install prettier --write --ignore-unknown \"$f\" ;; esac; } 2>/dev/null || true", + "timeout": 30 + } + ] + } + ] + } +} From 834aee0d9c13051473cb70c3f6106afd606b768a Mon Sep 17 00:00:00 2001 From: Duane Nykamp Date: Sun, 3 May 2026 00:27:59 -0500 Subject: [PATCH 2/2] chore: harden prettier hook per PR review feedback - Redirect jq stderr to suppress noise on missing/erroring jq - Guard against empty file path with [ -n "$f" ] check - Use realpath to normalize paths before comparison, blocking path traversal via .. segments Co-Authored-By: Claude Sonnet 4.6 --- .claude/settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.claude/settings.json b/.claude/settings.json index 9d01d6687..2ca24275d 100644 --- a/.claude/settings.json +++ b/.claude/settings.json @@ -6,7 +6,7 @@ "hooks": [ { "type": "command", - "command": "jq -r '.tool_response.filePath // .tool_input.file_path' | { read -r f; case \"$f\" in \"$PWD\"/*) npx --no-install prettier --write --ignore-unknown \"$f\" ;; esac; } 2>/dev/null || true", + "command": "jq -r '.tool_response.filePath // .tool_input.file_path' 2>/dev/null | { read -r f; [ -n \"$f\" ] && repo_root=$(realpath \"$PWD\") && target=$(realpath \"$f\") && case \"$target\" in \"$repo_root\"|\"$repo_root\"/*) npx --no-install prettier --write --ignore-unknown \"$target\" ;; esac; } 2>/dev/null || true", "timeout": 30 } ]