-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnotify.sh
More file actions
executable file
·90 lines (85 loc) · 2.44 KB
/
Copy pathnotify.sh
File metadata and controls
executable file
·90 lines (85 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -euo pipefail
payload="$(cat)"
hook_event="$(jq -r '.hook_event_name // empty' <<<"$payload")"
tool_name="$(jq -r '.tool_name // empty' <<<"$payload")"
notification_type="$(jq -r '.notification_type // empty' <<<"$payload")"
msg="$(jq -r '.message // empty' <<<"$payload")"
# Build title with tmux session:window from the pane that owns this process
cwd="$(jq -r '.cwd // empty' <<<"$payload")"
cwd_short="${cwd##*/}"
tmux_info=""
if command -v tmux &>/dev/null && tmux list-sessions &>/dev/null 2>&1; then
# Walk up the process tree to find the PID that lives in a tmux pane
pid=$$
while [[ -n "$pid" && "$pid" -ne 1 ]]; do
pane_info="$(tmux list-panes -a -F '#{pane_pid} #{session_name} #{window_index}' 2>/dev/null \
| awk -v p="$pid" '$1 == p {print $2, $3; exit}')"
if [[ -n "$pane_info" ]]; then
tmux_info="$pane_info"
break
fi
pid="$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')"
done
fi
if [[ -n "$tmux_info" ]]; then
tmux_session="${tmux_info% *}"
tmux_window="${tmux_info#* }"
title="Claude [$tmux_session] #$tmux_window"
else
title="Claude — $cwd_short"
fi
notify() {
terminal-notifier -title "$title" -message "$1" -sound "${2:-default}" -group "claude-notify"
}
case "$hook_event" in
PermissionRequest)
case "$tool_name" in
Bash)
desc="$(jq -r '.tool_input.description // empty' <<<"$payload")"
if [[ -n "$desc" ]]; then
notify "Permission: $desc"
else
cmd="$(jq -r '.tool_input.command // empty' <<<"$payload" | head -c 80)"
notify "Permission: Bash — $cmd"
fi
;;
Write|Edit|Read)
file="$(jq -r '.tool_input.file_path // empty' <<<"$payload")"
basename="${file##*/}"
notify "Permission: $tool_name $basename"
;;
ExitPlanMode)
notify "Approve plan"
;;
AskUserQuestion)
notify "Claude has a question"
;;
*)
notify "Permission: $tool_name"
;;
esac
;;
Notification)
case "$notification_type" in
permission_prompt)
notify "${msg:-Permission needed}"
;;
idle_prompt)
notify "Claude needs input"
;;
elicitation_dialog)
notify "Claude has a question"
;;
*)
notify "${msg:-Needs attention}"
;;
esac
;;
Stop)
notify "Claude finished" "Glass"
;;
*)
notify "${msg:-Needs attention}"
;;
esac