Skip to content

Commit 0f8c63e

Browse files
authored
fix(stop-hook): fire at most once per session via session_id sentinel (#93)
Implements Option B from #91 — creates a tmpfile keyed to session_id on first trigger so subsequent Stop events in the same session are no-ops. Avoids the repeated nudge loop when cumulative transcript counts stay above the threshold after a capture has already been requested. Closes #91
1 parent 240d6e7 commit 0f8c63e

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

.claude/hooks/wiki-stop-capture.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ print('1' if d.get('stop_hook_active') else '0')
2323
" 2>/dev/null || echo "0")
2424
[[ "$IS_HOOK_TURN" == "1" ]] && exit 0
2525

26+
# Fire at most once per session — sentinel file keyed to session_id prevents
27+
# repeated nudges after the threshold is crossed on the first turn.
28+
SESSION_ID=$(printf '%s' "$INPUT" | python3 -c "
29+
import json, sys; print(json.load(sys.stdin).get('session_id', ''))" 2>/dev/null || echo "")
30+
SENTINEL=""
31+
if [[ -n "$SESSION_ID" ]]; then
32+
SENTINEL="${TMPDIR:-/tmp}/wiki-stop-capture-${SESSION_ID}.done"
33+
[[ -f "$SENTINEL" ]] && exit 0
34+
fi
35+
2636
TRANSCRIPT_PATH=$(printf '%s' "$INPUT" | python3 -c "
2737
import json, sys
2838
d = json.load(sys.stdin)
@@ -70,6 +80,7 @@ BASH_COUNT=$(echo "$COUNTS" | awk '{print $2}')
7080
# Trigger if any file was written/edited, or if there were ≥ 4 shell calls
7181
# (suggesting investigation/debugging worth preserving).
7282
if [[ "${WRITE_EDIT:-0}" -ge 1 ]] || [[ "${BASH_COUNT:-0}" -ge 4 ]]; then
83+
[[ -n "$SENTINEL" ]] && : > "$SENTINEL" 2>/dev/null || true
7384
echo "Session ended with ${WRITE_EDIT} file edit(s) and ${BASH_COUNT} shell call(s). Please run /wiki-capture --quick now to preserve any reusable findings before this context closes." >&2
7485
exit 2
7586
fi

0 commit comments

Comments
 (0)