Repository navigation
Description
What variant of Codex are you using?
CLI (codex-cli 0.147.0, macOS arm64)
What feature would you like to see?
Codex reads the terminal's foreground and background once at startup with OSC 10/11 and holds that answer for the process lifetime. The discussion in #18942 is about restoring a re-query on FocusGained. That covers a user switching macOS appearance while Codex sits in a background window, but it cannot cover a terminal that changes its own colours while its window keeps focus, because there is no focus transition to hang the re-query on.
DECSET 2031 is the mechanism for that case:
- The application subscribes with
CSI ? 2031 h, and unsubscribes withCSI ? 2031 lon shutdown. - The terminal then sends
CSI ? 997 ; 1 nwhen it becomes dark andCSI ? 997 ; 2 nwhen it becomes light, whenever its colour scheme changes for any reason. - The report is a prompt to re-ask rather than the news itself, so the handler is just "re-issue the OSC 10/11 probe" and reuses whatever probe path the
FocusGainedfix lands on. The 1/2 payload only says which direction it moved.
This matters for every terminal whose theme is its own rather than the OS's: Ghostty and WezTerm configs, iTerm2 profiles, and any host app with its own palette. Concretely, in Threading, a macOS terminal I maintain that hosts agent CLIs and owns its own themes, a user switching the app theme from a dark one to a light one leaves a running Codex painting a #393939 composer plate with #CFCFCF ink onto a #FFFFFF background, and there is no focus change anywhere in that interaction. Quitting and resuming the session is the only recovery.
Claude Code subscribes to 2031 and re-themes live under the same theme switch. strings on the Codex 0.147.0 binary contains no 2031, so a terminal that emits the report has nothing Codex can hear.
Additional information
Measured against 0.147.0 in a bare PTY (no tmux, no SSH, no emulator), harness and results in #18942: exactly one OSC 10/11 query per process, at startup, and none afterwards under focus events, keyboard input, window resize or SIGWINCH.
2031 originates in Contour's terminal spec and is implemented by Ghostty, WezTerm, foot and others, so the report arrives from real terminals today.
Activity
jdcodes1 commentedon Aug 18, 2026
Implementation notes from the current code, for whoever picks this up:
The palette is a process-lifetime cache with an
attemptedflag, filled once by the bounded startup probe (https://github.com/openai/codex/blob/1f41cc5d92/codex-rs/tui/src/terminal_palette.rs#L140-L175).set_default_colors_from_startup_probealready overwrites it, so the "re-probe on 2031 report" handler mostly exists — reset the cache and re-run the OSC 10/11 probe, then trigger a full redraw.The real blocker is plumbing: after startup the TUI reads input through crossterm's event stream, and crossterm's parser silently discards CSI sequences it doesn't recognize —
CSI ? 997 ; Ps nis one of them. So the report never reaches application code without either a crossterm patch/fork hook or moving the subscription parsing into the raw-input layer the startup probe already uses. That plumbing choice is shared with theFocusGainedre-query in #18942, so it's worth solving once for both: any mechanism that can re-run the probe post-startup serves 2031, focus, and a manual/theme refreshfallback alike.Prompt a runtime that re-reads its colours only on focus
me-on-gh commentedon Aug 24, 2026
Environment
Problem
When Terminal.app switches between light and dark profiles while Codex remains
running, Codex keeps the foreground/background palette cached at startup.
The terminal and tmux repaint correctly, but the Codex composer retains colors
from the previous theme and can become effectively unreadable.
Previously I worked around this by sending
CSI I(FocusGained) to markedCodex panes. That stopped working after #35649 / commit 976129f, because
FocusGainednow requests a redraw without re-querying OSC 10/11 colors.tmux refresh-client,SIGWINCH, resize events, and synthetic focus eventstherefore only redraw the stale cached palette. Restarting Codex corrects it.
Reproduction
CSI Ithrough tmux.Requirement
A long-running Codex TUI should be able to refresh its cached terminal
foreground/background colors without restarting and without losing or delaying
keyboard input.
Suggested acceptance criteria
trigger such as
/refresh-theme, a signal, or a documented control sequence.DECSET 2031 may cover supporting terminals, but an explicit refresh mechanism is
still needed for terminals or multiplexers that do not support or forward it.
cblp0k commentedon Aug 25, 2026
Confirming this issue on Linux with Foot, including the current Codex release.
Environment
0.149.0, standalone Linux x86_64 build1.27.0TERM=footCOLORTERM=truecolor7.2.0--1-MANJAROReproduction
codex.SIGUSR1/SIGUSR2).Actual behavior
Foot changes its background and palette immediately, but the running Codex TUI keeps the old light RGB background in the composer/input area.
The stale white composer remains after keyboard input, normal redraws, and an explicit
SIGWINCH. Restarting only Codex — without restarting Foot — fixes the colors immediately.Expected behavior
Codex should subscribe to Foot private mode 2031 notifications. After receiving a theme-change report, it should:
Foot 1.27 implements private mode 2031, so this appears to be the same missing subscription described in this issue. This reproduction also confirms that the problem is still present in Codex CLI 0.149.0 and affects the light-to-dark direction.
piotrostr commentedon Aug 26, 2026
Reference implementation is ready:
It subscribes to DEC mode 2031, handles color-scheme reports automatically, re-queries OSC 10/11 through an input-preserving probe, replaces the palette cache, re-resolves the adaptive syntax theme, fixes stale composer foreground cells, and redraws. No command or config surface.
Validated on Ghostty 1.2.3 through tmux 3.6a on macOS.
just test -p codex-tui: 3976 passed, 6 skipped, including a PTY regression test for automatic refresh and interleaved typeahead preservation.The repository blocks external PR creation, so the Codex change is hosted as a reviewable fork PR for maintainers to cherry-pick or port.
~ codex & piotr
Prompt a runtime that re-reads its colours only on focus
fbaltor commentedon Aug 27, 2026
Confirming on Linux with a direct Ghostty PTY, without tmux or SSH.
Environment
0.149.11.3.1(GTK,TERM=xterm-ghostty,COLORTERM=truecolor)26.05, GNOME/WaylandReproduction
This is the same stale startup palette described here, but confirms the in-place/no-focus-transition path on Ghostty 1.3.1 under Linux. Normal redraws do not repair it because the terminal defaults have changed while Codex retains palette-derived RGB values.
dkozlov commentedon Aug 30, 2026
I can confirm this on Android over SSH with Mobile SSH (https://mobile-ssh.github.io) and
codex-cli 0.149.1.While debugging it I first found a terminal-side issue: Mobile SSH was swallowing Codex's
CSI ? 996 nsemantic colour-scheme query. After fixing that, Codex starts with the correct palette in both light and dark themes. An in-place theme change still reproduces this issue:Mobile SSH 2.16 now implements the terminal side of this protocol:
CSI ? 996 nreplies withCSI ? 997 ; 1 n(dark) orCSI ? 997 ; 2 n(light).DECSET 2031is tracked, including DECRQM state.With Codex 0.149.1, the terminal never observes
CSI ? 2031 h, so it correctly sends no live notification and Codex retains the stale palette.This confirms the requested subscription is useful beyond macOS-native terminals: it also affects a terminal whose palette changes locally while Codex is reached through SSH.
fabge commentedon Aug 30, 2026
Confirming this is still reproducible with:
0.151.0I switched the terminal theme while a Codex session was running. The terminal background updated immediately, but Codex retained colors from the previous theme.
This affects more than the composer: the input area remains light, while parts of the transcript, diff preview, and status UI retain stale colors or have very low contrast.
Expected behavior: all palette-derived TUI colors should be recalculated and the entire interface redrawn after an in-place terminal theme change.
stefanwayon commentedon Sep 11, 2026
Confirming this remains a usability problem in codex-cli 0.154.0. Adding a reproduction, an additional affected component, and a confirmed workaround.
Reproduction and impact
This is more than a cosmetic mismatch: it reduces input-text contrast during ordinary automatic or manual system theme switching. Selecting the ANSI syntax theme does not prevent it.
Confirmed workaround
Restarting with:
while retaining
tui.theme = "ansi"makes the interface substantially more usable. This was tried and confirmed by the affected user.Source inspection for the 0.154.0 release explains both symptoms and the workaround:
Color::Reset.Requested behaviour
Please subscribe to terminal-issued colour/palette-change notifications and refresh all palette-derived colours, including the composer and animated/shimmer text, without restarting the session. Re-query OSC 10/11 for the actual foreground/background values, update the cache, invalidate affected rendered styles, and redraw while preserving keyboard input.
iTerm2 is a relevant supported-terminal target: its VT100Terminal implementation handles DEC mode
2031viasendUnsolicitedDarkModeDSRand emits the997dark/light report. This is source verification, not a capture of events from the affected session.The protocol specification defines subscribing with
CSI ? 2031 h, receivingCSI ? 997 ; 1 n/CSI ? 997 ; 2 n, and unsubscribing withCSI ? 2031 l. Notifications should prompt a palette refresh even when focus has not changed.Please include a regression check that switches themes during the shimmer animation and checks composer foreground/background contrast. A documented whole-TUI ANSI/default-colour option would also be useful as a fallback; the current syntax-theme setting alone does not provide this.
Related bug: #18942.
NorthIsUp commentedon Oct 17, 2026
Still reproducible in codex-cli 0.163.0 (macOS arm64), in tty7, a terminal that supports DECSET 2031 and sends
CSI ? 997 ; 1|2 non every light/dark change.The 0.163.0 binary contains the
OSC 10/11probe strings and?1004h, but nothing for?2031or?997, so Codex never subscribes. After a dark → light flip, plain default-colour text follows the terminal, but the composer and user-message backgrounds stay dark: they were derived from the startupOSC 11answer. Restarting (codex resume --last) is the only workaround.The current focus-in handler (
codex-rs/tui/src/tui/event_stream.rs) deliberately keeps the startup palette, so neither path re-probes today. Subscribing to 2031 and re-running the OSC 10/11 probe when a 997 report arrives would cover terminals like this one, as described above.NorthIsUp commentedon Oct 17, 2026
Additional current reproduction on codex-cli 0.163.0 with tty7 26.10.0, macOS 26.7.1 (25G241), arm64. CLI/OS versions and
TERM_PROGRAM=tty7/TERM_PROGRAM_VERSION=26.10.0were checked locally. The reproduction below is the user's observed session, not an automated replay.Expected: the running TUI should refresh all palette-dependent backgrounds and foregrounds together after the terminal follows the system theme, without requiring a restart or losing the draft/input.
The user supplied a screenshot of this occurrence. It is intentionally not uploaded because it includes private project paths and session information; the relevant visual symptom is described above. No private logs or project files are attached.
This appears to be the same runtime palette-refresh problem tracked here and in #45163. This follow-up confirms the system-theme-change/readability symptom on the versions above; it does not independently establish which terminal notification or cached-style path is responsible.
nfarina commentedon Nov 3, 2026
Confirming this on codex-cli 0.166.0 (macOS arm64). Codex sends
OSC 10/OSC 11once at startup and never again. I drove it in a pty and sent a focus-out/focus-in pair (it enables?1004h), an unsolicitedCSI ? 997 ; 2 n, and a resize. None of them led to another color query, so the composer keeps its startup background.For a terminal that already supports this: Miks (https://github.com/nfarina/miks), a macOS terminal for running coding agents, sends
CSI ? 997 ; 1|2 non every light/dark change once a program sets mode 2031. It also answersCSI ? 996 n. Claude Code switches its theme live through it, so Codex subscribing withCSI ? 2031 hand querying OSC 10/11 again on each report would be all it takes.Written by Claude Opus 5.5 at my request. Feel free to delete it if it isn't useful.
gielcobben commentedon Nov 19, 2026
One thing from the terminal side that I don't see in this thread yet, because it affects how the handler has to be written.
A terminal can send more than one report per change, and the first can name the old theme.
I make Wortel, a macOS terminal built on libghostty. Logging the bytes each way with Claude Code running, one switch from light to dark produced this, all within 20 ms (T is the terminal, P the program):
Stock Ghostty on macOS does the same: ghostty-org/ghostty#15116. I have since removed the stale first report in Wortel, but two reports per change remain there, and Ghostty still sends three.
So, for whoever implements this:
bg_query_timerinsrc/nvim/tui/input.c).A handler that re-themes on the first report and ignores the rest would land on the wrong theme about as often as Codex does today.
What it looks like now. Measured with the Codex bundled in the desktop app (0.142.3): OSC 10 and OSC 11 once at startup, nothing after.
mainon 2026-11-19 still keeps the startup cache (tui/event_stream.rs, "Keep the startup-cached palette"). After a switch to dark, the composer is a near-white band with near-white text in it, a contrast of about 1.07, so what you type cannot be read. Claude Code follows the same switch live in the same terminal.To keep Codex usable I now force a minimum contrast in the terminal so the text is at least legible, and I plan to restart idle Codex processes on an appearance change (
codex resume <id>). Both are workarounds for one subscription and one re-query.