codex icon indicating copy to clipboard operation
codex copied to clipboard

Can't enter alternate screen buffer

Open Fpointzero opened this issue 6 months ago • 4 comments

What version of Codex CLI is running?

codex-cli 0.133.0

What subscription do you have?

gpt-5.5

Which model were you using?

gpt-5.5

What platform is your computer?

Linux 6.19.10-300.fc44.x86_64 x86_64 unknown

What terminal emulator and version are you using (if applicable)?

screen/tmux

Codex doctor report


What issue are you seeing?

Subject

TUI fails to enter Alternate Screen Buffer when tui.alternate_screen = "always" on Linux/Fedora

Describe the Bug

Even when tui.alternate_screen is explicitly set to "always" in ~/.codex/config.toml (or passed via CLI overrides), Codex CLI (v0.133.0) fails to transition to the terminal's alternate screen buffer.

Instead of taking over the viewport in a clean, full-screen mode (like vim), the TUI continues to render inline directly within the primary screen buffer (main scrollback). Upon exiting the CLI (via /exit or Ctrl+C), the welcome banner, help prompts, and interactive history are not cleared and remain permanently in the terminal's scrollback history, polluting the shell.

Environment

  • Codex CLI Version: v0.133.0
  • Operating System: Fedora Linux (Workstation)
  • Terminal Emulator: [Please insert your terminal name here, e.g., GNOME Terminal, Alacritty, iTerm2]
  • TERM Variable: xterm-256color / xterm

Steps to Reproduce

  1. Configure ~/.codex/config.toml with the following:
    [tui]
    alternate_screen = "always"
    
    

What steps can reproduce the bug?

start codex-cli

What is the expected behavior?

No response

Additional information

No response

Fpointzero avatar May 26 '26 08:05 Fpointzero

One focused triage note from a local repo read: the config path appears to be fairly direct: config.tui_alternate_screen is passed through determine_alt_screen_mode(), and anything other than AltScreenMode::Never enables alt-screen unless --no-alt-screen is set. The actual enter path then calls EnterAlternateScreen in codex-rs/tui/src/tui.rs, but currently ignores the crossterm result.

That makes this issue especially useful if the reporter can add:

  • the exact ~/.codex/config.toml snippet, including whether it is under [tui]
  • whether codex --config tui.alternate_screen=always changes behavior
  • echo $TERM, infocmp | grep -E "smcup|rmcup", and whether tmux/screen has terminal overrides that disable alternate-screen switching
  • whether this reproduces outside tmux/screen in the same terminal emulator

If this turns out to be terminal capability related, a small product improvement might be to stop swallowing EnterAlternateScreen/LeaveAlternateScreen failures and surface a warning in codex doctor or startup diagnostics when always is configured but the terminal does not actually switch buffers.

SylvainWinning avatar May 26 '26 10:05 SylvainWinning

I have the exact same issue on Mac.

  • Codex CLI Version: 0.136.0
  • Operating System: MacOS 26.5
  • Terminal Emulator: Tried on Iterm2, Ghostty and the default Apple Terminal
  • TERM Variable: xterm-256color

I have set tui.alternate_screen to "always" in ~/.codex/config.toml as well. Running codex --config tui.alternate_screen=always had no effect, the issue still occurs. infocmp | grep -E "smcup|rmcup" - both present.

I was not using screen/tmux/zellij. My Copilot CLI and Claude code and other programs are able to use alternate screen in the same terminal, so i don't think it's a terminal capability related issue.

This my tui settings in ~/.codex/config.toml , if it helps.

[tui]
alternate_screen = "always"
session_picker_view = "comfortable"
status_line = [
  "codex-version",
  "model-with-reasoning",
  "context-window-size",
  "used-tokens",
  "context-used",
  "five-hour-limit",
  "weekly-limit",
  "current-dir",
  "git-branch",
  "thread-title",
]
status_line_use_colors = true
terminal_title = ["activity", "thread-title"]
theme = "monokai-extended"
pet = "codex"

[tui.model_availability_nux]
"gpt-5.5" = 4

[features]
js_repl = false
terminal_resize_reflow = false

akdurai avatar Jun 01 '26 20:06 akdurai

I can reproduce this on codex-cli 0.144.6 on macOS 26.3.2.

Terminals tested:

  • Ghostty 1.3.1
  • Apple Terminal

Configuration:

[tui]
alternate_screen = "always"

I verified that the configuration is recognized: codex --strict-config doctor --json reports config.load: ok. These were fresh Codex sessions, with no --no-alt-screen flag and no tmux, Zellij, or screen involved.

In both terminals, scrolling moves the entire Codex UI, including the composer/input box, as if Codex were still rendering in the primary terminal buffer. Setting alternate_screen = "always" does not change the behavior.

This suggests the issue is still present in 0.144.6 and is not specific to a particular macOS terminal emulator.

Chaixueyuan avatar Jul 19 '26 10:07 Chaixueyuan

Follow-up after additional iTerm2 testing (2026-07-22): this owned-screen series correctly establishes a retained full-screen viewport, pinned composer, paused follow state, and jump control, but its current fixed-step virtual wheel scroller does not yet match Claude Code’s mature fullscreen scrolling behavior. Please treat this branch as an experimental prototype rather than a production-ready parity claim. For natural iTerm2 scrolling and selection today, use the isolated native-scrollback branch: https://github.com/Andrewwilliamross/codex/tree/agent/fix-iterm2-native-scrollback.

I confirmed this is not a missing terminal capability: the current tui.alternate_screen = "always" path does not give Codex ownership of a retained full-screen viewport.

I ported OpenAI’s public fcoury/owned-alt-screen-text-selection prototype onto current main, preserving Felipe Coury’s authorship, and completed the user-facing interaction:

  • always: Codex physically owns the alternate screen and retains the conversation viewport
  • auto: existing overlay-only inline behavior remains unchanged
  • never / --no-alt-screen: native terminal scrollback remains available
  • fixed composer at the bottom
  • PageUp/PageDown and mouse-wheel transcript navigation
  • scrolling upward pauses automatic bottom-following
  • a clickable Jump to bottom (click) ↓ control restores the latest output and follow state
  • draft composer text remains intact while scrolled

Experimental branch: https://github.com/Andrewwilliamross/codex/tree/agent/fix-iterm2-scrollback

The owned-screen foundation is split into the original-author commits 642345cdf339 through f653664b5586; the jump control and current-main compatibility are in dfa4ccd3d19e.

Functional verification: 3,259 codex-tui tests passed, 4 skipped, package fixer/formatter passed, and the basic scroll/pause/draft/click/resume flow passed manual iTerm2 testing. Further human testing identified the scroll-feel limitation described above.

If this architecture matches the intended semantics for always, I’m happy to continue refining it or split the series however maintainers prefer.

Andrewwilliamross avatar Jul 21 '26 22:07 Andrewwilliamross

Still reproducible with Codex CLI 0.154.0 on Linux.

Environment:

  • Kitty with TERM=xterm-kitty
  • Codex runs on a remote machine over SSH
  • Reproduces both inside Herdr and without Herdr; both tests ran on the same remote host over SSH from Kitty
  • --strict-config -c tui.alternate_screen=always is accepted

To inspect the bytes emitted by Codex, I ran it under the util-linux script command:

script -q -c 'command codex --strict-config -c tui.alternate_screen=always' /tmp/codex-screen.typescript

After exiting Codex with /quit, I searched the captured output for the standard alternate-screen sequences. It contained no CSI ? 1049 h, CSI ? 1047 h, or CSI ? 47 h, indicating that Codex never requested an alternate buffer. As a control, manually sending CSI ? 1049 h/l from the same remote shell, over the same SSH connection, switched buffers and restored the primary buffer correctly.

terminal-point avatar Sep 13 '26 15:09 terminal-point

Retested with codex-cli 0.157.1 in a plain SSH session using Kitty (TERM=xterm-kitty), outside tmux, GNU screen, and Zellij.

Command used:

codex --strict-config -c tui.alternate_screen=always

A control capture using tput smcup and tput rmcup produced:

enter_1049=1
leave_1049=1
enter_1047=0
leave_1047=0
enter_47=0
leave_47=0

The Codex capture produced:

enter_1049=0
leave_1049=0
enter_1047=0
leave_1047=0
enter_47=0
leave_47=0

This confirms that the terminal and capture path support alternate-screen switching, while Codex CLI still does not request it.

The user-visible behavior in 0.157.1 differs from what I had experienced previously. The TUI now clears the visible screen on startup and restores the previous view on exit. Its output includes screen-clearing, scrolling-region, and reverse-index controls, which is consistent with fullscreen-style management of the primary buffer. Intervening releases were not tested systematically, so this does not identify the version in which the clearing and restoration behavior changed.

Therefore, the user experience is improved, but tui.alternate_screen = "always" still does not enter the terminal's actual alternate screen. Is this primary-buffer implementation intentional, or should always still emit a matching alternate-screen enter and leave pair?

The release notes suggest that the new clearing and restoration behavior may be associated with the optional fullscreen TUI introduced in 0.156.0 and the fullscreen transcript changes enabled by default in 0.157.0. I did not test the 0.156.x releases, so I cannot identify the exact first version exhibiting this behavior.

terminal-point avatar Sep 26 '26 12:09 terminal-point

(response from codex)

Thanks for including the tput control. It confirms that your Kitty capture could detect an alternate-screen switch. On 0.157.1, Codex restored the previous view on exit, but your capture showed no matching enter/leave pair.

In 0.167.0, Fullscreen mode is intended to use the terminal’s actual alternate buffer. The fullscreen draw path calls enter_alt_screen(), and the terminal code sends EnterAlternateScreen on entry and LeaveAlternateScreen on exit. Fullscreen draw path · Terminal enter/leave implementation

Could you repeat the same SSH capture on 0.167.0 or later with both settings explicit?

codex -c tui.fullscreen_transcript=true -c tui.alternate_screen=always

After a normal /exit, the capture should contain a matching enter/leave pair. If both counts are still zero, that’s a reproducible discrepancy in Fullscreen mode even if the shell looks restored.

etraut-openai avatar Nov 09 '26 02:11 etraut-openai

Could you repeat the same SSH capture on 0.167.0 or later with both settings explicit?

Retested with codex-cli 0.169.0 using Kitty (TERM=xterm-kitty) over plain SSH to Rocky Linux 10.2, outside Herdr.

Command captured with util-linux script:

codex --strict-config \
  -c tui.fullscreen_transcript=true \
  -c tui.alternate_screen=always

After reaching the normal interactive UI and exiting with /exit:

enter_1049=1
leave_1049=1
enter_1047=0
leave_1047=0
enter_47=0
leave_47=0

The enter sequence preceded the main UI, and the matching leave followed shutdown. The command exited successfully. The tput smcup/rmcup control also produced one matching 1049 pair.

The previous shell screen was restored on exit. In a separate scrolling test, the composer stayed fixed while scrolling the transcript.

The alternate-screen failure reported on 0.157.1 no longer reproduces here on 0.169.0. Thanks for following up!

terminal-point avatar Nov 15 '26 13:11 terminal-point

Thanks for the careful retest and control capture. This confirms Codex 0.169.0 enters and leaves the alternate buffer correctly in fullscreen mode, restores the shell, and keeps the composer fixed while scrolling. Closing as fixed in fullscreen mode.

etraut-openai avatar Nov 16 '26 00:11 etraut-openai