Claude notifications: clicking one brings back the app Claude runs in

Ports CoreDesktop's 4fb3539.

The hooks ran notify-send from inside Claude, so the desktop couldn't tell
which app the notification came from and clicking it did nothing.
system/claude-notify finds the terminal or editor among Claude's parent
processes (or tmux's client, or the Flatpak) and names it in the
desktop-entry hint. The title shows the project folder and the body
Claude's own message.

configure agents writes the hooks through it, and swaps the old
notify-send ones for it, only where they're still the ones it wrote.
update doesn't change settings, so old hooks make configure agents to do
until it has swapped them.

Smoketest: 35-claude-notify. TEST.md: click one on COSMIC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 19:00:43 -07:00
co-authored by Claude Opus 5.5
parent dfb43c866c
commit 2952034654
7 changed files with 203 additions and 14 deletions
+76
View File
@@ -0,0 +1,76 @@
# shellcheck shell=bash
# Scenarios set what the runner and items read
# shellcheck disable=SC2034
DESCRIPTION="Claude Code's notifications name the app Claude runs in, and old hooks are swapped"
TIER=quick
# A fake /proc: pid $1 runs $2 under pid $3
fake_proc() {
mkdir -p "$PROC/$1"
echo "$2" > "$PROC/$1/comm"
printf 'Name:\t%s\nPPid:\t%s\n' "$2" "$3" > "$PROC/$1/status"
}
scenario() {
local bin="$HOME/.local/bin" sent="$HOME/sent" notify="$CONNECTOR/system/claude-notify" apps
PROC="$HOME/proc"
apps="$HOME/.local/share/applications"
mkdir -p "$bin" "$apps"
# A stand-in notify-send that records its arguments, one per line
printf '#!/bin/bash\nprintf "%%s\\n" "$@" > %q\n' "$sent" > "$bin/notify-send"
chmod +x "$bin/notify-send"
step "system/claude-notify"
# COSMIC Terminal (40) runs bash (41), which runs claude (42), which runs the hook
fake_proc 40 cosmic-term 1
fake_proc 41 bash 40
fake_proc 42 claude 41
touch "$apps/com.system76.CosmicTerm.desktop"
echo '{"message": "Claude needs your permission", "cwd": "/home/pop/Projects/demo"}' \
| XDG_DATA_DIRS="$HOME/none" CLAUDE_NOTIFY_PROC="$PROC" CLAUDE_NOTIFY_PID=42 "$notify" 'Needs your input'
check "it names COSMIC Terminal" grep -qxF -- "--hint=string:desktop-entry:com.system76.CosmicTerm" "$sent"
check "the title is the project folder" grep -qxF "Claude Code: demo" "$sent"
check "the body is Claude's message" grep -qxF "Claude needs your permission" "$sent"
echo '{"cwd": "/home/pop/Projects/demo"}' \
| XDG_DATA_DIRS="$HOME/none" CLAUDE_NOTIFY_PROC="$PROC" CLAUDE_NOTIFY_PID=42 "$notify" 'Task completed'
check "without a message, the hook's own text" grep -qxF "Task completed" "$sent"
rm "$apps/com.system76.CosmicTerm.desktop"
echo '{}' | XDG_DATA_DIRS="$HOME/none" CLAUDE_NOTIFY_PROC="$PROC" CLAUDE_NOTIFY_PID=42 "$notify" 'Task completed'
check_not "no app it can't find a desktop entry for" grep -q desktop-entry "$sent"
echo '{}' | XDG_DATA_DIRS="$HOME/none" FLATPAK_ID=com.vscodium.codium "$notify" 'Task completed'
check "inside a Flatpak, the Flatpak" grep -qxF -- "--hint=string:desktop-entry:com.vscodium.codium" "$sent"
step "configure agents' hooks"
source "$CONNECTOR/configure.d/30-agents.sh"
rm -f "$CLAUDE_SETTINGS"
check "claude_notifications writes them" claude_notifications
check_eq "through claude-notify" "$CLAUDE_NOTIFY 'Needs your input'" \
"$(jq -r '.hooks.Notification[0].hooks[0].command' "$CLAUDE_SETTINGS")"
check_not "they aren't the old ones" old_claude_notifications
# Settings written before claude-notify, with a hook of your own
cat > "$CLAUDE_SETTINGS" << 'EOF'
{
"model": "opus",
"hooks": {
"Notification": [{"matcher": "", "hooks": [{"type": "command", "command": "notify-send 'Claude Code' 'Needs your input'"}]}],
"Stop": [{"matcher": "", "hooks": [
{"type": "command", "command": "notify-send 'Claude Code' 'Task completed'"},
{"type": "command", "command": "my-own-hook"}
]}]
}
}
EOF
check "old hooks are found" old_claude_notifications
check "claude_notifications swaps them" claude_notifications
check_not "they're gone" old_claude_notifications
check_eq "Stop runs claude-notify" "$CLAUDE_NOTIFY 'Task completed'" \
"$(jq -r '.hooks.Stop[0].hooks[0].command' "$CLAUDE_SETTINGS")"
check_eq "your own hook stays" my-own-hook "$(jq -r '.hooks.Stop[0].hooks[1].command' "$CLAUDE_SETTINGS")"
check_eq "and your other settings" opus "$(jq -r .model "$CLAUDE_SETTINGS")"
cp "$CLAUDE_SETTINGS" "$HOME/before.json"
claude_notifications > /dev/null
check "running it again changes nothing" cmp -s "$CLAUDE_SETTINGS" "$HOME/before.json"
rm -rf "$PROC" "$sent" "$bin/notify-send" "$HOME/before.json" "$HOME/.claude"
}