From d24f009e7e549ee3aa1babc6805c2153c9ffea3a Mon Sep 17 00:00:00 2001 From: Kiet Ho Date: Mon, 26 Jan 2026 23:28:21 -0800 Subject: [PATCH] fix(desktop): enable notifications for permission prompts and questions Previously, notifications only worked for agent Stop events but not for "needs attention" states like permission prompts or questions. The issue was that we only configured the PermissionRequest hook (for decision control), but not the Notification hook which actually fires when Claude Code displays dialogs requiring user attention. Changes: - Add Notification hook with permission_prompt and elicitation_dialog matchers - Update notify shell script to handle Notification events and map them to PermissionRequest for desktop notification handling - Bump notify hook marker version to force script regeneration --- .../src/main/lib/agent-setup/agent-wrappers.ts | 9 +++++++++ .../src/main/lib/agent-setup/notify-hook.ts | 2 +- .../agent-setup/templates/notify-hook.template.sh | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/desktop/src/main/lib/agent-setup/agent-wrappers.ts b/apps/desktop/src/main/lib/agent-setup/agent-wrappers.ts index 345d66a4f8..69690817ad 100644 --- a/apps/desktop/src/main/lib/agent-setup/agent-wrappers.ts +++ b/apps/desktop/src/main/lib/agent-setup/agent-wrappers.ts @@ -82,6 +82,15 @@ export function getClaudeSettingsContent(notifyPath: string): string { PermissionRequest: [ { matcher: "*", hooks: [{ type: "command", command: notifyPath }] }, ], + // Notification hook fires when Claude Code needs user attention + // - permission_prompt: permission dialogs + // - elicitation_dialog: when Claude asks questions via MCP tool elicitation + Notification: [ + { + matcher: "permission_prompt|elicitation_dialog", + hooks: [{ type: "command", command: notifyPath }], + }, + ], }, }; diff --git a/apps/desktop/src/main/lib/agent-setup/notify-hook.ts b/apps/desktop/src/main/lib/agent-setup/notify-hook.ts index 5026f3a6ac..55c7053716 100644 --- a/apps/desktop/src/main/lib/agent-setup/notify-hook.ts +++ b/apps/desktop/src/main/lib/agent-setup/notify-hook.ts @@ -4,7 +4,7 @@ import { PORTS } from "shared/constants"; import { HOOKS_DIR } from "./paths"; export const NOTIFY_SCRIPT_NAME = "notify.sh"; -export const NOTIFY_SCRIPT_MARKER = "# Superset agent notification hook"; +export const NOTIFY_SCRIPT_MARKER = "# Superset agent notification hook v3"; const NOTIFY_SCRIPT_TEMPLATE_PATH = path.join( __dirname, diff --git a/apps/desktop/src/main/lib/agent-setup/templates/notify-hook.template.sh b/apps/desktop/src/main/lib/agent-setup/templates/notify-hook.template.sh index fc5dd40518..0dd8240544 100644 --- a/apps/desktop/src/main/lib/agent-setup/templates/notify-hook.template.sh +++ b/apps/desktop/src/main/lib/agent-setup/templates/notify-hook.template.sh @@ -30,6 +30,21 @@ fi # Map UserPromptSubmit to Start for simpler handling [ "$EVENT_TYPE" = "UserPromptSubmit" ] && EVENT_TYPE="Start" +# Handle Notification hook - check notification_type for user attention events +if [ "$EVENT_TYPE" = "Notification" ]; then + NOTIFICATION_TYPE=$(echo "$INPUT" | grep -oE '"notification_type"[[:space:]]*:[[:space:]]*"[^"]*"' | grep -oE '"[^"]*"$' | tr -d '"') + case "$NOTIFICATION_TYPE" in + permission_prompt|elicitation_dialog) + # Both permission prompts and question dialogs need user attention + EVENT_TYPE="PermissionRequest" + ;; + *) + # Ignore other notification types + exit 0 + ;; + esac +fi + # If no event type was found, skip the notification # This prevents parse failures from causing false completion notifications [ -z "$EVENT_TYPE" ] && exit 0