Skip to content

TUI: startup-only palette cache leaves input unreadable after system light/dark changes (0.154.0) #45163

Todo

Description

@lightninglu10

What version of Codex CLI is running?

codex-cli 0.154.0. The startup-only cache is also present in upstream main at a592c38c16cdd7623dacc9168926ebccedfb67d3.

What subscription do you have?

Not relevant to this terminal-rendering issue.

Which model were you using?

Model-independent; observed in long-running Codex CLI sessions.

What platform is your computer?

macOS, Darwin 25.6.0, arm64.

What terminal emulator and version are you using?

CodePress Terminal, a Tauri/xterm.js host configured to follow the system light/dark appearance. The host updates its terminal palette and answers OSC 10/11 queries. Exact host release not recorded.

What issue are you seeing?

After the terminal changes between light and dark appearance while Codex is already running, the composer and previously rendered user-message blocks retain their old background colors. The terminal's default foreground updates, producing nearly white text on a pale background (or the inverse mismatch). Long-lived sessions become unreadable after an automatic macOS appearance change.

Refocusing and redrawing do not refresh the cached palette. Restarting/resuming refreshes the startup colors, but the next appearance change can break the session again.

This follows up my earlier report #37298, which described a failed refresh permanently poisoning the color cache in 0.146.0. The current implementation has a different failure mode: focus-driven refresh has been removed entirely, so no transient failure is required.

What steps can reproduce the bug?

  1. Configure a terminal to follow macOS system appearance and start Codex while the terminal is light.
  2. Send a message so both a user-message block and the composer are visible.
  3. Change macOS appearance to dark without restarting Codex, or leave the process running across the automatic appearance change.
  4. Refocus the terminal and type in the composer.
  5. Observe that the terminal's normal foreground/background have changed but the composer/message backgrounds retain the light-theme color. Repeat dark to light as well.

A terminal host can verify the distinction by recording OSC 10/11 requests: the current focus handler intentionally does not send a new pair on focus regain.

What is the expected behavior?

Codex should adapt its palette-dependent rendering when the terminal's colors change, without restarting the process, losing draft text, dropping/reordering keys or pasted input, or inserting terminal replies into the composer.

Root cause and relevant change

PR #35649, merged July 27, intentionally removed focus-time palette queries because they could block the input loop and discard keystrokes. That input-preservation fix is important, but it also leaves a long-lived TUI unable to adapt to system appearance changes.

Source at the inspected commit:

  • terminal_palette.rs: the process-global cache stores the startup foreground/background; attempted prevents re-querying through default_colors().
  • tui/event_stream.rs: FocusGained explicitly preserves the startup-cached palette and only returns the focus event.
  • style.rs: user messages get an explicit derived background without a paired explicit foreground. When the terminal's default foreground changes, the old explicit background remains.
  • terminal_probe.rs: the existing Unix color probe uses a direct reader. Its read_until helper explicitly does not replay unrelated input, so simply calling this again from the focus handler would reintroduce the reason for Preserve TUI input when terminal focus returns #35649.

Proposed approach

Please restore runtime palette refresh through the normal terminal input/event path rather than reinstating the old synchronous raw-input probe:

  1. Request OSC 10/11 asynchronously on focus regain as a compatibility fallback. Also support a terminal theme-change notification so a theme switch while the terminal stays focused can refresh the palette; TUI: set DECSET 2031 so an in-place terminal theme change updates the composer colours #38575 tracks DECSET 2031 for that case.
  2. Parse replies through the existing input owner, preserving ordinary keys, bracketed paste, and fragmented/late replies. Coalesce repeated refresh triggers and keep only one bounded refresh outstanding; never wait on terminal replies in the UI input handler.
  3. Commit a complete valid foreground/background pair atomically. On timeout or malformed/partial replies, preserve the last known good palette and allow a later retry, avoiding TUI: one failed color requery permanently disables OSC 10/11 re-detection (poisoned cache in requery_default_colors) #37298's poisoned-cache behavior.
  4. Invalidate palette-dependent render caches and repaint the composer and affected transcript content when colors actually change. Preserve an explicitly chosen syntax-highlighting theme.
  5. Preserve startup trust/confirmation protections and terminal ownership during external-editor handoff and suspend/resume; a refresh must not start a second competing stdin reader.

Suggested regression coverage: both light/dark directions in the same process; theme changes without a focus transition; repeated focus notifications; immediate, delayed, fragmented, missing and partial OSC replies; a failed refresh followed by a successful one; typing and bracketed paste during refresh; unchanged draft and input ordering; and recoloring existing visible user-message blocks, not only newly generated output.

Workaround

Launching a new process with FORCE_COLOR=1 codex selects Codex's basic-color fallback, which uses the default/reset color for the derived composer background. This is source-backed, not an interactive validation from this investigation, and sacrifices richer colors. Restarting normally only fixes colors until the next theme change. /theme controls syntax highlighting and does not invalidate this palette cache.

Related issues

This report adds the 0.154.0 observation and the current startup-only-cache diagnosis, linking the earlier reports rather than treating this as an unrelated color preference. Per the current contribution policy, I am including the implementation constraints and regression cases here for the maintainers.

Activity

  1. added
    bug
    CLI
    TUI
    on Sep 13, 2026
  2. github-actions commented on Sep 13, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  3. lightninglu10 commented on Sep 15, 2026

    @lightninglu10
    Author

    Status: still reproduces on current main.

    Evidence: the FocusGained handler in codex-rs/tui/src/tui/event_stream.rs still keeps the startup-cached palette by design, and the palette cache in terminal_palette.rs latches on first attempt, so a mid-session OS appearance switch still leaves stale composer and message backgrounds. Related: #45291 was closed as a duplicate of this issue, confirming this as the live tracker.

    What is left: async palette refresh through the input path as proposed above, with atomic pair commit and repaint on change.

  4. naveedjanmo commented on Sep 19, 2026

    @naveedjanmo

    Confirmed on Codex CLI 0.155.0 on macOS arm64, September 18, using Herdr 0.9.0. A live light/dark switch updates the terminal surface but leaves the composer and some other TUI elements using the previous colors. With multiple long-running agent sessions, the workaround means interrupting, exiting, and resuming each session.

    I also checked the installed CLI in a controlled pseudo-terminal, without submitting a model request:

    1. Answer the startup OSC 10/11 queries with foreground #eeeeee and background #111111.
    2. Let the TUI initialize and type an unsubmitted draft.
    3. Change the harness's color-query answers to foreground #111111 and background #ffffff, then send focus-lost/focus-gained (CSI O, CSI I).
    4. Compare with a fresh process started using those light colors.
    Observation Dark startup, then light answers + refocus Fresh light startup
    OSC 10/11 requests One pair at startup; no new pair after refocus One pair at startup
    Explicit input background #2d2d2d, retained after refocus #f4f4f4
    DECSET 2031 subscription Not emitted Not emitted

    The harness used TERM=xterm-256color, COLORTERM=truecolor, FORCE_COLOR=3, with NO_COLOR removed. It kept the switched process alive for four seconds after the focus event. This verifies the stale palette and lack of re-query, not a fix or input-preservation behavior during a refresh.

    Current upstream a633ebc1 still explicitly keeps the startup-cached palette in the focus handler. Herdr already has terminal-side support for Mode 2031 notifications, but Codex does not subscribe in the tested release.

    The existing implementation references in #38575 look relevant: Codex fork PR and crossterm support PR. I have not tested those patches. Linking them here alongside the current-release reproduction, per the contribution policy, rather than opening another duplicate issue or external PR.

  5. pletinsky commented on Sep 20, 2026

    @pletinsky

    Independent repro on macOS + Ghostty.

    When macOS appearance switches from Light to Dark while Codex is already running, Ghostty updates to the dark theme, but the Codex composer/bottom panel remains light. Restarting/resuming Codex fixes the colors.

    Environment:

    • macOS 15.7.9 (24G830)
    • Ghostty 1.3.1, build 15212, commit 332b2aefc
    • codex-cli 0.155.1

    This affects long-running sessions in normal daily use, especially with automatic macOS appearance switching.

    Happy to test a prerelease/nightly fix if useful.

  6. rakhimovv commented on Sep 21, 2026

    @rakhimovv

    Independent confirmation on Codex CLI 0.155.1 with Herdr 0.9.1 on macOS 26.6.2.

    During a dark-to-light appearance transition, already-running Codex sessions kept the dark composer/input background and stale palette-dependent colors, while the Herdr terminal surface switched to light. A new Codex session created in the same Herdr workspace immediately used the correct light palette.

    Restarting or resuming the affected Codex processes is the only recovery I observed. This old-process/new-process comparison is consistent with the startup-only palette cache described in this issue.

  7. mradalbert commented on Sep 28, 2026

    @mradalbert

    Same issue with gnome-terminal

  8. pbar1 commented on Oct 4, 2026

    @pbar1

    I reproduced this with Codex CLI 0.158.0 on macOS 26.6.2 (arm64), Ghostty 1.3.1, and tmux 3.7c. Following the contribution policy, I’m sharing a tested reference patch here: pbar1/codex:auto-theme, commit 3d33104c3b, based on upstream cd7d9e128c.

    With Ghostty following system appearance, start Codex with -c 'tui.theme="ansi"', type an unsent draft, and switch macOS between light and dark. The running composer retains its previous shading while a fresh instance gets the correct colours. Selecting ANSI or Base16 does not avoid this: the composer still uses RGB shading derived from the cached terminal palette.

    One additional cache surfaced during testing: an already-open theme picker retains keyboard-hint foregrounds captured at construction, even after its preview and selection shading refresh.

    The patch preserves the normal shaded UI and explicit syntax-theme selection. It polls OSC 10/11 every second, pauses the crossterm reader for an exclusive probe, preserves queued input, and replays interleaved typing/paste. Only complete foreground/background pairs replace the cache; changed colours invalidate rendering caches and refresh picker hints. Missing replies retain the last good palette. A terminal that has previously answered keeps the normal retry interval, avoiding a roughly 31-second stale-colour delay encountered with a longer failure backoff.

    Validation:

    • Repository regressions compare the complete composer buffer with a fresh composer for ANSI and all six Base16 variants, including exact input shading and draft preservation. A running-process pseudo-terminal test covers interleaved Unicode paste, missing replies, and successful recovery. The focused run passed 155 unit tests and two integration tests; five unit tests and one integration test are new.
    • Separate local scripts changed actual macOS appearance via AppleScript, keeping each patched process alive and comparing it with fresh installed instances. All 42 comparisons passed: seven themes × three appearances × composer/picker. These compare draft-cell styles and picker colour sets, not screenshots or full-screen equality. The driver scripts are outside the repository test suite.

    This implementation is Unix-only polling, not DECSET 2031 support (#38575). The probe has a 100 ms read deadline, and input processing pauses during the handoff. It is not a fully asynchronous reply parser; that remains an architectural tradeoff. The replay and input-preservation tests specifically address the regression that motivated #35649. Full cross-platform CI has not been run.

  9. shepherdjerred commented on Oct 5, 2026

    @shepherdjerred

    I would love a fix for this. It's so ugly. At the moment I have to restart my Codex instances

    Codex+ghosttty using system theme following sunset

    Ugly:
    Image

    Correct:
    Image

  10. louwers commented on Oct 7, 2026

    @louwers

    Also a problem on Linux (GNOME) + Ghostty.

  11. 28 remaining items

  12. dltacube commented on Nov 11, 2026

    @dltacube

    Way adding a useless report result you just need to up vote the original issue !

    deleted it

  13. katzkevin commented on Nov 12, 2026

    @katzkevin

    Still happening on 0.167.1

  14. kskadart commented on Nov 17, 2026

    @kskadart

    I can still reproduce this on the latest stable release, Codex CLI 0.169.0, with Warp 0.2026.10.21.08.25.02 on macOS 26.6.2 (arm64). Start Codex in a light Warp theme, then switch Warp to dark while Codex is running. The terminal background changes, but the composer retains its light fill. The “This conversation is open in another app” card also retains its light fill when visible. A fresh Codex process picks up the dark palette.

    I confirmed this with the same CLI build in an isolated PTY. Codex sent OSC 10 and OSC 11 palette queries at startup and used RGB 244,244,244 for the composer. After switching the emulated terminal palette and triggering a redraw with focus events, resize, and input, Codex sent no further palette queries and kept the same fill. A fresh process started with a dark palette used RGB 37,37,37.

  15. GladioFeng commented on Nov 18, 2026

    @GladioFeng

    Can not belive, it still not fixed in 0.170.
    your rival Claude code are works fun.

  16. mathjiajia commented on Nov 18, 2026

    @mathjiajia

    In fact for my commonly used agents, only codex has this wired issue.

  17. 0ekk commented on Nov 19, 2026

    @0ekk

    Another trigger on 0.170.0: re-attaching tmux from a different terminal (no theme change)

    Codex 0.170.0 inside tmux. Codex was started while the tmux session was attached from a terminal with a dark background. Later the session was re-attached from a terminal with a light background. No terminal changed its theme; only the attached client changed.

    Result: the composer keeps the fill computed from the startup background, while text uses the new client's default foreground, so the input becomes hard to read. Restarting or resuming the session restores correct colors.

    After the re-attach, tmux answers the color queries for the new client: a fresh pane querying OSC 10/11 gets the light client's colors (e.g. rgb:ffff/ffff/ffff / rgb:3333/3333/3333), and CSI ? 996 n gets CSI ? 997 ; 2 n. A re-probe would therefore pick up the new colors.

    In 0.170.0, tui/event_stream.rs keeps the startup palette on FocusGained (to avoid blocking the input loop), and there is no ?2031 subscription, so this case has no refresh path.

    A possible approach: a non-blocking re-probe that writes the OSC 10/11 queries from the main loop and parses the replies in the existing crossterm event stream, triggered by:

    • FocusGained
    • CSI ? 997 reports (after CSI ? 2031 h)
    • resize, since switching tmux clients often changes the window size
  18. zwsn commented on Nov 25, 2026

    @zwsn

    Can not belive, it still not fixed in 0.172

  19. blegat commented on Nov 25, 2026

    @blegat

    In omarchy where you can so easily switch themes, this issue is quite annoying and make codex looks bad compared to the alternatives on that agent-first OS.

  20. kventinel commented on Nov 25, 2026

    @kventinel

    I reproduced this in both directions on Codex CLI 0.172.0 using a controlled pseudo-terminal on macOS 26.7.3 (arm64). With truecolor enabled, after the terminal palette switched the typed text used the terminal’s default foreground, but the composer still emitted its startup-derived background. It retained #f0f0f0 after light → dark and #2c2c2c after dark → light. The harness observed one OSC 10/11 pair at startup and none after the switch, including after refocus.

    I also tested a local change based on upstream 06f334aa4b that lets the terminal supply both foreground and background for the editable composer and inline answer fields. In both directions, with the terminal still focused, the rebuilt CLI preserved the text typed before the switch, accepted additional text after it, and rendered the combined draft using terminal-default colors. This approach removes the tinted fill from those input fields and leaves palette refresh for submitted messages and syntax highlighting outside the scope of the test. The focused TUI run passed 506 tests.

  21. itsb commented on Nov 28, 2026

    @itsb

    @fcoury-oai I’ve published a Codex 0.172.0 build with live palette refresh. It takes a similar approach to rodchristiansen’s patch. OSC 10/11 replies arrive through the same input stream as keys and paste, so typing can continue while the query is pending. A complete foreground/background pair updates the palette. A timeout keeps the last good colors and allows a later retry. Related fork PR

    Refresh runs on a terminal theme notification, focus regain, or return from a terminal handoff. There’s also /refresh-colors for terminals that answer color queries but don’t send theme notifications. If the terminal stays focused and sends no notification, a refresh still needs a manual trigger or a focus change. Reference branch

    I added a PTY regression test that switches light → dark → light without refocusing and checks that the composer repaints and preserves the prompt text. The test fails against upstream 0.172.0 on macOS ARM64 and Linux x64 because the composer keeps its light background after switching to dark. It passes against the autodark build on both platforms. Feature commit · Test commit

    Would the async input stream approach fit what you’re considering upstream? I’m happy to test a nightly build on macOS and Linux. I can manually switch between light and dark with text in the prompt box and check that the colors update, the text stays intact, and typing still works.

  22. scottdensmore commented on Nov 30, 2026

    @scottdensmore

    Still seeing this on Codex CLI 0.172.0 with macOS 26.7.3 and Ghostty 1.4.0. With Codex already running, switching macOS to Dark changes the terminal and the prompt text becomes white, but the input box keeps its pale gray fill. The resulting contrast makes typed text hard to read.

    Please keep the input readable across live appearance changes in Ghostty and Apple Terminal, including when Codex is running inside tmux (3.8 installed here). Ghostty is where I observed it. Apple Terminal and tmux are requested test cases.

    A manual command to refresh the composer colors or an option to use the terminal's default foreground and background for the composer would also help when a terminal or multiplexer cannot deliver a live appearance update.

  23. ShuoRaa commented on Nov 30, 2026

    @ShuoRaa

    I reproduced this on macOS with Codex CLI 0.172.0 in the VS Code 1.138.0 integrated terminal. Switching from Dark Modern to Light Modern left the composer fill at #333333, while the terminal switched its default text color to #3B3B3B.

    I tested a Unix TUI fix in ShuoRaa/codex#1. In the same running CLI session the composer fill changed from #333333 to #EEEEEE and back to #333333, with the draft preserved throughout. One VS Code detail relevant to this issue is that the terminal answered OSC 10/11 but reported DEC mode 2031 as unsupported. The fork uses a two-second recheck while that terminal is focused, so a theme change also takes effect without requiring a keystroke or focus change.

  24. yuyongyan29-dev commented on Nov 30, 2026

    @yuyongyan29-dev

    I can reproduce this in Rex 0.1.0-preview.37 on macOS 27.2.1 (arm64) with Codex CLI 0.172.0.

    1. Set Rex to follow the system appearance and open an interactive Codex session.
    2. Switch macOS from Light to Dark while the session is running. Rex updates its background, but the Codex input box keeps its light fill.
    3. Start Codex in Dark and switch macOS to Light. The input box keeps its dark fill. In both cases, the input box should follow the new appearance in the running session.

    I also reproduced both directions in a controlled pseudo-terminal with the installed CLI. After switching the reported palette and triggering a redraw, Codex still emitted the startup fill (#f0f0f0 after Light → Dark, #2c2c2c after Dark → Light). The CLI sent its OSC 10/11 color queries at startup only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CLITUIbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions