Skip to content

Commit 033b943

Browse files
authored
chore: claude post-write hook causes error when IDE checks output and doesn't apply formatting correctly (#15445)
- Swap eslint/prettier order for JS/TS files so prettier formats the braces eslint adds - Suppress stdout from formatting commands ([hook runners expect JSON or no output](https://cursor.com/docs/agent/hooks#command-based-hooks). (claude docs [here](https://code.claude.com/docs/en/hooks#advanced:-json-output))). Previously, the script filled the cursor hook execution log with errors - Use pnpm instead of npx to ensure it uses the prettier/eslint version installed in our monorepo ## Why The original hook ran prettier before eslint, so when eslint added missing braces (e.g., `if (x) return y` → `if (x) {return y}`), prettier never re-ran to format them onto separate lines. Usually it's safer to run eslint before prettier, because eslint does all lint auto-fixes without formatting in mind, and the formatting prettier applies usually does not create a need to re-lint. This is not the case the other way around. Stdout suppression is needed because prettier outputs filenames (e.g., `file.ts 50ms`) which hook runners interpret as malformed JSON responses. ## Cursor Hook Execution Log ### Previous ![Screenshot 2026-01-30 at 18 09 34](https://github.com/user-attachments/assets/0b775ccf-e048-46dc-b0a5-30d818a01edd) ### After ![Screenshot 2026-01-30 at 18 10 03](https://github.com/user-attachments/assets/5d073c40-41d1-4dc5-8983-1bec2d6912d3)
1 parent 9c8be5c commit 033b943

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ fi
2121
# Format based on file type
2222
case "$FILE" in
2323
*/package.json)
24-
npx sort-package-json "$FILE" 2>/dev/null
24+
pnpm sort-package-json "$FILE" >/dev/null 2>&1
2525
;;
2626
*.yml|*.json)
27-
npx prettier --write "$FILE" 2>/dev/null
27+
pnpm prettier --write "$FILE" >/dev/null 2>&1
2828
;;
2929
*.md|*.mdx)
30-
npx prettier --write "$FILE" 2>/dev/null
30+
pnpm prettier --write "$FILE" >/dev/null 2>&1
3131
if command -v markdownlint >/dev/null 2>&1; then
32-
markdownlint -i node_modules "$FILE" 2>/dev/null
32+
markdownlint -i node_modules "$FILE" >/dev/null 2>&1
3333
fi
3434
;;
3535
*.js|*.jsx|*.ts|*.tsx)
36-
npx prettier --write "$FILE" 2>/dev/null
37-
npx eslint --cache --fix "$FILE" 2>/dev/null
36+
pnpm eslint --cache --fix "$FILE" >/dev/null 2>&1
37+
pnpm prettier --write "$FILE" >/dev/null 2>&1
3838
;;
3939
esac
4040

0 commit comments

Comments
 (0)