[BUG] Bug: Tmux scrollback buffer cleared during autocompact/compact

Status Closed — duplicate
Reported on v2.0.76
Maintainer reply ✓ Yes — claude[bot]
Activity 13 comments · opened Jan 5, 2026 · closed Apr 27, 2026
💡 Likely answer: A maintainer (claude[bot], contributor) responded on this thread — see the highlighted reply below.

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 /clear command (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

  1. Start tmux session:

``bash
tmux new -s test
``

  1. Run some commands to populate scrollback buffer:

``bash
for i in {1..100}; do echo "Line $i"; done
``

  1. Start Claude Code:

``bash
claude
``

  1. Have a conversation that generates significant context (enough to trigger autocompact)
  • Or manually trigger compact with context management
  1. Observe: After autocompact occurs, the entire tmux scrollback buffer is cleared
  1. Try to scroll back (Ctrl+b + [):
  • Expected: See previous output
  • Actual: Buffer is empty, shows [0/0]

Related Issues

  • Issue #11260: Opposite problem - /clear does NOT clear scrollback buffer
  • Issue #4851: Rewind lag in tmux after extended use (possibly related to memory management)

Potential Causes

Based on investigation:

  1. 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
  1. Internal State Reset: The compact operation might trigger a terminal state reset that tmux interprets as a clear-history command
  1. Plugin Interference: tmux-resurrect or tmux-continuum might be interacting with Claude Code's compact operation in unexpected ways

Additional Context

  • The history-limit of 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:

  1. NOT emit any terminal escape sequences that clear scrollback
  2. Only manage its internal conversation state
  3. Preserve all terminal output in the tmux scrollback buffer
  4. Behave consistently with /clear command (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:

  1. What terminal control sequences (if any) are emitted during compact?
  2. Is there internal terminal state manipulation during compact?
  3. 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

  1. Start tmux session:

``bash
tmux new -s test
``

  1. Run some commands to populate scrollback buffer:

``bash
for i in {1..100}; do echo "Line $i"; done
``

  1. Start Claude Code:

``bash
claude
``

  1. Have a conversation that generates significant context (enough to trigger autocompact)
  • Or manually trigger compact with context management
  1. Observe: After autocompact occurs, the entire tmux scrollback buffer is cleared
  1. 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_

View original on GitHub ↗

13 Comments

abbbe · 7 months ago

I wonder if there is any progress or workarounds? It is indeed inconvenient look the scroll back buffer.

shaneberg · 7 months ago

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.

forhadahmed · 6 months ago

+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.

abbbe · 6 months ago

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.

9atatimer · 6 months ago
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.

Khandurian · 5 months ago

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:

  • Claude Code 2.1.78
  • tmux 3.5a (Homebrew/Linuxbrew)
  • Linux 6.17.0-14-generic
  • history-limit 100000
  • alternate-screen on (default)
MagnaCapax · 5 months ago

Root Cause Found — \e[3J in ansi-escapes clearTerminal

I tracked this down to the exact source. The ansi-escapes library bundled in cli.js defines:

clearTerminal = process.platform === "win32"
    ? `${eraseScreen}${ESC}0f`
    : `${eraseScreen}${ESC}3J${ESC}H`;

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 of ink.js in the bundle) and emits clearTerminal on 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[3J from the two clearTerminal definitions in the bundle. In 2.1.80, the minified variable names are JY/iz and MY/rz:

sed -i 's/\${JY\.eraseScreen}\${iz}3J\${iz}H/${JY.eraseScreen}${iz}H/g' cli.js
sed -i 's/\${MY\.eraseScreen}\${rz}3J\${rz}H/${MY.eraseScreen}${rz}H/g' cli.js

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-overrides

set -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[3J bytes go straight to tmux's input parser regardless of capability overrides.

Proper upstream fix

The clearTerminal function should not use \e[3J at all — or at minimum, should detect tmux ($TMUX env var is already checked in ansi-escapes for OSC wrapping) and omit \e[3J when running inside tmux.

Environment: Claude Code 2.1.80, tmux 3.5a, Linux, TERM=tmux-256color

MagnaCapax · 5 months ago

Update: CLAUDE_CODE_NO_FLICKER=1 on 2.1.89 — fixes one bug, reveals another

Tested 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[3J away from tmux's main scrollback. Mouse wheel enters copy-mode with actual content — no more [0/0].

What it breaks:

  • Scroll sensitivity: ~5 mouse wheel clicks to move 1 line. Native tmux scrolling in other panes works normally — isolated to the Claude Code pane.
  • Color rendering: Different color scheme compared to normal main-screen mode.
  • General responsiveness: Noticeably sluggish.

Two-bug model confirmed:

  1. \e[3J scrollback destruction (this issue) — NO_FLICKER fixes it by rendering in the alternate screen buffer.
  2. 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[3J from clearTerminal in cli.js) fixes only bug 1. Bug 2 requires clamping the cursor-up count in eraseLines() to min(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

MagnaCapax · 4 months ago

I traced this to Ink's render loop.

The call chain: ansi-escapes defines clearTerminal as eraseScreen + \e[3J + cursor-home (VT-spec correct), but vadimdemedes/ink calls 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[3J from 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.

MagnaCapax · 4 months ago

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 remaining CSI 2J + CSI H render-loop cadence on emulators that treat CSI 2J as scrollback-destructive (ConPTY, xterm.js).

Detail and mitigation attempts: #42670.

MagnaCapax · 4 months ago

Update: posted a working two-part workaround for the post-2.1.101 CSI 2J render-loop scrollback issue on WSL2/Win11. Combines CLAUDE_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.

claude[bot] contributor · 4 months ago

This is a duplicate of #34718, which was fixed as of version 2.1.101.

github-actions[bot] · 3 months ago

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.