Skip to content

fix(cli): resolve autoThemeSwitching when background hasn't changed but theme mismatches#20706

Merged
sehoon38 merged 1 commit intomainfrom
fix-auto-theme-switching
Feb 28, 2026
Merged

fix(cli): resolve autoThemeSwitching when background hasn't changed but theme mismatches#20706
sehoon38 merged 1 commit intomainfrom
fix-auto-theme-switching

Conversation

@sehoon38
Copy link
Contributor

Summary

Fixes an issue where autoThemeSwitching would not work if the terminal background color hadn't changed since the application started, but the active theme was mismatched (e.g. a Light theme on a Dark background).
The bug was caused by an early return inside handleTerminalBackground that bypassed the theme-switching logic when previousColor === hexColor.

Details

Moved the logic for evaluating the theme (getLuminance, shouldSwitchTheme) to happen before the early return check, so the theme matching logic still runs and correctly applies the theme even when the background hasn't changed.
Included a new unit test in useTerminalTheme.test.tsx to explicitly verify this edge-case behavior.

Related Issues

Fixes #20705

How to Validate

  1. Open Gemini CLI in a terminal with a dark background but with your ui.theme set to default-light (and autoThemeSwitching enabled).
  2. Start the CLI. Wait for the terminalBackgroundPollingInterval (default 60s).
  3. Observe that the theme now correctly switches to the default dark theme, instead of remaining permanently stuck on light.

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@sehoon38 sehoon38 requested a review from a team as a code owner February 28, 2026 20:34
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a bug in the autoThemeSwitching feature of the Gemini CLI. Previously, the system would fail to switch themes if the terminal's background color hadn't changed since startup, even if the current theme was inappropriate for the background (e.g., a light theme on a dark background). The changes ensure that theme matching logic is always executed, allowing the CLI to correctly apply the appropriate theme based on the terminal's luminance, thereby improving user experience and consistency.

Highlights

  • autoThemeSwitching fix: Resolved an issue where autoThemeSwitching failed to apply the correct theme when the terminal background color remained unchanged but the active theme was mismatched.
  • Logic reordering: Reordered the theme evaluation logic (getLuminance, shouldSwitchTheme) to execute before the early return check in handleTerminalBackground, ensuring theme matching runs regardless of background color changes.
  • Test coverage: Introduced a new unit test to specifically validate the corrected behavior for the autoThemeSwitching edge case.
Changelog
  • packages/cli/src/ui/hooks/useTerminalTheme.test.tsx
    • Added a new test case to verify theme switching when the terminal background is identical but the current theme is mismatched.
  • packages/cli/src/ui/hooks/useTerminalTheme.ts
    • Moved the getLuminance and shouldSwitchTheme calls to occur earlier in the handleTerminalBackground function.
    • Modified the early return condition to allow theme selection to proceed if a new theme is determined, even if the terminal background color has not changed.
    • Relocated the config.setTerminalBackground and themeManager.setTerminalBackground calls to execute only when the background color actually changes.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly resolves an issue where automatic theme switching would fail if the terminal background color hadn't changed, but the theme was mismatched. The fix is well-implemented and is accompanied by a new unit test that specifically validates this edge case. The suggested refactoring for improved conciseness and maintainability has been retained as it aligns with general best practices.

@github-actions
Copy link

Size Change: +95 B (0%)

Total Size: 25.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 25.3 MB +95 B (0%)
./bundle/node_modules/@google/gemini-cli-devtools/dist/client/main.js 221 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/_client-assets.js 227 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/index.js 11.5 kB 0 B
./bundle/node_modules/@google/gemini-cli-devtools/dist/src/types.js 132 B 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 28, 2026
@sehoon38 sehoon38 added this pull request to the merge queue Feb 28, 2026
Merged via the queue into main with commit 6757d4b Feb 28, 2026
30 checks passed
@sehoon38 sehoon38 deleted the fix-auto-theme-switching branch February 28, 2026 23:35
BryanBradfo pushed a commit to BryanBradfo/gemini-cli that referenced this pull request Mar 5, 2026
liamhelmer pushed a commit to badal-io/gemini-cli that referenced this pull request Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix autoThemeSwitching when terminal background color hasn't changed but theme is mismatched

2 participants