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
8 Comments
Same issue on windows.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
Actual. Claude Code 2.0.64. Also in native Claude Code without dtach. It seems to me that the problem is related to the long answers. It feels like when you get long answers (maybe ones that don't fit on one screen), the problem gets worse. Again, with this problem, it feels like the screen is trying to scroll from the beginning of the dialog (top) to the end (bottom), but due to interface updates (animations, answers, reflections), there is a constant redrawing and attempts to scroll from top to bottom again.
Same issue on Mac. Here is the video.
https://github.com/user-attachments/assets/15d01c29-dff5-4697-9b33-32c76bf883a9
I've reported this as a separate issue: https://github.com/anthropics/claude-code/issues/16457
I've since closed that issue as a duplicate of this issue here.
The bug doesn't apply just to terminal multiplexers - it also applies to normal terminals (e.g. Warp) on macOS.
https://github.com/user-attachments/assets/619138e7-1f2a-485d-95ab-9b9f760b990f
This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.