From c6b99a74d842b8f512beb11b95f1860c7988eb22 Mon Sep 17 00:00:00 2001 From: 21st Dev Date: Thu, 29 Jan 2026 08:39:35 +0000 Subject: [PATCH] feat: add desktop notification when agent prompts with multichoice question Shows a native OS notification when the Claude agent uses the AskUserQuestion tool to prompt the user with a multichoice question. The notification only appears when the app window is not focused, helping users know when the agent needs their input even if they've switched to another application. Uses the existing notifyAgentNeedsInput() function which respects the user's notification settings and includes priority-based throttling to prevent spam. Fixes: ENG-586 Co-Authored-By: Claude Opus 4.5 --- .../features/agents/main/active-chat.tsx | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/renderer/features/agents/main/active-chat.tsx b/src/renderer/features/agents/main/active-chat.tsx index 5bc5bf06..09011e3f 100644 --- a/src/renderer/features/agents/main/active-chat.tsx +++ b/src/renderer/features/agents/main/active-chat.tsx @@ -2024,6 +2024,9 @@ const ChatViewInner = memo(function ChatViewInner({ (state) => state.allSubChats.find((sc) => sc.id === subChatId)?.name || "", ) + // Desktop notifications for agent events + const { notifyAgentNeedsInput } = useDesktopNotifications() + // Mutation for renaming sub-chat const renameSubChatMutation = api.agents.renameSubChat.useMutation({ onError: (error) => { @@ -2628,6 +2631,24 @@ const ChatViewInner = memo(function ChatViewInner({ } }, [subChatId, lastAssistantMessage, isStreaming, pendingQuestions, setPendingQuestionsMap]) + // Track previous pending question toolUseId to detect new questions + const prevPendingQuestionToolUseIdRef = useRef(null) + + // Notify user when a new AskUserQuestion arrives (when window is not focused) + useEffect(() => { + if (pendingQuestions) { + // Only notify if this is a NEW question (different toolUseId) + if (prevPendingQuestionToolUseIdRef.current !== pendingQuestions.toolUseId) { + prevPendingQuestionToolUseIdRef.current = pendingQuestions.toolUseId + // notifyAgentNeedsInput already checks document.hasFocus() internally + notifyAgentNeedsInput(subChatName || "Agent") + } + } else { + // Clear the ref when there's no pending question + prevPendingQuestionToolUseIdRef.current = null + } + }, [pendingQuestions, subChatName, notifyAgentNeedsInput]) + // Helper to clear pending and expired questions for this subChat (used in callbacks) const clearPendingQuestionCallback = useCallback(() => { setPendingQuestionsMap((current) => {