-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop-failure.sh
More file actions
executable file
·31 lines (27 loc) · 1.14 KB
/
Copy pathstop-failure.sh
File metadata and controls
executable file
·31 lines (27 loc) · 1.14 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
#!/usr/bin/env bash
# StopFailure hook handler: logs API failures and notifies user for critical ones.
# Invoked with a single argument: the severity class (critical|rate_limit|high).
set -euo pipefail
severity="${1:-high}"
input_json="$(cat)"
error="$(printf '%s' "$input_json" | jq -r '.error // "unknown"')"
timestamp="$(date +'%Y-%m-%d %H:%M:%S')"
cwd="$(pwd)"
branch="$(git branch --show-current 2>/dev/null || echo unknown)"
basename_cwd="$(basename "$cwd")"
mkdir -p ~/.claude/logs
case "$severity" in
rate_limit)
echo "[$timestamp] RATE_LIMIT in $cwd branch=$branch" >> ~/.claude/logs/failures.log
;;
critical)
echo "[$timestamp] STOP_FAILURE($error) in $cwd branch=$branch" >> ~/.claude/logs/failures.log
~/.claude/scripts/notify.sh "$error in $basename_cwd — action required" \
-t "Claude Code" -p critical --tags rotating_light 2>/dev/null || true
;;
high)
echo "[$timestamp] STOP_FAILURE($error) in $cwd branch=$branch" >> ~/.claude/logs/failures.log
~/.claude/scripts/notify.sh "API failure ($error) in $basename_cwd" \
-t "Claude Code" -p high --tags rotating_light 2>/dev/null || true
;;
esac