[BUG] Bug: Tmux scrollback buffer cleared during autocompact/compact
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Bug Report: Tmux History Cleared During Autocompact/Compact
Summary
When Claude Code performs autocompact or compact operations, the entire tmux scrollback buffer is cleared as if :clear-history was executed. This is the opposite behavior described in issue #11260.
Environment
- Claude Code Version: 2.0.76 (Claude Code)
- Tmux Version:
tmux 3.5a - OS: Linux
- Terminal: Running inside Claude Code's built-in terminal (parent process:
claude) - Shell:
/bin/bash
Tmux Configuration
# ~/.tmux.conf
set -g history-limit 1000000
set -g default-terminal "screen-256color"
set-option -sa terminal-overrides ",xterm*:Tc"
set -g mouse on
set -s set-clipboard on
# Base window from 1
set -g base-index 1
set -g pane-base-index 1
# Vim style pane selection
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# Plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'dreamsofcode-io/catppuccin-tmux'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
# tmux-resurrect settings
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-strategy-bash 'history'
set -g @resurrect-save-shell-history 'on'
# tmux-continuum settings
set -g @continuum-restore 'on'
set -g @continuum-save-interval '15'
# Clipboard integration
set -g @override_copy_command 'xclip -selection clipboard -in'
# Vi mode
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Split window in current path
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
Problem Description
Expected Behavior
When Claude Code performs autocompact or manual compact operations, the tmux scrollback buffer should preserve all history (up to the configured history-limit of 1,000,000 lines).
Actual Behavior
The entire tmux scrollback buffer is cleared as if I had executed :clear-history in tmux. The buffer shows [0/0] and all previous output is lost.
Key Details
- This happens specifically during autocompact/compact operations
- Does NOT happen with
/clearcommand (which correctly preserves tmux history per #11260) - The clearing is complete - not just Claude Code output, but ALL terminal output including bash commands
- Cannot scroll back to any previous content
- Buffer counter shows
[0/0]
Steps to Reproduce
- Start tmux session:
``bash``
tmux new -s test
- Run some commands to populate scrollback buffer:
``bash``
for i in {1..100}; do echo "Line $i"; done
- Start Claude Code:
``bash``
claude
- Have a conversation that generates significant context (enough to trigger autocompact)
- Or manually trigger compact with context management
- Observe: After autocompact occurs, the entire tmux scrollback buffer is cleared
- Try to scroll back (Ctrl+b + [):
- Expected: See previous output
- Actual: Buffer is empty, shows
[0/0]
Related Issues
- Issue #11260: Opposite problem -
/cleardoes NOT clear scrollback buffer - Issue #4851: Rewind lag in tmux after extended use (possibly related to memory management)
Potential Causes
Based on investigation:
- Escape Sequence Emission: Claude Code might be emitting terminal escape sequences during compact that inadvertently clear tmux history:
\033[3J- Clear scrollback buffer\033[H\033[2J- Clear screen and move cursor
- Internal State Reset: The compact operation might trigger a terminal state reset that tmux interprets as a clear-history command
- Plugin Interference: tmux-resurrect or tmux-continuum might be interacting with Claude Code's compact operation in unexpected ways
Additional Context
- The
history-limitof 1,000,000 lines is configured correctly - The problem is consistent - happens every time autocompact triggers
- No manual intervention (like manually calling
:clear-history) is performed - Other tmux features work normally (pane switching, copy mode, etc.)
Workarounds Attempted
None found - the buffer is irreversibly cleared after compact.
Expected Fix
Claude Code's autocompact/compact operations should:
- NOT emit any terminal escape sequences that clear scrollback
- Only manage its internal conversation state
- Preserve all terminal output in the tmux scrollback buffer
- Behave consistently with
/clearcommand (which preserves scrollback per #11260)
Impact
- High: Loss of important terminal history during long coding sessions
- Cannot review previous command outputs or errors
- Forces frequent session restarts to preserve history
- Disrupts workflow when working with large codebases
Debug Information Needed
Would be helpful to know:
- What terminal control sequences (if any) are emitted during compact?
- Is there internal terminal state manipulation during compact?
- Are there any settings to control this behavior?
---
Note: I'm happy to provide additional debugging information, logs, or test cases if needed.
What Should Happen?
Claude Code's autocompact/compact operations should only manage its internal conversation state without affecting the tmux scrollback buffer.
The tmux history (configured with history-limit 1000000) should be preserved, allowing me to scroll back through all previous terminal output.
This should behave like the /clear command (which correctly preserves tmux scrollback per issue #11260).
Error Messages/Logs
Found evidence of autocompact events in Claude Code debug logs (~/.claude/debug/*.txt):
2026-01-02T20:51:21.523Z [DEBUG] Getting matching hook commands for PreCompact with query: auto
2026-01-02T20:52:43.879Z [DEBUG] Getting matching hook commands for SessionStart with query: compact
2026-01-02T20:52:43.879Z [DEBUG] Matched 0 unique hooks for query "compact" (0 before deduplication)
Observations from logs:
- PreCompact hook is triggered with query "auto" (autocompact)
- SessionStart hook is triggered with query "compact" (manual compact)
- No hooks are configured (0 matches)
- No terminal control sequences are logged - cannot verify what (if any) escape sequences are emitted
- No buffer state information - cannot verify tmux buffer size before/after
What's missing from logs:
- Terminal escape sequences emitted during compact (e.g.,
\033[3J,\033[2J) - Terminal state changes
- Tmux buffer interaction
- Any explicit "clear" or "reset" operations
Steps to Reproduce
Steps to Reproduce
- Start tmux session:
``bash``
tmux new -s test
- Run some commands to populate scrollback buffer:
``bash``
for i in {1..100}; do echo "Line $i"; done
- Start Claude Code:
``bash``
claude
- Have a conversation that generates significant context (enough to trigger autocompact)
- Or manually trigger compact with context management
- Observe: After autocompact occurs, the entire tmux scrollback buffer is cleared
- Try to scroll back (Ctrl+b + [):
- Expected: See previous output
- Actual: Buffer is empty, shows
[0/0]
Claude Model
Sonnet (default)
Is this a regression?
Yes, this worked in a previous version
Last Working Version
1
Claude Code Version
2.0.76 (Claude Code)
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
_No response_
13 Comments
I wonder if there is any progress or workarounds? It is indeed inconvenient look the scroll back buffer.
I am frustrated and impeded by this behavior on a daily basis. Useful conversations/content are frequently deleted after compacting a conversation. I do not understand why claude needs to modify my scrollback in order to compact or clear context.
+1 — This is a serious UX problem. Context compaction is an internal optimization and should be invisible to the terminal experience. Losing scrollback mid-session means losing reference to earlier test output, command results, and conversation history that the user is actively working with. Competing tools (e.g., Codex) preserve scrollback regardless of internal context management. Terminal display and context window are separate concerns.
Note the conversation history is still stashed somewhere under ~/.claude, so it is not lost irreversibly. If you insist a bit, Claude will be able to pull it.
This said, I agree the current behaviour is rather annoying and seems to be absolutely pointless.
Just to clarify: It's not just the loss of claude conversation history -- it's the whole frickin' terminal history that gets wiped, eg anything and everything that was in the term history before claude was even run. Very, very aggravating UX behavior. Unwanted, surprising, and unwarranted.
Still happening on v2.1.78 (Linux, tmux 3.5a). This started after upgrading from 2.1.77 →
2.1.78 on March 17, 2026 — was not experiencing this on 2.1.77.
Evidence: Mid-session, tmux display-message -p '#{history_size}/#{history_limit}' shows
155/100000 — the scrollback is being actively wiped, not overflowed. I was able to scroll
back to the beginning of the conversation earlier in the same session, then after a
re-render/compaction event the scrollback was truncated.
Environment:
Root Cause Found —
\e[3Jinansi-escapesclearTerminalI tracked this down to the exact source. The
ansi-escapeslibrary bundled incli.jsdefines:The
\e[3J(CSI 3 J = "Erase Scrollback") is the destructive sequence. It tells the terminal emulator to wipe the scrollback buffer. tmux processes this and clears the pane's history, resulting in[0/0].Ink enters "fullscreen mode" when
outputHeight >= stdout.rows(around line 320 ofink.jsin the bundle) and emitsclearTerminalon every render cycle — so scrollback is destroyed repeatedly, not just during compaction.Confirming 2.1.78 regression
@Khandurian's observation matches — 2.1.72 works, 2.1.78+ is broken. Something changed in the Ink rendering path between those versions that triggers fullscreen mode more aggressively.
Working patch
Remove
\e[3Jfrom the twoclearTerminaldefinitions in the bundle. In 2.1.80, the minified variable names areJY/izandMY/rz:This preserves screen clearing (
\e[2J) and cursor homing (\e[H) — only the scrollback destruction is removed. tmux scrolling works again after patching.Note on tmux
terminal-overridesset -ga terminal-overrides ',*:E3@'does not fix this because Ink constructs escape sequences as string literals at bundle load time — it never queries terminfo. The raw\e[3Jbytes go straight to tmux's input parser regardless of capability overrides.Proper upstream fix
The
clearTerminalfunction should not use\e[3Jat all — or at minimum, should detect tmux ($TMUXenv var is already checked inansi-escapesfor OSC wrapping) and omit\e[3Jwhen running inside tmux.Environment: Claude Code 2.1.80, tmux 3.5a, Linux,
TERM=tmux-256colorUpdate:
CLAUDE_CODE_NO_FLICKER=1on 2.1.89 — fixes one bug, reveals anotherTested the NO_FLICKER env var on 2.1.89 inside tmux (tmux 3.4, Debian 13).
What it fixes: Scrollback destruction is gone. The alt-screen buffer keeps
\e[3Jaway from tmux's main scrollback. Mouse wheel enters copy-mode with actual content — no more[0/0].What it breaks:
Two-bug model confirmed:
\e[3Jscrollback destruction (this issue) — NO_FLICKER fixes it by rendering in the alternate screen buffer.eraseLines()cursor-up overflow — persists in NO_FLICKER mode. Likely the cause of the broken scroll sensitivity. The cursor-up sequences that overflow the viewport in main-screen mode manifest as extreme scroll insensitivity in alt-screen mode.The binary patch from my earlier comment (removing
\e[3JfromclearTerminalin cli.js) fixes only bug 1. Bug 2 requires clamping the cursor-up count ineraseLines()tomin(linesToErase, stdout.rows)— which is what PR #35683 addresses.Net result: NO_FLICKER trades one set of tmux problems for another. Still pinned to 2.1.72 for interactive tmux sessions.
Environment: Claude Code 2.1.89, tmux 3.4, Debian 13 (trixie),
CLAUDE_CODE_NO_FLICKER=1— Väinämöinen / Pulsed Media
I traced this to Ink's render loop.
The call chain:
ansi-escapesdefinesclearTerminalaseraseScreen + \e[3J + cursor-home(VT-spec correct), butvadimdemedes/inkcalls it on every render cycle when output exceeds the viewport. A repaint should never touch scrollback. This was partially identified in ink#359 back in 2020, but that issue was closed without fixing the render path, and the Anthropic threads haven't connected back to it.Every terminal that implements VT correctly honors CSI 3 J: tmux, GNU screen, xterm.js (and everything built on it: ttyd, code-server, VS Code, Cursor), Microsoft Terminal, WezTerm, Alacritty, Kitty, Ghostty. Only iTerm2 on macOS has an opt-out. Full cross-terminal table, Ink fix options, and the cli.js sed patch:
Full analysis: root cause chain, cross-terminal table, working fixes
For anyone on non-macOS right now: the working paths are (a) the cli.js sed patch (strips
\e[3Jfrom the bundled clearTerminal), (b) pinning to around 2.1.75, or (c) raw TTY SSH without any multiplexer.Happy to file this against Ink if nobody at Anthropic is already on it.
Post-2.1.101 follow-up on our April 10 observation.
Byte-level measurements on 2.1.114 confirm zero
CSI 3J— the chain we named is closed as intended. Scrollback loss continues via the remainingCSI 2J + CSI Hrender-loop cadence on emulators that treatCSI 2Jas scrollback-destructive (ConPTY, xterm.js).Detail and mitigation attempts: #42670.
Update: posted a working two-part workaround for the post-2.1.101
CSI 2Jrender-loop scrollback issue on WSL2/Win11. CombinesCLAUDE_CODE_NO_FLICKER=1(alt-screen, preserves scrollback) with stdin-side amplification of SGR wheel events (restores usable wheel sensitivity that NO_FLICKER alone destroys).Full detail: #42670.
This is a duplicate of #34718, which was fixed as of version 2.1.101.
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.