opencode icon indicating copy to clipboard operation
opencode copied to clipboard

tui: removing theme from cli.json does not revert to default theme

Open mezen opened this issue 2 weeks ago • 2 comments

Summary

In the TUI, changing or adding theme.name in cli.json applies live, but removing the theme entry does not revert the theme to the default (opencode) — the last explicitly applied theme stays, even after /reload.

Environment

  • opencode version: 2.3.0
  • OS: Windows 11 10.0.26300 (win32 x64)
  • Terminal: Windows Terminal
  • Shell: cmd.exe
  • Install/channel: latest (npm, @opencode/cli)
  • Active plugins: none

Reproduction

  1. Start the TUI with no theme entry in ~/.config/opencode/cli.json (default theme shown).
  2. Add "theme": { "name": "gruvbox" } → the theme changes live, no restart needed.
  3. Remove the theme entry again → the TUI keeps the gruvbox colors.
  4. Run /reload → the theme still stays gruvbox.
  5. Set "theme": { "name": "opencode" } explicitly → the default look is applied immediately.

Verified repeatedly (gruvbox and nord as test themes), with the TUI window focused during each change.

Expected Behavior

Removing the theme entry (or forcing a reload with /reload) restores the default theme (opencode), since the setting is no longer present.

Actual Behavior

The theme is only re-applied when a value is present in the config; an absent value does not reset the currently displayed theme. Reverting to the default requires explicitly setting "theme": { "name": "opencode" } or restarting the TUI.

Additional Context

  • The cli.json file is read and hot-reloaded correctly (theme changes apply live), so this is not a config-loading issue.
  • Workaround: set "theme": { "name": "opencode" } explicitly, or restart the TUI.
  • Minor/harmless; logged for completeness. Observed on Windows; not tested on Linux.

mezen avatar Nov 17 '26 11:11 mezen

Thanks for the clear steps. I reproduced this on @opencode/cli 2.3.0, and it still happens on the latest dev (a9a35b4).

What I did, with the TUI running (the recording and screenshots below show each step):

  1. Started with an empty global cli.json: default opencode theme.
  2. Added "theme": { "name": "gruvbox" }: gruvbox applied live.
  3. Removed the theme entry again: the TUI stayed on gruvbox.
  4. Ran /reload: the "Configuration reloaded" toast appeared, still gruvbox.
  5. Set "theme": { "name": "opencode" } explicitly: the default theme came back right away.

The script below reproduces it. Until it is fixed, your workaround works: set "name": "opencode" explicitly, or restart the TUI.

https://github.com/user-attachments/assets/933cfd6d-28c9-4f43-8852-b1aceacefa02

Screenshot

Screenshot

Reproduction script (drive.ts)
// Repro for anomalyco/opencode#64420: removing `theme` from cli.json does not revert to the default theme.
import { Effect } from "effect"
import { OpenCodeDriver } from "opencode-drive"
import { mkdirSync, writeFileSync } from "node:fs"
import { join } from "node:path"

// Drive points OPENCODE_CONFIG_DIR at <artifacts>/files/.opencode, so this is the global cli.json.
const write = (artifacts: string, cfg: object) =>
  Effect.sync(() => {
    const dir = join(artifacts, "files", ".opencode")
    mkdirSync(dir, { recursive: true })
    writeFileSync(join(dir, "cli.json"), JSON.stringify(cfg, null, 2) + "\n")
  })

export default OpenCodeDriver.use(
  {
    ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
    tui: { recording: true, keypressOverlay: true },
  },
  ({ ui, artifacts }) =>
    Effect.gen(function* () {
      yield* write(artifacts, {})
      yield* Effect.sleep(3000)
      yield* ui.screenshot("1-default-no-theme")

      yield* write(artifacts, { theme: { name: "gruvbox" } })
      yield* Effect.sleep(4000)
      yield* ui.screenshot("2-gruvbox-added")

      yield* write(artifacts, {})
      yield* Effect.sleep(4000)
      yield* ui.screenshot("3-theme-removed")

      yield* ui.submit("/reload")
      yield* Effect.sleep(4000)
      yield* ui.screenshot("4-after-reload")

      yield* write(artifacts, { theme: { name: "opencode" } })
      yield* Effect.sleep(4000)
      yield* ui.screenshot("5-opencode-explicit")
    }),
)

Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

opencodejr[bot] avatar Nov 17 '26 11:11 opencodejr[bot]

The reactive theme effect returns early when theme.name disappears, while provider initialization already defaults to opencode. This focused patch applies that same fallback on updates (commit 0488d1cb157b5aae85047390d9b7b6d349a1d293, based on a9a35b4).

Automated macOS validation exercises the real ConfigProvider → ThemeProvider → rendered text/color path. Both removal cases fail on the base and pass with the patch; explicit theme changes and the pinned light-mode preference are covered. All 7 tests pass across 10 runs, 122 adjacent theme/config tests pass, and root bun run check passes all 35 tasks.

The full TUI suite hits an OpenTUI runtime-plugin import stack overflow, also reproduced with both changed files restored to the base; its candidate run ended in SIGKILL. Windows-native testing and hosted CI remain unverified. PR creation is still blocked by the account's existing CreatePullRequest permission error; the branch and patch are available for review.

1052326311 avatar Nov 17 '26 12:11 1052326311