Skip to content

fix: clear terminal scrollback when switching between sessions#43

Draft
omrisavra wants to merge 1 commit into
Frayo44:mainfrom
omrisavra:fix/clear-scrollback-on-session-switch
Draft

fix: clear terminal scrollback when switching between sessions#43
omrisavra wants to merge 1 commit into
Frayo44:mainfrom
omrisavra:fix/clear-scrollback-on-session-switch

Conversation

@omrisavra
Copy link
Copy Markdown

@omrisavra omrisavra commented Mar 26, 2026

Summary

  • Fixes previous session content appearing when scrolling up after switching sessions
  • Adds \x1b[3J (clear scrollback buffer) alongside existing \x1b[2J (clear visible screen) in all screen transition points
  • Adds refresh-client after switch-client for clean redraws on Ctrl+]/Ctrl+\

Root cause

When attaching/detaching tmux sessions, the code only cleared the visible screen (\x1b[2J) but not the terminal's scrollback buffer. This meant the terminal emulator's scrollback retained output from the previous session since it was never cleared.

The fix adds \x1b[3J which is the standard ANSI escape sequence for clearing the terminal scrollback buffer. Supported by iTerm2, Terminal.app, and all modern terminal emulators.

For in-tmux session switching (Ctrl+]/Ctrl+), refresh-client forces tmux to fully redraw after switching.

Changes

  • src/core/tmux.ts\x1b[3J in attachSessionSync() and attachWithPty() cleanup
  • src/core/ssh.ts\x1b[3J in attach() and attachSync()
  • src/core/updater.ts\x1b[3J in performUpdateSync()
  • src/core/tmux.confrefresh-client after switch-client

Test plan

  • Attach to session A, do some work, press Ctrl+Q to detach
  • Attach to session B, scroll up — should NOT see session A content
  • While attached, press Ctrl+] to switch sessions — screen should render cleanly
  • Scroll up after switching — should only see current session content

Previously, only the visible screen was cleared (\x1b[2J) when
attaching/detaching tmux sessions. This left previous session content
in the terminal's scrollback buffer, visible when scrolling up.

Added \x1b[3J (clear scrollback) alongside \x1b[2J in all screen
transition points: attachSessionSync, attachWithPty, SSH attach, and
updater. Also added refresh-client after switch-client in tmux.conf
to force clean redraws when switching sessions via Ctrl+]/Ctrl+\.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@omrisavra omrisavra force-pushed the fix/clear-scrollback-on-session-switch branch 3 times, most recently from fd30a17 to 37e19a5 Compare March 29, 2026 10:29
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.

2 participants