-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcapture-hook.sh
More file actions
executable file
·31 lines (25 loc) · 993 Bytes
/
capture-hook.sh
File metadata and controls
executable file
·31 lines (25 loc) · 993 Bytes
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
#!/bin/bash
# Capture hook for debugging hook calls
# This script captures the JSON input from hooks and logs it
# Create logs directory if it doesn't exist
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_DIR="${SCRIPT_DIR}/hook-logs"
mkdir -p "$LOG_DIR"
# Generate timestamp-based log file
TIMESTAMP=$(date +"%Y%m%d_%H%M%S_%N")
LOG_FILE="${LOG_DIR}/hook-${TIMESTAMP}.json"
# Read JSON from stdin and save it
INPUT=$(cat)
echo "$INPUT" > "$LOG_FILE"
# Print the log file location to stderr (won't interfere with JSON output)
echo "Hook data captured to: $LOG_FILE" >&2
# Extract hook_event_name from input
HOOK_EVENT=$(echo "$INPUT" | grep -o '"hook_event_name":"[^"]*"' | cut -d'"' -f4)
# Output appropriate response based on hook event
if [ "$HOOK_EVENT" = "SessionEnd" ]; then
# SessionEnd hooks don't use hookSpecificOutput, just exit successfully
exit 0
else
echo '{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow"}}'
exit 0
fi