Terminal scrollback buffer not cleared on /clear, causing chat history to reappear on window resize
Description:
When using /clear command in Claude Code within terminal multiplexers (dtach, tmux, screen), the chat history appears to be cleared initially, but old conversations reappear when the terminal window is resized. This causes accumulated chat content and scroll jumping issues.
Steps to Reproduce:
- Connect to remote server via SSH
- Start Claude Code in a terminal multiplexer:
```bash
# With dtach:
dtach -A /tmp/claude-session -r winch claude
# OR with tmux:
tmux new -s claude
claude
# OR with screen:
screen -S claude
claude
```
- Have a conversation with Claude (multiple messages)
- Execute
/clearcommand in Claude Code - Observe: chat appears cleared, only 1 message visible
- Resize the terminal window (make it larger/smaller)
- Observe: old chat history reappears in the visible area
Expected Behavior:
After /clear command, the chat should remain cleared even when terminal window is resized. The terminal scrollback buffer should be completely cleared.
Actual Behavior:
/clearclears the internal chat state but doesn't clear the terminal scrollback buffer- On window resize (SIGWINCH), Claude Code redraws the UI and old content from terminal buffer becomes visible again
- With repeated
/clearoperations, content accumulates causing: - Scroll jumping
- Performance degradation
- UI rendering issues
Environment:
- Claude Code version: 2.0.36
- OS: Linux 6.8.0-85-generic
- Connection: SSH
- Terminal multiplexers tested: dtach, tmux, screen (issue occurs with all)
- Platform: linux
Reproducibility:
- ✅ Occurs with dtach
- ✅ Occurs with tmux
- ✅ Occurs with screen
- ✅ Occurs over SSH connection
- ❓ Unknown if occurs without multiplexer/SSH (likely terminal emulator dependent)
Possible Root Cause:
The /clear command likely:
- Clears internal conversation state
- Redraws the UI
- But doesn't emit proper terminal escape sequences to clear scrollback buffer (\
\033[3J\)
On resize, the terminal multiplexer and/or SSH session causes terminal state restoration, making old content reappear. The combination of:
- Alternate screen buffer handling
- Terminal multiplexer session persistence
- SIGWINCH signal handling
creates conditions where old buffer content becomes visible again.
Suggested Fix:
When /clear is executed, Claude Code should emit:
\\\\
\033[3J\033[H\033[2J
\\
- \
\033[3J\- Clear scrollback buffer - \
\033[H\- Move cursor to home - \
\033[2J\- Clear entire screen
Additionally, consider:
- Proper alternate screen buffer reset
- Clearing internal render cache on
/clear - Testing with common multiplexers (tmux, screen, dtach)
Workaround:
Currently users need to:
- Exit and restart multiplexer session instead of using
/clear - Manually clear terminal before reconnecting to session
This issue has 8 comments on GitHub. Read the full discussion on GitHub ↗