This repository was archived by the owner on Jun 30, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstop-gate.sh
More file actions
38 lines (32 loc) · 1.95 KB
/
Copy pathstop-gate.sh
File metadata and controls
38 lines (32 loc) · 1.95 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
#!/bin/bash
# Stop gate: prevents accidental session termination.
# Generates a nonce, asks Claude to confirm it wants to stop.
# If Claude hasn't seen the nonce, blocks and shows reminders.
NONCE_FILE="/tmp/claude-stop-nonce"
INPUT=$(cat)
# Check if Claude included the nonce in its last message
LAST_MSG=$(echo "$INPUT" | jq -r '.assistant_message // .content // .transcript // empty' 2>/dev/null)
if [ -z "$LAST_MSG" ]; then
LAST_MSG=$(echo "$INPUT")
fi
# If nonce file exists, check if Claude confirmed it
if [ -f "$NONCE_FILE" ]; then
EXPECTED=$(cat "$NONCE_FILE")
if echo "$LAST_MSG" | grep -q "STOP_CONFIRMED_$EXPECTED" 2>/dev/null; then
rm -f "$NONCE_FILE"
exit 0
fi
fi
# Generate new nonce
NONCE=$(head -c 6 /dev/urandom | xxd -p)
echo "$NONCE" > "$NONCE_FILE"
# Build reason message
REASON="STOP GATE: Before stopping, please:"
REASON="$REASON [1] Review your task list -- any incomplete tasks?"
REASON="$REASON [2] Review user messages -- did you miss anything?"
REASON="$REASON [3] If you have overnight work queued, make a tool call to ensure the loop continues."
REASON="$REASON [4] Terminate any background commands that are stuck, legacy, or unused -- clean up after yourself."
REASON="$REASON [5] Consider stretch goals: if the main work is done, try bonus improvements on an experimental branch or separate folder -- the criteria is that the main work and the homelab must not be jeopardized. If the stretch succeeds, switch back to main before signing off. If it fails, keep the artifact and explain what went wrong in your final sign-off alongside the nonce."
REASON="$REASON [6] To confirm stop, include this nonce: STOP_CONFIRMED_${NONCE}"
REASON="$REASON -- You may also send the nonce even with pending work IF a background command will complete it in bounded time. Spawn one via Bash run_in_background if you just need to wait N minutes instead of hot-grinding."
jq -n --arg reason "$REASON" '{"decision":"block","reason":$reason}'