From cd3cc548ce77f8c9b4fd13b616b0267794ec3481 Mon Sep 17 00:00:00 2001 From: novarii <165450912+novarii@users.noreply.github.com> Date: Tue, 12 May 2026 15:18:49 -0400 Subject: [PATCH] add ask user question hook Wires up a PreToolUse hook for AskUserQuestion that emits a structured 'question_asked' event (already defined in Warp's CLI agent protocol and mapped to Blocked status). Without this, AskUserQuestion calls fire no Warp notification, so users miss prompts when not focused on Warp. --- plugins/warp/hooks/hooks.json | 11 +++++++ plugins/warp/scripts/on-ask-user-question.sh | 32 ++++++++++++++++++++ plugins/warp/tests/test-hooks.sh | 2 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 plugins/warp/scripts/on-ask-user-question.sh diff --git a/plugins/warp/hooks/hooks.json b/plugins/warp/hooks/hooks.json index b2273b4..3ef2d0a 100644 --- a/plugins/warp/hooks/hooks.json +++ b/plugins/warp/hooks/hooks.json @@ -62,6 +62,17 @@ } ] } + ], + "PreToolUse": [ + { + "matcher": "AskUserQuestion", + "hooks": [ + { + "type": "command", + "command": "${CLAUDE_PLUGIN_ROOT}/scripts/on-ask-user-question.sh" + } + ] + } ] } } diff --git a/plugins/warp/scripts/on-ask-user-question.sh b/plugins/warp/scripts/on-ask-user-question.sh new file mode 100755 index 0000000..b553459 --- /dev/null +++ b/plugins/warp/scripts/on-ask-user-question.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Hook script for Claude Code PreToolUse event on AskUserQuestion +# Sends a structured Warp notification when Claude asks the user a question, +# transitioning the session status to Blocked until the user answers. + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "$SCRIPT_DIR/should-use-structured.sh" + +# No legacy equivalent for this hook +if ! should_use_structured; then + exit 0 +fi + +source "$SCRIPT_DIR/build-payload.sh" + +# Read hook input from stdin +INPUT=$(cat) + +# AskUserQuestion supports 1-4 questions. Surface the first question's text as +# the notification summary; if Claude asks more than one in the same call, +# answering any of them unblocks the session. +SUMMARY=$(echo "$INPUT" | jq -r '.tool_input.questions[0].question // "Claude is asking a question"' 2>/dev/null) + +# Truncate for notification display +if [ -n "$SUMMARY" ] && [ ${#SUMMARY} -gt 200 ]; then + SUMMARY="${SUMMARY:0:197}..." +fi + +BODY=$(build_payload "$INPUT" "question_asked" \ + --arg summary "$SUMMARY") + +"$SCRIPT_DIR/warp-notify.sh" "warp://cli-agent" "$BODY" diff --git a/plugins/warp/tests/test-hooks.sh b/plugins/warp/tests/test-hooks.sh index c8fcbb6..54cd7a0 100755 --- a/plugins/warp/tests/test-hooks.sh +++ b/plugins/warp/tests/test-hooks.sh @@ -218,7 +218,7 @@ assert_eq "legacy Warp shows active message" \ echo "" echo "--- Modern-only hooks exit silently without protocol version ---" -for HOOK in on-permission-request.sh on-prompt-submit.sh on-post-tool-use.sh; do +for HOOK in on-permission-request.sh on-prompt-submit.sh on-post-tool-use.sh on-ask-user-question.sh; do echo '{}' | bash "$HOOK_DIR/$HOOK" 2>/dev/null assert_eq "$HOOK exits 0 without protocol version" "0" "$?" done