You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Input box remain dark after the system theme turn to light #18942
What terminal emulator and version are you using (if applicable)?
Ghostty + Tmux
What issue are you seeing?
After the system switch to light theme in another day morning, the input box of the codex cli is still in dark mode(last night is in dark mode). I have to /exit codex and reopen it again, the input box turns to light theme.
What steps can reproduce the bug?
Switch to dark mode in mac, and open codex:
2. then switch to light mode, and you will see the input box stay dark:
What is the expected behavior?
No response
Additional information
No response
Reacted by Younes Elhjouji, Chris Beiser, InnoZhan, everdimension-with-banner, Henri, Lewis Russell, Kostia R, cor, Brendan Mulholland, Michael and 6 more
It also adds a focused unit test for the FocusGained event path.
Why this hook
FocusGained is already where Codex refreshes its view of the terminal palette, so it is the least invasive place to update the adaptive theme as well. This keeps the work off the render hot path and only runs when the terminal returns focus.
User impact
terminals that update their reported default colors after a system appearance switch can cause Codex to follow the new appearance without restarting
users with an explicit tui.theme setting see no behavior change
Still reproducible on codex-cli 0.147.0 (macOS arm64), and the cause on main is now different from the one this issue was filed against.
The re-query was removed.codex-rs/tui/src/tui/event_stream.rs:274 now does:
Event::FocusGained => {self.terminal_focused.store(true,Ordering::Relaxed);// Keep the startup-cached palette: querying terminal colors here blocks the// input loop, and a direct probe would discard keys typed during the refresh.Some(TuiEvent::Draw)}
So the terminal's default colors are read exactly once, by the startup probe in codex-rs/tui/src/terminal_probe.rs (100 ms deadline), cached in a OnceLock in codex-rs/tui/src/terminal_palette.rs, and never refreshed for the life of the process. That makes the stale input box permanent in every terminal, not only after an OS appearance switch.
Measurement. I ran codex under a PTY harness that plays the host terminal and answers OSC 10/11, then counted the queries in the raw output:
what the harness did
ESC]10;?
ESC]11;?
ESC[?2031h
composer background emitted
answer rgb:2828/2a2a/3636
1
1
never
ESC[48;2;65;67;78m
answer rgb:ffff/ffff/ffff
1
1
never
ESC[48;2;244;244;244m
answer 250 ms late
1
1
never
none
answer nothing
1
1
never
none
answer, then send ESC[O and ESC[I at t+8s
1
1
never
ESC[48;2;65;67;78m
Codex enables focus reporting (ESC[?1004h) and the harness writes ESC[I to its input, and no second query appears. The composer background is user_message_bg_rgb in codex-rs/tui/src/style.rs, blended from the one cached value.
Repro without touching OS appearance. Start codex in a terminal whose theme is light, then switch that terminal to a dark theme. The composer keeps the light background while the text is drawn in the new light foreground, so the input line becomes unreadable. My case was Warp: it answers ESC]11;? with the active theme's background, and I changed themes 20 minutes into a session.
Suggested fix that does not reintroduce the blocking probe. Send ESC[?2031h at startup and update the cached palette when the terminal pushes CSI ?997;1n (dark) or CSI ?997;2n (light). That is push-based, so it costs nothing on the input loop, and it avoids the FocusGained freeze reported in #33037. Terminals that do not implement mode 2031 simply keep today's behavior.
Note for triage: #37298 proposes fixing requery_default_colors(), but that function no longer exists on main.
I’ve implemented and tested a reference fix for this:
on FocusGained Codex sends non-blocking OSC 10/11 queries. Responses are consumed through the existing Crossterm EventStream, avoiding a competing terminal reader and preserving input typed during the refresh. Once both colors arrive Codex updates the cached palette and redraws the TUI.
Validation: just test -p codex-tui — 3,447 tests passed, including PTY coverage confirming that palette queries occur when focus returns and immediate input is not lost.
I’m happy to open a Codex PR if I can get an to invite to contribute
Independent reproduction on codex-cli 0.147.0 (macOS arm64), in a bare PTY with no tmux, no SSH and no terminal emulator in the path. This corroborates @duc-cloudthinker's reading of event_stream.rs:274 and separates this from the failure modes in #23489 and #37298.
The harness answers OSC 10/11 immediately (microseconds, far inside the 100 ms deadline), then changes the terminal's colours and sends a focus transition:
The focus event is delivered and parsed. Codex sets DECSET 1004, and ZQZ written to the same fd right after the CSI I comes back echoed by the TUI. So the bytes arrive; FocusGained is received and deliberately ignored.
Exactly one query per process lifetime, here at t≈0.7s. No later query under keyboard input, window resize or SIGWINCH.
Repro, no dependencies, works against any build:
#!/usr/bin/env python3"""Minimal repro: does the Codex TUI ever re-read the terminal's colours?A bare PTY, no tmux, no SSH, no terminal emulator. It answers OSC 10/11immediately (microseconds, not the 100 ms deadline), so every timeout theory isoff the table. Usage: python3 osc_repro.py /path/to/codex"""importfcntl, os, pty, re, select, struct, sys, termios, timefromcollectionsimportCounterBIN=sys.argv[1] iflen(sys.argv) >1else"codex"pid, fd=pty.fork()
ifpid==0:
os.environ["TERM"] ="xterm-256color"os.environ["COLORTERM"] ="truecolor"os.execvp(BIN, [BIN])
fcntl.ioctl(fd, termios.TIOCSWINSZ, struct.pack("HHHH", 40, 120, 0, 0))
# Phase 1 answers with a distinctive dark blue so a *detected* palette is# impossible to confuse with the built-in dark fallback.answer, fg="1010/1010/6060", "e0e0/e0e0/e0e0"before, after=b"", b""queries, modes= [], set()
switched=Falsestart=time.time()
whiletime.time() -start<14:
ready, _, _=select.select([fd], [], [], 0.2)
now=time.time() -startifnow>6andnotswitched: # the terminal changes its coloursswitched=Trueanswer, fg="ffff/ffff/ffff", "1111/1111/1111"os.write(fd, b"\x1b[O") # focus losttime.sleep(0.1)
os.write(fd, b"\x1b[I") # focus gainedtime.sleep(0.3)
os.write(fd, b"ZQZ") # control: does input reach the TUI?ifnotready:
continuetry:
data=os.read(fd, 65536)
exceptOSError:
breakifnotdata:
breakifswitched:
after+=dataelse:
before+=dataforslotinre.findall(rb"\x1b\](1[01]);\?", data):
queries.append((slot.decode(), round(now, 2)))
forminre.findall(rb"\x1b\[\?([\d;]+)h", data):
modes.update(m.decode().split(";"))
ifb"\x1b]11;?"indata:
os.write(fd, ("\x1b]11;rgb:%s\x1b\\"%answer).encode())
ifb"\x1b]10;?"indata:
os.write(fd, ("\x1b]10;rgb:%s\x1b\\"%fg).encode())
ifb"\x1b[c"indata:
os.write(fd, b"\x1b[?1;2c")
ifb"\x1b[6n"indata:
os.write(fd, b"\x1b[1;1R")
try:
os.kill(pid, 9)
exceptOSError:
passos.close(fd)
defplates(buf):
text=buf.decode("utf-8", "replace")
returnCounter("#%02X%02X%02X"% (int(r), int(g), int(b))
forr, g, binre.findall(r"48;2;(\d+);(\d+);(\d+)", text)).most_common(3)
print("focus reporting enabled (DECSET 1004):", "1004"inmodes)
print("OSC 10/11 queries (slot, seconds): ", queries)
print("plates before, told bg #101060: ", plates(before))
print("plates after, told bg #FFFFFF + focus:", plates(after))
print("control keystroke reached the TUI: ", b"ZQZ"inafter)
One note for whoever picks up @dandandy's branch: restoring the re-query on FocusGained does not cover terminals whose theme is application-owned rather than OS-owned. Changing the theme in a focused window produces no focus transition at all, so the composer stays stale while the window never loses focus. DECSET 2031 is the mechanism designed for exactly that, and Codex does not set it today (strings on the 0.147.0 binary contains no 2031). Filed separately as #38575.
Codex CLI: 0.149.0
Platform: macOS
Behavior:
When macOS automatically switches from light mode to dark mode at night,
an already-running Codex CLI session does not refresh the TUI theme correctly.
The composer/input area becomes a large white/light block, while the typed text
is effectively invisible because of the foreground/background color conflict.
This happens reproducibly every night when macOS automatically changes appearance.
Workaround:
Ctrl+C / exit Codex
Run codex resume <session-id>
The UI immediately renders correctly in dark mode.
Important:
The underlying Terminal renders correctly after the macOS appearance switch.
Only the already-running Codex TUI is affected.
Expected behavior:
Codex CLI should detect macOS/terminal appearance changes while running and
refresh the TUI palette automatically, without requiring the user to restart
the session.
another data point ruling out the terminal side: this repros in programa (libghostty-based terminal). when macos auto-switches between light and dark, the terminal swaps its default bg/fg immediately and emits the mode 2031 color scheme report, so the background under codex follows the new theme right away. codex keeps painting the palette it detected at startup, so after a dark to light flip you get light gray text on a light background, close to unreadable.
claude code running in the same terminal is unaffected because it draws with terminal defaults / ansi indices instead of fixed rgb.
subscribing to mode 2031 (CSI ? 2031 h and handling the unsolicited DSR report) or re-running theme detection when it arrives would fix live switching without needing a restart.
Working automatic reference implementation covering this repro is posted here: #38575 (comment)
It includes both live DEC mode 2031 refresh and the stale composer foreground fix. Validated on Ghostty 1.2.3 through tmux 3.6a. No command or config surface.
Codex keeps the composer/input-bar color that was detected when the process started. Switching Alacritty between light and dark themes does not update it.
Closing and reopening Alacritty does not fix the color when the Codex process remains alive in a persistent tmux session. After reattaching to that session, the composer still uses the old color. I have to close the tmux pane or session, create a new pane, and relaunch Codex.
Codex should refresh its terminal foreground and background colors when the terminal theme changes. It should also re-query them after a terminal disconnect and tmux reattachment.
#38575 looks related and proposes terminal theme-change notifications.
Still reproducible on Codex CLI 0.153.0 on macOS with Ghostty + tmux. After an automatic light/dark theme switch during a long-running session, the composer retains its old background and the text becomes effectively unreadable; restarting and resuming the session is the only reliable workaround. Sorry for the direct ping, @nornagon-openai and @dedrisian-oai, but could the TUI maintainers please take a look? This is extremely disruptive in long sessions.
Still reproducible on codex-cli 0.153.2, macOS 26 arm64, in a host-application terminal that owns its palette and follows the system appearance. The window keeps focus across the flip, so there is no CSI I to hang a re-query on: the terminal repaints dark and the composer keeps the light plate it computed at startup.
Two observations for triage, since this thread now has three reference branches and no landed fix.
1. The 2031 report is discarded by the pinned crossterm, and that bump is what blocks every branch here
At the rev codex-rs/Cargo.toml pins today (openai-oss-forks/crossterm@45fecb95), parse_csi has no arm for CSI ? … n:
So CSI ? 997 ; 1 n is dropped rather than mis-parsed. That is worth stating precisely, because it cuts both ways: sending CSI ? 2031 h today is harmless (it will not wedge the input parser), but it is also completely inert, and no amount of TUI-side work can see the report until the dependency changes.
Three fork PRs propose that plumbing, and all three are still open with the pin unchanged:
Since #2 comes from the Codex side, the intended shape may already be settled. Merging one of them and bumping the rev in codex-rs/Cargo.toml unblocks every community branch in this thread at once, and is a much smaller review than any of the branches themselves.
2. A refresh path that needs no fork bump already exists in the tree
Tui::probe_default_colors_after_protected_startup already re-probes after startup on Windows: pause the event stream, probe, write the cache, resume, redraw.
The palette cache is also not write-once, which I mention because it has been described upthread as a OnceLock. It is a OnceLock<Mutex<Cache<DefaultColors>>> where the OnceLock only guards the mutex; set_default_colors_from_startup_probe already overwrites both the value and the attempted flag:
The one real gap is typeahead during the 100 ms probe window, and the startup path already solves that: startup() replays everything it consumed through startup_replay_input() + crossterm::event::buffer_input(), both available on unix at the pinned rev.
So an explicit trigger, either a /theme refresh command or a re-probe on FocusGained gated on the startup probe having actually answered so silent terminals never pay the 100 ms, is self-contained inside codex-rs/tui and can land independently of the 2031 work and of any fork bump. It also covers the cases 2031 cannot: tmux reattach (reported above by @pascalporedda), and multiplexers that do not forward the report.
Why this bites harder than a wrong colour
Worth noting for prioritisation: when the OSC 10/11 probe returns nothing at all, user_message_style_for(None) yields a plain Style::default() and the composer simply inherits the terminal's own colours, which is always readable. The unreadable state only happens to terminals that do answer the probe correctly. A stale-but-successful detection is strictly worse than no detection, which is why "just restart Codex" keeps being the only workaround people find.
Closing as a duplicate of #45163. It tracks the composer staying in the old theme after automatic or manual appearance changes, including the need to restart to refresh it. The bug remains open there.
Activity
github-actions commentedon Apr 22, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
rushrs commentedon Apr 23, 2026
Proposed fix
I have a working branch with a narrow fix here:
The change does three things:
requery_default_colors()onFocusGainedtui.themeoverrides untouchedIt also adds a focused unit test for the
FocusGainedevent path.Why this hook
FocusGainedis already where Codex refreshes its view of the terminal palette, so it is the least invasive place to update the adaptive theme as well. This keeps the work off the render hot path and only runs when the terminal returns focus.User impact
tui.themesetting see no behavior change120318 commentedon May 27, 2026
any updates?
YounesElhjouji commentedon May 30, 2026
Same here, also with ghostty + tmux.
This one is a real bummer, sometimes quitting and reopening fixes it, but mostly does not, opening a new session also doesn't fix it.
codex: refresh adaptive syntax theme on focus regain (#2133)
duc-cloudthinker commentedon Aug 9, 2026
Still reproducible on
codex-cli 0.147.0(macOS arm64), and the cause onmainis now different from the one this issue was filed against.The re-query was removed.
codex-rs/tui/src/tui/event_stream.rs:274now does:So the terminal's default colors are read exactly once, by the startup probe in
codex-rs/tui/src/terminal_probe.rs(100 ms deadline), cached in aOnceLockincodex-rs/tui/src/terminal_palette.rs, and never refreshed for the life of the process. That makes the stale input box permanent in every terminal, not only after an OS appearance switch.Measurement. I ran
codexunder a PTY harness that plays the host terminal and answersOSC 10/11, then counted the queries in the raw output:ESC]10;?ESC]11;?ESC[?2031hrgb:2828/2a2a/3636ESC[48;2;65;67;78mrgb:ffff/ffff/ffffESC[48;2;244;244;244mESC[OandESC[Iat t+8sESC[48;2;65;67;78mCodex enables focus reporting (
ESC[?1004h) and the harness writesESC[Ito its input, and no second query appears. The composer background isuser_message_bg_rgbincodex-rs/tui/src/style.rs, blended from the one cached value.Repro without touching OS appearance. Start codex in a terminal whose theme is light, then switch that terminal to a dark theme. The composer keeps the light background while the text is drawn in the new light foreground, so the input line becomes unreadable. My case was Warp: it answers
ESC]11;?with the active theme's background, and I changed themes 20 minutes into a session.Suggested fix that does not reintroduce the blocking probe. Send
ESC[?2031hat startup and update the cached palette when the terminal pushesCSI ?997;1n(dark) orCSI ?997;2n(light). That is push-based, so it costs nothing on the input loop, and it avoids theFocusGainedfreeze reported in #33037. Terminals that do not implement mode 2031 simply keep today's behavior.Note for triage: #37298 proposes fixing
requery_default_colors(), but that function no longer exists onmain.dandandy commentedon Aug 13, 2026
I’ve implemented and tested a reference fix for this:
on
FocusGainedCodex sends non-blocking OSC 10/11 queries. Responses are consumed through the existing CrosstermEventStream, avoiding a competing terminal reader and preserving input typed during the refresh. Once both colors arrive Codex updates the cached palette and redraws the TUI.my reference fix branch:
https://github.com/dandandy/codex/tree/fix/live-terminal-palette-refresh
crossterm dependency PR:
openai-oss-forks/crossterm#1
Validation:
just test -p codex-tui— 3,447 tests passed, including PTY coverage confirming that palette queries occur when focus returns and immediate input is not lost.I’m happy to open a Codex PR if I can get an to invite to contribute
everlof commentedon Aug 14, 2026
Independent reproduction on
codex-cli 0.147.0(macOS arm64), in a bare PTY with no tmux, no SSH and no terminal emulator in the path. This corroborates @duc-cloudthinker's reading ofevent_stream.rs:274and separates this from the failure modes in #23489 and #37298.The harness answers OSC 10/11 immediately (microseconds, far inside the 100 ms deadline), then changes the terminal's colours and sends a focus transition:
Three things that pins down:
#101060produces a composer plate of#2C2C73, derived from that answer. So the startup probe succeeded and the cache holds a correct value. This is not TUI: one failed color requery permanently disables OSC 10/11 re-detection (poisoned cache in requery_default_colors) #37298 (a failed probe overwriting a good value) and not Do not rely on startup OSC probing for the composer background #23489 (a probe that times out). The palette is right and simply never read again.ZQZwritten to the same fd right after theCSI Icomes back echoed by the TUI. So the bytes arrive;FocusGainedis received and deliberately ignored.Repro, no dependencies, works against any build:
One note for whoever picks up @dandandy's branch: restoring the re-query on
FocusGaineddoes not cover terminals whose theme is application-owned rather than OS-owned. Changing the theme in a focused window produces no focus transition at all, so the composer stays stale while the window never loses focus. DECSET 2031 is the mechanism designed for exactly that, and Codex does not set it today (stringson the 0.147.0 binary contains no 2031). Filed separately as #38575.Prompt a runtime that re-reads its colours only on focus
xudalin007 commentedon Aug 21, 2026
Codex CLI: 0.149.0
Platform: macOS
Behavior:
When macOS automatically switches from light mode to dark mode at night,
an already-running Codex CLI session does not refresh the TUI theme correctly.
The composer/input area becomes a large white/light block, while the typed text
is effectively invisible because of the foreground/background color conflict.
This happens reproducibly every night when macOS automatically changes appearance.
Workaround:
codex resume <session-id>Important:
The underlying Terminal renders correctly after the macOS appearance switch.
Only the already-running Codex TUI is affected.
Expected behavior:
Codex CLI should detect macOS/terminal appearance changes while running and
refresh the TUI palette automatically, without requiring the user to restart
the session.
arzafran commentedon Aug 24, 2026
another data point ruling out the terminal side: this repros in programa (libghostty-based terminal). when macos auto-switches between light and dark, the terminal swaps its default bg/fg immediately and emits the mode 2031 color scheme report, so the background under codex follows the new theme right away. codex keeps painting the palette it detected at startup, so after a dark to light flip you get light gray text on a light background, close to unreadable.
claude code running in the same terminal is unaffected because it draws with terminal defaults / ansi indices instead of fixed rgb.
subscribing to mode 2031 (
CSI ? 2031 hand handling the unsolicited DSR report) or re-running theme detection when it arrives would fix live switching without needing a restart.piotrostr commentedon Aug 26, 2026
Working automatic reference implementation covering this repro is posted here: #38575 (comment)
It includes both live DEC mode 2031 refresh and the stale composer foreground fix. Validated on Ghostty 1.2.3 through tmux 3.6a. No command or config surface.
~ codex & piotr
Prompt a runtime that re-reads its colours only on focus
pascalporedda commentedon Aug 29, 2026
This is still reproducible with:
Codex keeps the composer/input-bar color that was detected when the process started. Switching Alacritty between light and dark themes does not update it.
Closing and reopening Alacritty does not fix the color when the Codex process remains alive in a persistent tmux session. After reattaching to that session, the composer still uses the old color. I have to close the tmux pane or session, create a new pane, and relaunch Codex.
Codex should refresh its terminal foreground and background colors when the terminal theme changes. It should also re-query them after a terminal disconnect and tmux reattachment.
#38575 looks related and proposes terminal theme-change notifications.
vladkens commentedon Sep 4, 2026
Still reproducible on Codex CLI 0.153.0 on macOS with Ghostty + tmux. After an automatic light/dark theme switch during a long-running session, the composer retains its old background and the text becomes effectively unreadable; restarting and resuming the session is the only reliable workaround. Sorry for the direct ping, @nornagon-openai and @dedrisian-oai, but could the TUI maintainers please take a look? This is extremely disruptive in long sessions.
evertjr commentedon Sep 4, 2026
Still reproducible on codex-cli 0.153.2, macOS 26 arm64, in a host-application terminal that owns its palette and follows the system appearance. The window keeps focus across the flip, so there is no
CSI Ito hang a re-query on: the terminal repaints dark and the composer keeps the light plate it computed at startup.Two observations for triage, since this thread now has three reference branches and no landed fix.
1. The 2031 report is discarded by the pinned crossterm, and that bump is what blocks every branch here
At the rev
codex-rs/Cargo.tomlpins today (openai-oss-forks/crossterm@45fecb95),parse_csihas no arm forCSI ? … n:https://github.com/openai-oss-forks/crossterm/blob/45fecb9508105988f42fe6ff0441783ed3717f92/src/event/sys/unix/parse.rs#L231-L235
and
Parser::advanceclears the buffer for any unrecognised CSI whose final byte is in0x40..=0x7e:https://github.com/openai-oss-forks/crossterm/blob/45fecb9508105988f42fe6ff0441783ed3717f92/src/event/source/unix/tty.rs#L450-L465
So
CSI ? 997 ; 1 nis dropped rather than mis-parsed. That is worth stating precisely, because it cuts both ways: sendingCSI ? 2031 htoday is harmless (it will not wedge the input parser), but it is also completely inert, and no amount of TUI-side work can see the report until the dependency changes.Three fork PRs propose that plumbing, and all three are still open with the pin unchanged:
Since #2 comes from the Codex side, the intended shape may already be settled. Merging one of them and bumping the rev in
codex-rs/Cargo.tomlunblocks every community branch in this thread at once, and is a much smaller review than any of the branches themselves.2. A refresh path that needs no fork bump already exists in the tree
Tui::probe_default_colors_after_protected_startupalready re-probes after startup on Windows: pause the event stream, probe, write the cache, resume, redraw.codex/codex-rs/tui/src/tui.rs
Lines 706 to 713 in b3f5e45
The palette cache is also not write-once, which I mention because it has been described upthread as a
OnceLock. It is aOnceLock<Mutex<Cache<DefaultColors>>>where theOnceLockonly guards the mutex;set_default_colors_from_startup_probealready overwrites both the value and theattemptedflag:codex/codex-rs/tui/src/terminal_palette.rs
Lines 175 to 196 in b3f5e45
The one real gap is typeahead during the 100 ms probe window, and the startup path already solves that:
startup()replays everything it consumed throughstartup_replay_input()+crossterm::event::buffer_input(), both available on unix at the pinned rev.codex/codex-rs/tui/src/terminal_probe.rs
Lines 272 to 290 in b3f5e45
So an explicit trigger, either a
/theme refreshcommand or a re-probe onFocusGainedgated on the startup probe having actually answered so silent terminals never pay the 100 ms, is self-contained insidecodex-rs/tuiand can land independently of the 2031 work and of any fork bump. It also covers the cases 2031 cannot: tmux reattach (reported above by @pascalporedda), and multiplexers that do not forward the report.Why this bites harder than a wrong colour
Worth noting for prioritisation: when the OSC 10/11 probe returns nothing at all,
user_message_style_for(None)yields a plainStyle::default()and the composer simply inherits the terminal's own colours, which is always readable. The unreadable state only happens to terminals that do answer the probe correctly. A stale-but-successful detection is strictly worse than no detection, which is why "just restart Codex" keeps being the only workaround people find.etraut-openai commentedon Oct 12, 2026
(response from codex)
Closing as a duplicate of #45163. It tracks the composer staying in the old theme after automatic or manual appearance changes, including the need to restart to refresh it. The bug remains open there.
theme: remind which codex panes need a restart after a flavor change