Add to Claude Code
41 addsInstall this Claude Code hook.
Name: iMessage Notify on Complete
Save to: ~/.claude/hooks/imessage-notify-on-complete.sh
Make executable: yes
---
#!/usr/bin/env bash
# Hook type: Stop
# Trigger: When Claude Code completes a session or long task
#
# Sends an iMessage to a configured phone number when Claude finishes.
# macOS only — uses AppleScript to send via Messages.app.
#
# Place this in your hooks config:
# hooks:
# Stop:
# - matcher: ""
# hooks:
# - type: command
# command: /path/to/imessage-notify.sh
set -euo pipefail
# ── Configuration ─────────────────────────────────────────────────────────────
NOTIFY_NUMBER="${IMESSAGE_NOTIFY_NUMBER:-+1XXXXXXXXXX}" # set in env or edit here
# ──────────────────────────────────────────────────────────────────────────────
# Read the stop reason from stdin (JSON)
INPUT=$(cat)
REASON=$(echo "$INPUT" | python3 -c "
import sys, json
d = json.load(sys.stdin)
print(d.get('stop_reason', 'completed'))
" 2>/dev/null || echo "completed")
MESSAGE="Claude Code has finished ($REASON)."
# Send via AppleScript
osascript -e "
tell application \"Messages\"
set targetService to 1st account whose service type = iMessage
set targetBuddy to participant \"$NOTIFY_NUMBER\" of targetService
send \"$MESSAGE\" to targetBuddy
end tell
" 2>/dev/null
# Fallback: if Messages.app isn't available, try terminal-notifier
if [ $? -ne 0 ] && command -v terminal-notifier &>/dev/null; then
terminal-notifier -title "Claude Code" -message "$MESSAGE"
fi
Paste into Claude Code to add this hook. Review the source first.
This is a shell script. Review the source before running: view raw.
How to add
Full guide →Click Add, then paste into Claude Code. Claude will configure the hook in your settings.
Target: .claude/settings.json → hooks