fix: use env var instead of tmux check for Stop hook scoping

The tmux display-message approach had edge cases: it could succeed outside
tmux, fail on first iteration, or behave differently depending on tmux
socket state.

Replace with AGENT_LOOP_ACTIVE env var exported by loop.sh. CC sessions
spawned by the loop inherit it; interactive CC sessions don't. Simple,
no external dependencies, no race conditions.
This commit is contained in:
2026-04-02 10:42:46 -04:00
parent bab002b927
commit a1a3dfbd63
4 changed files with 7 additions and 7 deletions

View File

@@ -14,11 +14,10 @@
SETTINGS_FILE="${PROJECT_ROOT}/.claude/settings.local.json"
# The hook command checks we're inside the agent-loop tmux session before killing.
# This prevents the hook from affecting other CC sessions open in the same project.
# IMPORTANT: Must check $TMUX first — tmux display-message can succeed even outside
# tmux by falling back to the most recently created session, which would be agent-loop.
HOOK_COMMAND='[ -n "$TMUX" ] && tmux display-message -p "#{session_name}" 2>/dev/null | grep -q "^agent-loop$" && kill -INT $PPID || true'
# The hook checks AGENT_LOOP_ACTIVE before killing. This env var is exported by
# loop.sh and inherited by CC sessions it spawns. Interactive CC sessions in the
# same project won't have it set, so the hook is a no-op for them.
HOOK_COMMAND='[ "${AGENT_LOOP_ACTIVE:-}" = "1" ] && kill -INT $PPID || true'
install_hooks() {
if [ ! -f "$SETTINGS_FILE" ]; then