Terminal scrollback wiped during session (alternate screen buffer cleared on redraw)
Description
Terminal scrollback gets completely wiped mid-session, losing all previous output. The screen clears and only shows the Claude Code banner + greeting as if the session just started. This happens multiple times within a single session, sometimes close together.
Environment
- Claude Code version: v2.1.90
- Model: Opus 4.6 (1M context) with Claude Max
- Terminal: macOS Terminal.app, 130x37+
- OS: macOS 26.x (Darwin 25.4.0)
- Shell: zsh
Reproduction
- Start a Claude Code session
- Run several tool-heavy operations (SSH commands, parallel Agent calls, long markdown table output)
- After some time (varies — sometimes 10-12 minutes), the entire terminal output is cleared
- Only the Claude Code banner, the greeting line, and the latest prompt remain visible
- All previous output (tool results, tables, analysis) is gone from scrollback
Observed behavior
- Screen wipes happen at unpredictable intervals, sometimes twice in quick succession
- Context usage at time of wipe is low (~12% of usable context, ~20K tokens) — not near autocompact threshold
- The session continues working normally after the wipe — only the terminal display is affected
- The conversation context is preserved (Claude remembers prior exchanges), but the user can't scroll back to see previous output
Expected behavior
Terminal scrollback should be preserved throughout the session. If Claude Code needs to redraw its UI (autocompact, context management), it should not clear the alternate screen buffer's scrollback.
Investigation done
Checked all custom hooks — none write terminal-clearing escape sequences:
set-terminal-title.sh(SessionStart) — writes OSC title sequence to TTY, no screen cleargsd-context-monitor.js(PostToolUse) — JSON stdout onlygsd-statusline.js— JSON stdout onlyformat-on-edit.sh(PostToolUse) — runs formatters silently- Custom
statusline.sh— ANSI color codes via stdout only
The issue appears to be Claude Code's internal rendering/redraw logic clearing the alternate screen buffer.
Screenshots
Two consecutive screen wipes during a single session — first showing 8K tokens consumed, second showing 20.2K tokens. Both times the screen was wiped clean to just the banner + greeting.
Workaround
Running inside tmux preserves scrollback independent of Claude Code's buffer management.
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗