fix: prevent Stop hook from killing sessions outside tmux

tmux display-message succeeds even outside tmux by falling back to the
most recently created session (agent-loop). This caused the hook to
match and kill interactive CC sessions.

Fix: check $TMUX env var first — only set when actually inside tmux.
This commit is contained in:
2026-04-02 09:14:43 -04:00
parent 71b00cf11f
commit bab002b927

View File

@@ -16,7 +16,9 @@ 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.
HOOK_COMMAND='tmux display-message -p "#{session_name}" 2>/dev/null | grep -q "^agent-loop$" && kill -INT $PPID || true'
# 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'
install_hooks() {
if [ ! -f "$SETTINGS_FILE" ]; then