Auto-format Claude Code's output with a PostToolUse hook
A `PostToolUse` hook on Write/Edit fires your formatter every time Claude touches a file — no more manual prettier/eslint runs before push.
- Type: Prompt
- Tags: Coding Agent Hacks, Intermediate, Claude Code
- Updated: 2026-10-01
Prompt
A `PostToolUse` hook on Write/Edit fires your formatter every time Claude touches a file — no more manual prettier/eslint runs before push. Claude usually writes clean code, but the last 10% of formatting inconsistencies means you're still running your formatter by hand before you can push. Claude Code creator Boris Cherny shared a `PostToolUse` hook that triggers automatically on every Write or Edit. Drop it in `.claude/settings.json` for one project or `~/.claude/settings.json` for global. The `|| true` keeps a transient formatter failure from crashing the session. Implementation example: // .claude/settings.json (or ~/.claude/settings.json) { "hooks": { "PostToolUse": [ { "matcher": "Write|Edit", "hooks": [ { "type": "command", "command": "bun run format || true" } ] } ] } }
More prompts
- Expense Report Automation System — Save More Time
- Meeting Scheduling Link Standardization — Save More Time
- Invoice Generation and Delivery Automation — Save More Time
- Document Template Automation Library — Save More Time
- Calendar Management Automation Rules — Save More Time
- File Organization and Naming System — Save More Time
- Recurring Payment Automation Setup — Save More Time
- Data Entry Elimination Framework — Save More Time