Repository navigation
Description
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?
- Configure a terminal to follow macOS system appearance and start Codex while the terminal is light.
- Send a message so both a user-message block and the composer are visible.
- Change macOS appearance to dark without restarting Codex, or leave the process running across the automatic appearance change.
- Refocus the terminal and type in the composer.
- 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;attemptedprevents re-querying throughdefault_colors().tui/event_stream.rs:FocusGainedexplicitly 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. Itsread_untilhelper 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:
- 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.
- 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.
- 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.
- Invalidate palette-dependent render caches and repaint the composer and affected transcript content when colors actually change. Preserve an explicitly chosen syntax-highlighting theme.
- 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
- TUI: one failed color requery permanently disables OSC 10/11 re-detection (poisoned cache in requery_default_colors) #37298 — my earlier report: one failed requery permanently disabled future refreshes.
- Composer text becomes unreadable after live terminal theme switch #14105 — composer readability after a live terminal theme switch.
- TUI: set DECSET 2031 so an in-place terminal theme change updates the composer colours #38575 — theme-change reporting without a focus transition.
- Input box remain dark after the system theme turn to light #18942 — related focus/theme refresh discussion.
- Preserve TUI input when terminal focus returns #35649 — intentional removal of focus queries to preserve input.
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
github-actions commentedon Sep 13, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
lightninglu10 commentedon Sep 15, 2026
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.
naveedjanmo commentedon Sep 19, 2026
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:
#eeeeeeand background#111111.#111111and background#ffffff, then send focus-lost/focus-gained (CSI O,CSI I).#2d2d2d, retained after refocus#f4f4f4The harness used
TERM=xterm-256color,COLORTERM=truecolor,FORCE_COLOR=3, withNO_COLORremoved. 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
a633ebc1still 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.
pletinsky commentedon Sep 20, 2026
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:
This affects long-running sessions in normal daily use, especially with automatic macOS appearance switching.
Happy to test a prerelease/nightly fix if useful.
rakhimovv commentedon Sep 21, 2026
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.
mradalbert commentedon Sep 28, 2026
Same issue with gnome-terminal
pbar1 commentedon Oct 4, 2026
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:
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.
shepherdjerred commentedon Oct 5, 2026
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:

Correct:

louwers commentedon Oct 7, 2026
Also a problem on Linux (GNOME) + Ghostty.
28 remaining items
dltacube commentedon Nov 11, 2026
deleted it
katzkevin commentedon Nov 12, 2026
Still happening on 0.167.1
kskadart commentedon Nov 17, 2026
I can still reproduce this on the latest stable release, Codex CLI
0.169.0, with Warp0.2026.10.21.08.25.02on macOS26.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,244for 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 RGB37,37,37.GladioFeng commentedon Nov 18, 2026
Can not belive, it still not fixed in 0.170.
your rival Claude code are works fun.
mathjiajia commentedon Nov 18, 2026
In fact for my commonly used agents, only codex has this wired issue.
0ekk commentedon Nov 19, 2026
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), andCSI ? 996 ngetsCSI ? 997 ; 2 n. A re-probe would therefore pick up the new colors.In 0.170.0,
tui/event_stream.rskeeps the startup palette onFocusGained(to avoid blocking the input loop), and there is no?2031subscription, 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:
FocusGainedCSI ? 997reports (afterCSI ? 2031 h)zwsn commentedon Nov 25, 2026
Can not belive, it still not fixed in 0.172
blegat commentedon Nov 25, 2026
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.
kventinel commentedon Nov 25, 2026
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
#f0f0f0after light → dark and#2c2c2cafter 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
06f334aa4bthat 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.issue-proofs: 5 port tests for upstream TUI issues (openai#12882, ope…
itsb commentedon Nov 28, 2026
@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-colorsfor 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 branchI 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.
scottdensmore commentedon Nov 30, 2026
Still seeing this on Codex CLI
0.172.0with macOS26.7.3and Ghostty1.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.8installed 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.
ShuoRaa commentedon Nov 30, 2026
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
#333333to#EEEEEEand 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.yuyongyan29-dev commentedon Nov 30, 2026
I can reproduce this in Rex 0.1.0-preview.37 on macOS 27.2.1 (arm64) with Codex CLI 0.172.0.
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 (
#f0f0f0after Light → Dark,#2c2c2cafter Dark → Light). The CLI sent its OSC 10/11 color queries at startup only.