Skip to content

Instantly share code, notes, and snippets.

@quiiver
Created April 10, 2026 21:41
Show Gist options
  • Select an option

  • Save quiiver/dcfa5d9423d7a7517c48a7bd18fee930 to your computer and use it in GitHub Desktop.

Select an option

Save quiiver/dcfa5d9423d7a7517c48a7bd18fee930 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
EVENT="${1:-}"
PANE="${TMUX_PANE:-}"
# helper: get window name for the Claude pane (not the focused window)
get_window_name() {
tmux display-message -t "$PANE" -p '#{window_name}'
}
# helper: only mark if not already marked
mark_window() {
local name
name=$(get_window_name)
# don't double-prefix
if [[ "$name" !=* ]]; then
tmux set-option -t "$PANE" -w @original_name "$name"
tmux rename-window -t "$PANE" "${name}"
# set a tmux focus hook to auto-reset when the window gets focus
tmux set-hook -t "$PANE" -w pane-focus-in "run-shell '$0 reset-from-tmux $PANE'"
fi
}
# helper: reset window name and clean up
reset_window() {
local pane="${1:-$PANE}"
local name
name=$(tmux show-option -t "$pane" -wqv @original_name 2>/dev/null || true)
if [ -n "$name" ]; then
tmux rename-window -t "$pane" "$name"
tmux set-option -t "$pane" -wu @original_name
tmux set-hook -t "$pane" -uw pane-focus-in 2>/dev/null
fi
}
case "$EVENT" in
question)
terminal-notifier \
-title 'Claude Code' \
-message 'Claude is asking a question' \
-sound default \
-sender com.apple.Terminal \
-group "claude-$(date +%s)"
if [ -n "$PANE" ]; then
mark_window
fi
;;
permission)
terminal-notifier \
-title 'Claude Code' \
-message 'Permission needed' \
-sender com.apple.Terminal \
-group "claude-$(date +%s)"
if [ -n "$PANE" ]; then
mark_window
fi
;;
reset)
if [ -n "$PANE" ]; then
reset_window "$PANE"
fi
;;
reset-from-tmux)
# called by tmux focus hook — pane passed as arg since no $TMUX_PANE
if [ -n "${2:-}" ]; then
reset_window "$2"
fi
;;
*)
echo "Usage: claude-notify <question|permission|reset>" >&2
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment