From 29520346542c35230bf082f91b52724d9749995e Mon Sep 17 00:00:00 2001 From: David Young Date: Sat, 28 Nov 2026 19:00:43 -0700 Subject: [PATCH] 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 --- PLAN.md | 1 - README.md | 2 +- TEST.md | 2 + configure.d/30-agents.sh | 51 +++++++++++---- smoketest/README.md | 1 + smoketest/scenarios/35-claude-notify.sh | 76 ++++++++++++++++++++++ system/claude-notify | 84 +++++++++++++++++++++++++ 7 files changed, 203 insertions(+), 14 deletions(-) create mode 100644 smoketest/scenarios/35-claude-notify.sh create mode 100755 system/claude-notify diff --git a/PLAN.md b/PLAN.md index 4583256..bc17790 100644 --- a/PLAN.md +++ b/PLAN.md @@ -53,7 +53,6 @@ Since `4a4a3bd`, to look at: and its later checks from `d5925fa` (what root runs is root's alone) and `53c6c8b` (the install path). Hiding the connector's settings from agents is done. -- [ ] `4fb3539` Claude notifications: clicking one brings back the app Claude runs in - [ ] `9dc5eb1` Upgrade safeguards, hardware setup, sign-in options and Taildrop. To port: `configure security-key` and `configure fingerprint` (through `pam-auth-update` and fprintd on Pop!_OS, not by editing PAM files), diff --git a/README.md b/README.md index 2a84d95..eceee70 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ opencode, Hermes and Cline Desktop run in Anthropic's sandbox runtime (srt), whi - can't read your SSH keys, keyrings, password managers, browser profiles, Evolution's mail, calendars and contacts, Thunderbird, Element, cloud and Git credentials, the other agents' logins, or Federated Connector's settings (your Core's domain and user name, and what the sandbox allows) - can reach only AI providers and common developer sites: GitHub, Gitea, npm, PyPI, crates.io, RubyGems, the Go module proxy, and Ubuntu's and Pop!_OS' sites -Typing `opencode`, `hermes` or `hermes-agent` runs it in the sandbox: `configure agents` adds a block at the end of ~/.bashrc that puts `sandbox/bin` first on PATH. To run one without the sandbox, type `unsandboxed opencode`. Claude Code uses its own built-in sandbox, also on bubblewrap, for every command it runs, which `configure agents` turns on (see `/sandbox` inside Claude). If you had no Claude Code settings, it also adds notifications for when Claude needs you and when it's done. +Typing `opencode`, `hermes` or `hermes-agent` runs it in the sandbox: `configure agents` adds a block at the end of ~/.bashrc that puts `sandbox/bin` first on PATH. To run one without the sandbox, type `unsandboxed opencode`. Claude Code uses its own built-in sandbox, also on bubblewrap, for every command it runs, which `configure agents` turns on (see `/sandbox` inside Claude). If you had no Claude Code settings, it also adds notifications for when Claude needs you and when it's done. Clicking one brings back the app Claude runs in (COSMIC Terminal, VS Codium, or the terminal tmux is in); the title shows the project folder. Settings written by an earlier version, whose notifications did nothing when clicked, are changed to match the next time you run `configure agents`, and only those two hooks. If Hermes' gateway is set up as a service, `configure agents` runs it in the sandbox too. Hermes can change its own settings from inside the sandbox, so the Matrix server they name isn't trusted on its own: `configure hermes` asks whether it's your server and may be reached, and keeps your answer in `~/.config/federated-connector/sandbox/hermes.json`, which no sandbox can read or write. For other messaging services, add their domains to that file as shown below. If Cline Desktop is installed, its entry in the app library opens it in the sandbox. diff --git a/TEST.md b/TEST.md index 567b9a9..029c5bb 100644 --- a/TEST.md +++ b/TEST.md @@ -92,6 +92,8 @@ Once it's packaged for Pop!_OS (see [PLAN.md](PLAN.md)): ### AI agents and the sandbox - [ ] Each agent installs and signs in, and runs in the sandbox +- [ ] Claude Code's notification, from Claude in COSMIC Terminal, shows the + project folder, and clicking it brings COSMIC Terminal back - [ ] If Pop!_OS restricts user namespaces, the AppArmor profile for bubblewrap lets the sandbox start - [ ] An AI server on the network or tailnet is found by `configure ai-servers` diff --git a/configure.d/30-agents.sh b/configure.d/30-agents.sh index 2b5062f..beeccb8 100644 --- a/configure.d/30-agents.sh +++ b/configure.d/30-agents.sh @@ -104,18 +104,44 @@ turn_on_claude_sandbox() { echo "Claude Code runs the commands it starts in its own sandbox." } -# A desktop notification when Claude Code needs you or is done, if you have no -# settings of your own yet +# A desktop notification when Claude Code needs you or is done, through +# system/claude-notify so that clicking one brings back the app Claude runs in. +# The hook runs in a shell, which expands ~. +# shellcheck disable=SC2088 +CLAUDE_NOTIFY="~/.local/share/federated-connector/connector/system/claude-notify" +OLD_NOTIFY_INPUT="notify-send 'Claude Code' 'Needs your input'" +OLD_NOTIFY_DONE="notify-send 'Claude Code' 'Task completed'" + +# Settings written before claude-notify ran notify-send itself, so clicking +# did nothing: true while either of those two hooks is still there +old_claude_notifications() { + jq -e --arg input "$OLD_NOTIFY_INPUT" --arg done "$OLD_NOTIFY_DONE" \ + '[.hooks.Notification[]?.hooks[]?, .hooks.Stop[]?.hooks[]? | objects | .command] + | any(. == $input or . == $done)' "$CLAUDE_SETTINGS" &> /dev/null +} + +# Your own settings are left alone: the hooks are added only if you have no +# settings yet, and changed only where they're still the ones written here claude_notifications() { - [ -f "$CLAUDE_SETTINGS" ] && return 0 - edit_json "$CLAUDE_SETTINGS" '{}' \ - --arg needs "notify-send 'Claude Code' 'Needs your input'" \ - --arg finished "notify-send 'Claude Code' 'Task completed'" \ - '.hooks = { - Notification: [{matcher: "", hooks: [{type: "command", command: $needs}]}], - Stop: [{matcher: "", hooks: [{type: "command", command: $finished}]}] - }' || return 1 - echo "Claude Code shows a notification when it needs you and when it's done." + if [ ! -f "$CLAUDE_SETTINGS" ]; then + edit_json "$CLAUDE_SETTINGS" '{}' \ + --arg needs "$CLAUDE_NOTIFY 'Needs your input'" \ + --arg finished "$CLAUDE_NOTIFY 'Task completed'" \ + '.hooks = { + Notification: [{matcher: "", hooks: [{type: "command", command: $needs}]}], + Stop: [{matcher: "", hooks: [{type: "command", command: $finished}]}] + }' || return 1 + echo "Claude Code shows a notification when it needs you and when it's done." + elif old_claude_notifications; then + edit_json "$CLAUDE_SETTINGS" '{}' \ + --arg old_input "$OLD_NOTIFY_INPUT" --arg new_input "$CLAUDE_NOTIFY 'Needs your input'" \ + --arg old_done "$OLD_NOTIFY_DONE" --arg new_done "$CLAUDE_NOTIFY 'Task completed'" ' + def swap(old; new): + if type == "object" and .command == old then .command = new else . end; + (.hooks.Notification[]?.hooks[]?) |= swap($old_input; $new_input) + | (.hooks.Stop[]?.hooks[]?) |= swap($old_done; $new_done)' || return 1 + echo "Clicking Claude Code's notifications brings back the app it runs in." + fi } # --- Hermes' gateway and Cline Desktop ----------------------------------------------- @@ -189,7 +215,8 @@ sandbox_cline() { sandbox_ready() { srt_path > /dev/null && on_path && pkg_installed "${SANDBOX_PACKAGES[@]}" && bwrap_works \ - && { ! agent_installed claude || claude_sandbox_on; } && gateway_ok && cline_ok + && { ! agent_installed claude || { claude_sandbox_on && ! old_claude_notifications; }; } \ + && gateway_ok && cline_ok } is_configured() { diff --git a/smoketest/README.md b/smoketest/README.md index f655189..18a72fd 100644 --- a/smoketest/README.md +++ b/smoketest/README.md @@ -31,6 +31,7 @@ Each run writes its logs to `smoketest/results/