-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
48 lines (41 loc) · 1.38 KB
/
install.sh
File metadata and controls
48 lines (41 loc) · 1.38 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
#!/usr/bin/env bash
# install.sh — Register agent-timeout.sh as a Claude Code SessionStart hook
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
HOOK_SCRIPT="$SCRIPT_DIR/agent-timeout.sh"
SETTINGS_DIR="$HOME/.claude"
SETTINGS_FILE="$SETTINGS_DIR/settings.json"
if ! command -v jq &>/dev/null; then
echo "Error: jq is required. Install with: brew install jq (macOS) or apt install jq (Linux)" >&2
exit 1
fi
chmod +x "$HOOK_SCRIPT"
mkdir -p "$SETTINGS_DIR"
if [[ ! -f "$SETTINGS_FILE" ]]; then
echo '{}' > "$SETTINGS_FILE"
fi
# Bail out if hook is already present
if jq -e '.hooks.SessionStart[]? | .hooks[]? | select(.command | contains("agent-timeout"))' \
"$SETTINGS_FILE" >/dev/null 2>&1; then
echo "agent-timeout hook is already installed."
exit 0
fi
# Append the SessionStart hook entry
jq --arg cmd "bash $HOOK_SCRIPT" '
.hooks //= {} |
.hooks.SessionStart //= [] |
.hooks.SessionStart += [{
"matcher": "",
"hooks": [{
"type": "command",
"command": $cmd
}]
}]
' "$SETTINGS_FILE" > "${SETTINGS_FILE}.tmp" && mv "${SETTINGS_FILE}.tmp" "$SETTINGS_FILE"
echo "Installed agent-timeout hook into $SETTINGS_FILE"
echo ""
echo "Defaults:"
echo " AGENT_TIMEOUT=300 (seconds before SIGTERM)"
echo " POLL_INTERVAL=10 (seconds between checks)"
echo ""
echo "Override by exporting these variables in your shell profile."