Skip to content

feat(local-terminal): close orphaned native tab on session kill#141

Merged
Time4Mind merged 1 commit into
mainfrom
fix/close-orphan-terminal-tab
Jun 29, 2026
Merged

feat(local-terminal): close orphaned native tab on session kill#141
Time4Mind merged 1 commit into
mainfrom
fix/close-orphan-terminal-tab

Conversation

@Time4Mind

Copy link
Copy Markdown
Owner

Проблема

При включённом local_terminal каждая новая сессия открывает нативную вкладку iTerm/Terminal/эмулятора, которая запускает tmux attach …; exec ${SHELL} -l. Безусловный exec-хвост был нужен, чтобы пережить ручной detach (Ctrl-b d) без потери scrollback — но он же оставлял вкладку висеть голым логин-шеллом после kill сессии, замусоривая iTerm на каждый /kill.

Фикс

Хвостовой exec стал условным от живости per-window group-сессии:

tmux attach …; tmux has-session -t <group> && exec …
  • Ручной detach → group жив → шелл остаётся, scrollback цел (старое поведение).
  • Kill сессииkill_window сносит group (_kill_grouped_session_for_window) → has-session падает → bash -c выходит чисто → терминал закрывает осиротевшую вкладку.

Применено к обоим билдерам команд — macOS (_build_tmux_command) и Linux (_build_linux_shell_cmd).

Проверки

  • ruff check / ruff format --check — ✅
  • pyright — ✅ 0 errors
  • Новые тесты: test_exec_guarded_by_has_session, test_linux_exec_guarded_by_has_session — ✅

🤖 Generated with Claude Code

The local_terminal feature opened a native iTerm/Terminal/emulator tab
per session that ran `tmux attach …; exec ${SHELL} -l`. The unconditional
exec tail was meant to survive a manual detach (Ctrl-b d) without losing
scrollback — but it also kept the tab alive as a bare login shell after a
session kill, leaving a leftover tab on every /kill.

Guard the tail on the per-window group session still existing:
`tmux attach …; tmux has-session -t <group> && exec …`. A manual detach
leaves the group alive (shell stays, scrollback preserved); kill_window
tears the group down (see _kill_grouped_session_for_window), so has-session
fails, the bash -c wrapper exits cleanly, and the host terminal closes the
now-orphaned tab. Applied to both the macOS and Linux command builders.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Time4Mind Time4Mind merged commit 01ae972 into main Jun 29, 2026
4 checks passed
@Time4Mind Time4Mind deleted the fix/close-orphan-terminal-tab branch June 29, 2026 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant