Skip to content

Commit 67e1e6f

Browse files
authored
Make plugin work for legacy users as it did before (#6)
If we want to release this plugin to the same plugin repo that the old repo was in, we should make sure users who upgrade the plugin but don't update warp don't just loose the functionality. To support this, this PR adds back the legacy plugin's hooks, and we use those hooks when we can see that the user is in warp but their warp version has not declared a version of notifications that it supports (i.e. they haven't updated). This ensures complete backwards compatibility. demo: https://www.loom.com/share/a2f0dd9f94aa4b85881215444a6106d2
1 parent bc80ff4 commit 67e1e6f

11 files changed

Lines changed: 165 additions & 11 deletions
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# Hook script for Claude Code Notification event
3+
# Sends a Warp notification when Claude needs user input
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Read hook input from stdin
8+
INPUT=$(cat)
9+
10+
# Extract the notification message
11+
MSG=$(echo "$INPUT" | jq -r '.message // "Input needed"' 2>/dev/null)
12+
[ -z "$MSG" ] && MSG="Input needed"
13+
14+
"$SCRIPT_DIR/warp-notify.sh" "Claude Code" "$MSG"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
# Hook script for Claude Code SessionStart event
3+
# Shows welcome message and Warp detection status
4+
5+
# Check if running in Warp terminal
6+
if [ "$TERM_PROGRAM" = "WarpTerminal" ]; then
7+
# Running in Warp - notifications will work
8+
cat << 'EOF'
9+
{
10+
"systemMessage": "🔔 Warp plugin active. You'll receive native Warp notifications when tasks complete or input is needed."
11+
}
12+
EOF
13+
else
14+
# Not running in Warp - suggest installing
15+
cat << 'EOF'
16+
{
17+
"systemMessage": "ℹ️ Warp plugin installed but you're not running in Warp terminal. Install Warp (https://warp.dev) to get native notifications when Claude completes tasks or needs input."
18+
}
19+
EOF
20+
fi
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
# Hook script for Claude Code Stop event
3+
# Sends a Warp notification when Claude completes a task
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Read hook input from stdin
8+
INPUT=$(cat)
9+
10+
# Extract transcript path from the hook input
11+
TRANSCRIPT_PATH=$(echo "$INPUT" | jq -r '.transcript_path // empty' 2>/dev/null)
12+
13+
# Default message
14+
MSG="Task completed"
15+
16+
# Try to extract prompt and response from the transcript (JSONL format)
17+
if [ -n "$TRANSCRIPT_PATH" ] && [ -f "$TRANSCRIPT_PATH" ]; then
18+
# Get the first user prompt
19+
PROMPT=$(jq -rs '
20+
[.[] | select(.type == "user")] | first | .message.content // empty
21+
' "$TRANSCRIPT_PATH" 2>/dev/null)
22+
23+
# Get the last assistant response
24+
RESPONSE=$(jq -rs '
25+
[.[] | select(.type == "assistant" and .message.content)] | last |
26+
[.message.content[] | select(.type == "text") | .text] | join(" ")
27+
' "$TRANSCRIPT_PATH" 2>/dev/null)
28+
29+
if [ -n "$PROMPT" ] && [ -n "$RESPONSE" ]; then
30+
# Truncate prompt to 50 chars
31+
if [ ${#PROMPT} -gt 50 ]; then
32+
PROMPT="${PROMPT:0:47}..."
33+
fi
34+
# Truncate response to 120 chars
35+
if [ ${#RESPONSE} -gt 120 ]; then
36+
RESPONSE="${RESPONSE:0:117}..."
37+
fi
38+
MSG="\"${PROMPT}\"${RESPONSE}"
39+
elif [ -n "$RESPONSE" ]; then
40+
# Fallback to just response if no prompt found
41+
if [ ${#RESPONSE} -gt 175 ]; then
42+
RESPONSE="${RESPONSE:0:172}..."
43+
fi
44+
MSG="$RESPONSE"
45+
fi
46+
fi
47+
48+
"$SCRIPT_DIR/warp-notify.sh" "Claude Code" "$MSG"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Warp notification utility using OSC escape sequences
3+
# Usage: warp-notify.sh <title> <body>
4+
5+
TITLE="${1:-Notification}"
6+
BODY="${2:-}"
7+
8+
# OSC 777 format: \033]777;notify;<title>;<body>\007
9+
# Write directly to /dev/tty to ensure it reaches the terminal
10+
printf '\033]777;notify;%s;%s\007' "$TITLE" "$BODY" > /dev/tty 2>/dev/null || true

plugins/warp/scripts/on-notification.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# Sends a structured Warp notification when Claude has been idle
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Legacy fallback for old Warp versions
8+
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
[ "$TERM_PROGRAM" = "WarpTerminal" ] && exec "$SCRIPT_DIR/legacy/on-notification.sh"
10+
exit 0
11+
fi
12+
613
source "$SCRIPT_DIR/build-payload.sh"
714

815
# Read hook input from stdin

plugins/warp/scripts/on-permission-request.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
# Sends a structured Warp notification when Claude needs permission to run a tool
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# No legacy equivalent for this hook
8+
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
exit 0
10+
fi
11+
612
source "$SCRIPT_DIR/build-payload.sh"
713

814
# Read hook input from stdin

plugins/warp/scripts/on-post-tool-use.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# transitioning the session status from Blocked back to Running.
55

66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
8+
# No legacy equivalent for this hook
9+
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
10+
exit 0
11+
fi
12+
713
source "$SCRIPT_DIR/build-payload.sh"
814

915
# Read hook input from stdin

plugins/warp/scripts/on-prompt-submit.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
# transitioning the session status from idle/blocked back to running.
55

66
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7+
8+
# No legacy equivalent for this hook
9+
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
10+
exit 0
11+
fi
12+
713
source "$SCRIPT_DIR/build-payload.sh"
814

915
# Read hook input from stdin

plugins/warp/scripts/on-session-start.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,21 @@
22
# Hook script for Claude Code SessionStart event
33
# Shows welcome message, Warp detection status, and emits plugin version
44

5-
if ! command -v jq &>/dev/null; then
6-
cat << 'EOF'
7-
{
8-
"systemMessage": "⚠️ Warp notifications require jq — install it with your system package manager (e.g. brew install jq, apt install jq)"
9-
}
10-
EOF
11-
exit 0
12-
fi
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
136

7+
# Legacy fallback for old Warp versions
148
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
exec "$SCRIPT_DIR/legacy/on-session-start.sh"
10+
fi
11+
12+
if ! command -v jq &>/dev/null; then
1513
cat << 'EOF'
1614
{
17-
"systemMessage": "⚠️ Please update Warp to get agent notifications — your terminal does not declare cli-agent protocol support"
15+
"systemMessage": "⚠️ Warp notifications require jq — install it with your system package manager (e.g. brew install jq, apt install jq)"
1816
}
1917
EOF
2018
exit 0
2119
fi
22-
23-
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2420
source "$SCRIPT_DIR/build-payload.sh"
2521

2622
# Read hook input from stdin

plugins/warp/scripts/on-stop.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
# Sends a structured Warp notification when Claude completes a task
44

55
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
# Legacy fallback for old Warp versions
8+
if [ -z "$WARP_CLI_AGENT_PROTOCOL_VERSION" ]; then
9+
[ "$TERM_PROGRAM" = "WarpTerminal" ] && exec "$SCRIPT_DIR/legacy/on-stop.sh"
10+
exit 0
11+
fi
12+
613
source "$SCRIPT_DIR/build-payload.sh"
714

815
# Read hook input from stdin

0 commit comments

Comments
 (0)