Stackmark › Prompts

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

Privacy · Terms · llms.txt