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
TUI shows wrong theme on startup when system dark/light mode changed since last session #21871
When launching the OpenCode TUI in iTerm2 (with automatic dark/light mode switching based on system appearance), the initial theme mode is incorrect.
Example: If I was in light mode last time I used OpenCode, but now my system is in dark mode, OpenCode still shows light mode on startup. However, if I toggle the system appearance after OpenCode is running, it correctly switches themes via the CliRenderEvents.THEME_MODE event.
Steps to Reproduce
Open OpenCode in dark mode → use it → exit
Switch system to light mode (or vice versa)
Reopen OpenCode → it still shows the previous session's theme instead of the current one
Root Cause
In packages/opencode/src/cli/cmd/tui/context/theme.tsx, the ThemeProvider init prioritizes the cached theme_mode from KV storage over the freshly detected mode from OSC 11 (props.mode):
setStore(produce((draft)=>{constlock=pick(kv.get("theme_mode_lock"))constmode=pick(kv.get("theme_mode",props.mode))// ← cached value takes prioritydraft.mode=lock??mode??props.mode// ...}),)
Since apply() saves theme_mode to KV on every mode change, the stale cached value from the previous session overrides the current OSC 11 detection result on the next startup.
The runtime detection works fine because the renderer emits CliRenderEvents.THEME_MODE events which call apply() and update the mode correctly after startup.
Expected Behavior
When no theme_mode_lock is set, the startup mode should use the real-time OSC 11 detection result (props.mode), not the cached value from the previous session.
Suggested Fix
// In ThemeProvider init:constlock=pick(kv.get("theme_mode_lock"))// When not locked, always prefer the fresh OSC 11 detection resultdraft.mode=lock??props.mode
The KV-cached theme_mode should only be used as a fallback when OSC 11 detection fails (returns no result), not as the primary source.
Environment
OpenCode v1.4.3
iTerm2 on macOS with automatic dark/light mode switching
Activity
BretFisher commentedon Apr 15, 2026
I have this issue too. I thought I wasn't understanding how lock mode should work. 😂
anaskhan96 commentedon Apr 17, 2026
have the same issue in ghostty macos
i think this PR would fix it - #21011
github-actions commentedon Jul 4, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.