# 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" }