Skip to content

Auto set light/dark theme variants based on OS preference #12840

Open

Description

@galah92

What variant of Codex are you using?

v0.105.0

What feature would you like to see?

In continuation to #1618, I would like the Codex CLI to auto detect the MacOS preference (light/dark) and apply the relevant theme accordingly.

Additional information

No response

Activity

  1. etraut-openai commented on Feb 26, 2026

    @etraut-openai
    Contributor

    You're using the CLI, right? Terminal programs generally have their own light/dark settings and color themes that are independent of the OS's.

  2. galah92 commented on Feb 26, 2026

    @galah92
    Author

    CLI, yes. And in bat for example I can do:

    --theme="auto"
    --theme-light="minimal-light"
    --theme-dark="minimal-dark"
    

    Also many programs like neovim, ghostty, support that and auto switching when I toggle that option at the OS level.

    Edit: This might be helpful.

  3. davidgilbertson commented on Feb 26, 2026

    @davidgilbertson
    Contributor

    After update to 105 I see this, is that the intended default? I'm on Windows Terminal with dark mode.

    Image

    It seems that the /theme options all change text colour, but because the background colours are close to medium lightness, neither light nor dark text gives particularly good contrast. Changing to the GitHub theme makes diffs just readable, but it's a real squint-fest, and other text becomes unreadable.

    Image

    This makes 105 unusable for me, unless there's some option for "make it like it used to be"?

  4. davidgilbertson commented on Feb 26, 2026

    @davidgilbertson
    Contributor

    If I do this:

    $env:COLORTERM="truecolor"
    codex
    

    Then Codex correctly recognises my terminal as truecolor and I get the default dark green/red and can read diffs.

    For fellow Terminal users, this can be set as a regular environment variable, or in the settings JSON, as a property of a particular profile in Terminal:

    ...
    "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402436}",
    "name": "PowerShell",
    "environment": {
      "COLORTERM": "truecolor"
    }
    ...

    The underlying issue is that the supports-color crate used to detect color seems to just check environment variables, maybe some other heuristics, not the actual capability. E.g. if I run node then process.stdout.getColorDepth() it returns returns 24 for my terminal, which should be treated as truecolor.

  5. laffo16 commented on Feb 26, 2026

    @laffo16

    These background colours are blinding me, please can we do something to get those more natural colours we had in 0.104 or someway of easily configuring these background colours in the diff (including none as an option). I would of much preferred if 0.104 was the default theme after upgrading to 0.105. Completely onboard with everything david has mentioned above.

    update:
    david's fix with base16-256 theme is ok (i can see again!)

    Image Image
  6. davidgilbertson commented on Feb 26, 2026

    @davidgilbertson
    Contributor

    I think a quick fix in Codex would be logic like: "if a terminal can't do true color, don't use background colors".
    Then a more refined step would be to better detect truecolor-able terminals.

  7. galah92 commented on Feb 27, 2026

    @galah92
    Author

    @etraut-openai not sure why this issue was closed with a fix PR - the original request was to support light/dark variants based on OS preference.

  8. etraut-openai commented on Feb 27, 2026

    @etraut-openai
    Contributor

    Sorry, Github automatically closed it because it was referenced in the PR commit notes. Reopening.

  9. acgxv commented on Feb 28, 2026

    @acgxv

    You're using the CLI, right? Terminal programs generally have their own light/dark settings and color themes that are independent of the OS's.

    Image Image

    And I set it to auto. The theme will be changed automatically. Codex must support this.

    Allow to set different themes for different system themes.

  10. galah92 commented on Mar 4, 2026

    @galah92
    Author

    @etraut-openai the most pressing thing for me, which is related, is to fix the text background issue when switching between light/dark on the OS level, since right now when doing so the text is unreadable at all.

    The prompt background (and diffs/syntax theme) doesn't update on OS theme change because the terminal bg is queried once via OSC 11 and cached, re-query only happens on FocusGained.

    I'd like to add mode 2031 support so terminals that implement it (Ghostty, Kitty, WezTerm, foot, etc.) notify Codex on theme change, triggering requery_default_colors() + redraw. All three color subsystems already key off is_light(default_bg()), so this should just work. Terminals without mode 2031 fall back to the existing FocusGained behavior.

    Would this be welcome?

  11. added
    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal display
    and removed
    CLIIssues related to the Codex CLI
    on Apr 2, 2026
  12. galah92 commented on May 18, 2026

    @galah92
    Author

    @etraut-openai any chance to push this forward?

    Currently we have:

    [tui]
    theme = "light-theme"

    I would be appreciated if we can support:

    [tui]
    theme-light = "light-theme"
    theme-dark = "dark-theme"
  13. mavam commented on May 31, 2026

    @mavam

    Even better: just give us theme = "terminal".

    The terminal already has colors. Why another layer of theme on top of theme? Your Ghostty, Alacritty, etc., almost surely already has a light/dark theme. Just use that. (That's why I wrote https://github.com/mavam/pi-terminal-theme for Pi.)

  14. bric3 commented on Jun 10, 2026

    @bric3

    Also note that currently with the default settings, when the theme changes, e.g. from dark to light the prompt stays with the previous color. E.g.

    iTerm2
    codex in iTerm2 after going back from dark to light

    IntelliJ IDEA
    codex in IntelliJ IDEA after going back from dark to light

    This is so annoying that one has to restart and resume the session. Pretty disruptive.

  15. bric3 commented on Jun 10, 2026

    @bric3

    Also FYI, it seems that tennis found a way to reliably detect the term background:

    Tennis includes a termbg.zig module to detect the terminal background color so it can choose the correct theme (dark or light). Detection is complicated, and I'm calling it out here because I don't think anyone has implemented this in Zig yet.

    https://github.com/gurgeous/tennis/blob/498c1c6762f0d78297dc25bb5c13a195083238a6/src/termbg.zig

    By the way it seems there's a OSC 11 sequence, on which tennis is based, that is used to query the terminal background (and OSC 10 for the foreground).

  16. bric3 commented on Jun 10, 2026

    @bric3

    Oh actually it seems that codex is already doing that #16335 (comment)

    Which means codex should just refresh the values.

  17. arzafran commented on Sep 18, 2026

    @arzafran

    Root cause and a working implementation, since external PRs are not accepted here.

    Why it stays stale today. The TUI probes OSC 10/11 once in terminal_probe::startup and never again. Event::FocusGained in tui/event_stream.rs deliberately keeps the startup-cached palette. So after a macOS auto light/dark switch nothing re-reads the background, and highlight::adaptive_default_theme_selection keeps the mocha/latte pick from launch.

    The signal exists. Terminals that implement DEC private mode 2031 (Ghostty, Contour, kitty, foot, WezTerm) send CSI ? 997 ; 1 n (dark) / CSI ? 997 ; 2 n (light) the moment the scheme changes, if the app enabled it with CSI ? 2031 h. Claude Code already uses this. The Codex crossterm fork currently parses that report as an unknown private CSI and discards it, so Codex cannot see it.

    Implementation (built, cargo clippy -p codex-tui --all-targets -- -D warnings clean):

    1. crossterm fork: Surface DEC mode 2031 color scheme reports as Event::ColorSchemeChanged openai-oss-forks/crossterm#6 adds Event::ColorSchemeChanged(ColorScheme::{Dark, Light}) from the ?997;N n report, with a parser test.
    2. codex: main...arzafran:codex:theme-2031 (commit arzafran/codex@901c4d4cf7) (branch theme-2031, 3 files, +107). Enables mode 2031 in set_modes, disables it on restore. On the event: broker.pause_events(), re-run the existing bounded terminal_probe::default_colors (100 ms cap), set_default_colors_from_startup_probe, re-resolve the adaptive theme unless tui.theme is set, resume_events(), TuiEvent::Draw. Same pause-probe-resume shape as the suspend-key path and probe_default_colors_after_protected_startup on Windows. A failed probe keeps the cached palette rather than clearing it (the TUI: one failed color requery permanently disables OSC 10/11 re-detection (poisoned cache in requery_default_colors) #37298 pattern).

    Cost: keys typed inside the 100 ms probe window at the instant of the flip are dropped, same as the Windows post-startup probe. Unix only, since Windows Terminal declined mode 2031.

    Happy to adjust if a different shape fits better.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displayenhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions