diff --git a/lib/hooks.sh b/lib/hooks.sh index a39f637..84a6f60 100644 --- a/lib/hooks.sh +++ b/lib/hooks.sh @@ -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