Skip to content

Commit cd3cc54

Browse files
committed
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.
1 parent b8ad3cc commit cd3cc54

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

plugins/warp/hooks/hooks.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@
6262
}
6363
]
6464
}
65+
],
66+
"PreToolUse": [
67+
{
68+
"matcher": "AskUserQuestion",
69+
"hooks": [
70+
{
71+
"type": "command",
72+
"command": "${CLAUDE_PLUGIN_ROOT}/scripts/on-ask-user-question.sh"
73+
}
74+
]
75+
}
6576
]
6677
}
6778
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# Hook script for Claude Code PreToolUse event on AskUserQuestion
3+
# Sends a structured Warp notification when Claude asks the user a question,
4+
# transitioning the session status to Blocked until the user answers.
5+
6+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
source "$SCRIPT_DIR/should-use-structured.sh"
8+
9+
# No legacy equivalent for this hook
10+
if ! should_use_structured; then
11+
exit 0
12+
fi
13+
14+
source "$SCRIPT_DIR/build-payload.sh"
15+
16+
# Read hook input from stdin
17+
INPUT=$(cat)
18+
19+
# AskUserQuestion supports 1-4 questions. Surface the first question's text as
20+
# the notification summary; if Claude asks more than one in the same call,
21+
# answering any of them unblocks the session.
22+
SUMMARY=$(echo "$INPUT" | jq -r '.tool_input.questions[0].question // "Claude is asking a question"' 2>/dev/null)
23+
24+
# Truncate for notification display
25+
if [ -n "$SUMMARY" ] && [ ${#SUMMARY} -gt 200 ]; then
26+
SUMMARY="${SUMMARY:0:197}..."
27+
fi
28+
29+
BODY=$(build_payload "$INPUT" "question_asked" \
30+
--arg summary "$SUMMARY")
31+
32+
"$SCRIPT_DIR/warp-notify.sh" "warp://cli-agent" "$BODY"

plugins/warp/tests/test-hooks.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ assert_eq "legacy Warp shows active message" \
218218
echo ""
219219
echo "--- Modern-only hooks exit silently without protocol version ---"
220220

221-
for HOOK in on-permission-request.sh on-prompt-submit.sh on-post-tool-use.sh; do
221+
for HOOK in on-permission-request.sh on-prompt-submit.sh on-post-tool-use.sh on-ask-user-question.sh; do
222222
echo '{}' | bash "$HOOK_DIR/$HOOK" 2>/dev/null
223223
assert_eq "$HOOK exits 0 without protocol version" "0" "$?"
224224
done

0 commit comments

Comments
 (0)