aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/__claude-code-notify
blob: 351f0d521855ee3b60389f1be82ff48d5ee8377c (plain)
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
#!/usr/bin/env bash

input="$(cat)"

message="$(jq -r '.message // "Task completed"' <<<"$input")"

if [ "$message" = "Claude is waiting for your input" ]; then
    exit # it's annoying
fi

# Skip notification if any background task is still running.
if [ "$1" = "Stop" ]; then
    if jq -e '.background_tasks // [] | length > 0' >/dev/null 2>&1 <<<"$input"; then
        exit
    fi
fi

if [ "$(uname)" = "Darwin" ]; then
    if [ "$1" = "Stop" ]; then
        sound=Glass
    else
        sound=Funk
    fi
    osascript \
        -e 'on run argv' \
        -e 'display notification (item 1 of argv) with title (item 2 of argv) sound name (item 3 of argv)' \
        -e 'end run' \
        -- "$message" "Claude Code" "$sound"
else
    if [ "$1" = "Stop" ]; then
        sound=complete
    else
        sound=bell
    fi
    notify-send "Claude Code" "$message" --hint "string:sound-name:$sound"
fi