Add to Claude Code
177 addsInstall this Claude Code hook.
Name: Notify on Long Run
Save to: ~/.claude/hooks/notify-on-long-run.sh
Make executable: yes
---
#!/usr/bin/env bash
# Hook type: Stop / PostToolUse
# Trigger: Bash tool calls that complete after a long duration
#
# Place this in your hooks config:
# hooks:
# PostToolUse:
# - matcher: "Bash"
# hooks:
# - type: command
# command: /path/to/notify-on-long-run.sh
set -euo pipefail
# Read JSON from stdin
INPUT=$(cat)
TOOL=$(echo "$INPUT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_name',''))" 2>/dev/null || true)
if [ "$TOOL" != "Bash" ]; then
exit 0
fi
DURATION=$(echo "$INPUT" | python3 -c "
import sys, json
d = json.load(sys.stdin)
print(d.get('duration_ms', 0))
" 2>/dev/null || echo "0")
THRESHOLD=30000 # 30 seconds in ms
if [ "$DURATION" -lt "$THRESHOLD" ]; then
exit 0
fi
CMD=$(echo "$INPUT" | python3 -c "
import sys, json
d = json.load(sys.stdin)
cmd = d.get('tool_input', {}).get('command', 'unknown command')
print(cmd[:80])
" 2>/dev/null || echo "command")
SECONDS_TAKEN=$(( DURATION / 1000 ))
MESSAGE="Finished in ${SECONDS_TAKEN}s: $CMD"
# macOS
if command -v osascript &>/dev/null; then
osascript -e "display notification \"$MESSAGE\" with title \"Claude Code\""
# Linux (notify-send)
elif command -v notify-send &>/dev/null; then
notify-send "Claude Code" "$MESSAGE"
fi
Paste into Claude Code to add this hook. Review the source first.
This is a shell script. Review the source before running: view raw.
How to add
Full guide →Click Add, then paste into Claude Code. Claude will configure the hook in your settings.
Target: .claude/settings.json → hooks