forked from Parli/node-simple-server-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclaude-notify
More file actions
75 lines (61 loc) · 1.96 KB
/
claude-notify
File metadata and controls
75 lines (61 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Claude Code notification wrapper
# Usage: claude-notify <claude-code-command>
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
NOTIFY_SCRIPT="$SCRIPT_DIR/notify.sh"
# Create a temporary file to track the last activity
ACTIVITY_FILE="/tmp/claude_activity_$$"
echo "$(date +%s)" > "$ACTIVITY_FILE"
# Function to send notification
send_notification() {
if [[ -x "$NOTIFY_SCRIPT" ]]; then
bash "$NOTIFY_SCRIPT" "Claude Code is ready for your input!"
fi
}
# Background process to monitor for idle state
monitor_idle() {
local last_activity=$(cat "$ACTIVITY_FILE" 2>/dev/null || echo "0")
local idle_threshold=3 # seconds of inactivity before notification
while [[ -f "$ACTIVITY_FILE" ]]; do
sleep 1
local current_time=$(date +%s)
local file_time=$(cat "$ACTIVITY_FILE" 2>/dev/null || echo "$current_time")
if (( current_time - file_time >= idle_threshold )); then
# Check if we're at a prompt (no recent output)
send_notification
# Update activity to prevent spam notifications
echo "$current_time" > "$ACTIVITY_FILE"
sleep 10 # Wait 10 seconds before next possible notification
fi
done
}
# Start the idle monitor in background
monitor_idle &
MONITOR_PID=$!
# Function to update activity timestamp
update_activity() {
echo "$(date +%s)" > "$ACTIVITY_FILE"
}
# Cleanup function
cleanup() {
kill $MONITOR_PID 2>/dev/null
rm -f "$ACTIVITY_FILE"
}
# Set up cleanup on exit
trap cleanup EXIT INT TERM
# Run the actual command while monitoring its output
if [[ $# -gt 0 ]]; then
# Monitor stdout and stderr for activity
"$@" 2>&1 | while IFS= read -r line; do
echo "$line"
update_activity
done
# Command finished, send final notification
sleep 1
send_notification
else
echo "Usage: $0 <command>"
echo "Example: $0 claude"
echo " $0 npm run dev"
fi
cleanup