Claude CodeIntermediate

How to Get a Notification When Claude Code Finishes a Task

Use a Stop hook to fire a desktop or sound notification the moment Claude Code finishes responding.

6 minIntermediate

When you give Claude Code a long task and switch to another window, it is easy to miss when it finishes. The Stop hook runs the moment the main agent stops responding, which makes it perfect for a finished notification. This guide adds a sound and a desktop alert on macOS, with notes for other systems.

  • Claude Code with hooks support
  • A terminal that can run a small shell script
  • On macOS, the built-in osascript and afplay commands

Step 1: Write the notification script

Keep it tiny. On macOS, osascript shows a banner and afplay rings a system sound. On Linux you would swap in notify-send; on Windows, a PowerShell toast.

.claude/hooks/notify.sh
#!/usr/bin/env bash
# macOS: banner + sound when Claude Code stops
osascript -e 'display notification "Task finished" with title "Claude Code"'
afplay /System/Library/Sounds/Glass.aiff 2>/dev/null || true
zsh - my-project
$chmod +x .claude/hooks/notify.sh
$

Step 2: Register it on the Stop event

The Stop event has no tool to match, so the matcher can be empty or omitted. Add it to settings.json under the Stop array.

.claude/settings.json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/notify.sh"
          }
        ]
      }
    ]
  }
}
.claude/settings.json
Explorer
hooks
settings.json
.claude/settings.json
1{
2 "hooks": {
3 "Stop": [
4 { "hooks": [ { "type": "command", "command": "...notify.sh" } ] }
5 ]
6 }
7}
Stop hooks need no matcher because there is no tool involved.
Use the Notification event too
There is a separate Notification hook event that fires when Claude needs your input or permission. Wire the same script there to also get pinged when a task is waiting on you, not just when it ends.

Step 3: Test it

Run any quick request and switch away. When Claude finishes, the banner appears and the sound plays. If nothing happens, run the script directly in your terminal to confirm the notification commands work on your machine.

macOS notification
Claude Code
Task finished
(Glass.aiff played)

Result: a hands-off alert every time Claude Code finishes, so you can run long tasks in the background and get pulled back exactly when there is something to look at.

Watch related tutorials

Tags
#hooks#notifications#automation#stop