Add notification and formatting hooks to Claude Code
Choose the right hook event, preserve existing settings and check that the action actually runs.
Originally posted · Published here · 1 source · Resume reading
Claude Code hooks run commands at specified events. The official guide uses Notification for desktop alerts and PostToolUse for formatting after an edit. [1]
Add an alert without replacing settings
In ~/.claude/settings.json, merge a Notification event into the existing hooks object. The guide supplies separate macOS, Linux and Windows examples. On macOS it uses osascript; Linux uses notify-send. [1]
Use the permission_prompt matcher when you want approval alerts rather than every notification. Open /hooks inside Claude Code and check that the event appears. Then trigger a permission request and confirm you receive the alert. [1]
Scope the formatter
The guide uses a PostToolUse event with the Edit|Write matcher. Its example reads the edited path from the hook input and runs Prettier. It requires jq. [1]
Before enabling automatic formatting, check which files your formatter supports and how its command handles paths containing spaces. Try a disposable file and inspect the diff.
Hooks execute commands with your environment's permissions. Read commands copied from another repository before putting them in settings. [1]
Keep this guide
Filed under Claude Code
Sources
- Claude Code hooks guidecode.claude.com
Next in this stack
Keyword SPEC
Five Claude Code habits for spec-first development
Keyword HOOKLIGHT
Use Claude Code hooks for status notifications
Keyword SLIDES
Choose a slide tool for Claude Code