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

Resolved 💬 13 comments Opened Jan 5, 2026 by ricardoasensio Closed Apr 27, 2026

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 ↗

This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗