Skip to content

Instantly share code, notes, and snippets.

@ericboehs
Last active September 15, 2025 17:06
Show Gist options
  • Save ericboehs/68182f6a3642f0fe899299a08383f99d to your computer and use it in GitHub Desktop.
Save ericboehs/68182f6a3642f0fe899299a08383f99d to your computer and use it in GitHub Desktop.
#!/bin/bash
# claude-notify - Notification handler for Claude Code hooks
# Parse command line arguments
sender=""
while [[ $# -gt 0 ]]; do
case $1 in
--sender)
sender="$2"
shift 2
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Read JSON from stdin
json=$(cat)
# Get tmux info if available
if [[ -n "$TMUX" ]]; then
tmux_info=$(tmux display-message -p '#T (#S:#{window_index}.#{pane_index})')
else
tmux_info="Session"
fi
# Build terminal-notifier command with optional sender
build_notifier_cmd() {
local title="$1"
local message="$2"
local cmd="terminal-notifier -title \"$title\" -message \"$message\""
if [[ -n "$sender" ]]; then
cmd="$cmd -sender \"$sender\""
fi
echo "$cmd"
}
# Check if this is a notification with title/message or a stop hook
if echo "$json" | jq -e '.title and .message' >/dev/null 2>&1; then
# Notification payload
title=$(echo "$json" | jq -r '.title')
message=$(echo "$json" | jq -r '.message')
cmd=$(build_notifier_cmd "$title" "$tmux_info: $message")
eval "$cmd"
else
# Stop hook payload
cmd=$(build_notifier_cmd "Claude Code Stopped" "$tmux_info is ready for further instruction.")
eval "$cmd"
fi
@ericboehs
Copy link
Author

claude-notify

A notification handler for Claude Code hooks that sends macOS notifications via terminal-notifier.

Features

  • Sends desktop notifications when Claude Code operations complete
  • Integrates with tmux to show session/window/pane information
  • Supports custom sender application for notifications
  • Handles both notification payloads and stop hook events

Usage

This script is designed to be used as a Claude Code hook. It reads JSON from stdin and sends appropriate notifications.

Command Line Options

  • --sender <app>: Specify the sender application for notifications (optional)

Hook Integration

Add to your Claude Code hooks configuration to receive notifications when operations complete.

Requirements

  • macOS
  • terminal-notifier (brew install terminal-notifier)
  • jq for JSON parsing (brew install jq)
  • Optional: tmux for session information

How it works

  1. Reads JSON payload from stdin
  2. Detects if it's a notification with title/message or a stop hook
  3. Builds appropriate terminal-notifier command
  4. Includes tmux session info if available
  5. Sends desktop notification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment