Skip to content

fix(cli): skip console log/info in headless mode#22739

Merged
cynthialong0-0 merged 26 commits intomainfrom
fix/headless-log
Mar 25, 2026
Merged

fix(cli): skip console log/info in headless mode#22739
cynthialong0-0 merged 26 commits intomainfrom
fix/headless-log

Conversation

@cynthialong0-0
Copy link
Copy Markdown
Contributor

@cynthialong0-0 cynthialong0-0 commented Mar 16, 2026

Summary

Skip output in headless mode to avoid polluting the terminal with raw console logs and info, unless debug mode is enabled.

Details

  • Introduced headlessMode parameter to ConsolePatcher.
  • When headlessMode is true and debugMode is false, ConsolePatcher will skip printing to the original console for type 'info' and 'log'.
  • Enabled headlessMode in nonInteractiveCli.ts and conditionally in gemini.tsx based on isHeadlessMode().
  • Added unit tests for ConsolePatcher to prevent regression.
  • Update extenions-install e2e test to add -debug to match expected text since in integration test it automatically treat it as headless

Related Issues

Fixes #22168

How to Validate

  1. Run CLI in headless mode and verify no console logs are printed unless --debug is used.
npm run start -- -p "Hello there"

> @google/gemini-cli@0.35.0-nightly.20260313.bb060d7a9 start
> cross-env NODE_ENV=development node scripts/start.js -p Hello there

Checking build status...
Build is up-to-date.
Hello! I'm Gemini CLI, your autonomous AI partner. How can I help you with your project today?

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
    • Windows
    • Linux
      • npm run

@cynthialong0-0 cynthialong0-0 requested a review from a team as a code owner March 16, 2026 21:53
@gemini-code-assist
Copy link
Copy Markdown
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 aims to prevent unnecessary console output from polluting the terminal when the CLI is run in headless mode. By introducing a new suppression mechanism in the ConsolePatcher, the application will now only display raw console logs if debug mode is explicitly enabled, leading to a cleaner user experience for non-interactive operations.

Highlights

  • Console Output Suppression: Introduced a suppressConsoleOutput parameter to the ConsolePatcher class, allowing for conditional suppression of console logs.
  • Conditional Logging Logic: Implemented logic within ConsolePatcher to prevent console output when suppressConsoleOutput is enabled and debugMode is disabled.
  • CLI Integration: Configured the CLI's gemini.tsx and nonInteractiveCli.ts to utilize this new suppression feature, specifically in headless modes.
  • Testing: Added comprehensive unit tests for ConsolePatcher and nonInteractiveCli to validate the new console output behavior.
Changelog
  • packages/cli/src/gemini.tsx
    • Imported isHeadlessMode utility.
    • Configured ConsolePatcher to conditionally suppress console output based on whether the application is running in headless mode.
  • packages/cli/src/nonInteractiveCli.test.ts
    • Added a new test case to ensure ConsolePatcher is correctly initialized within the non-interactive CLI.
    • Updated existing test configurations to explicitly set debugMode for specific scenarios.
  • packages/cli/src/nonInteractiveCli.ts
    • Enabled console output suppression by default for the ConsolePatcher in non-interactive CLI operations.
  • packages/cli/src/ui/utils/ConsolePatcher.test.ts
    • Added a new test file dedicated to ConsolePatcher.
    • Included tests to verify the suppression logic under various debugMode and suppressConsoleOutput conditions.
  • packages/cli/src/ui/utils/ConsolePatcher.ts
    • Extended ConsolePatcherParams with an optional suppressConsoleOutput boolean property.
    • Modified the patchConsoleMethod to return early, effectively suppressing output, if suppressConsoleOutput is true and debugMode is false.
Activity
  • Updated relevant documentation and README (if needed).
  • Added/updated tests (if needed).
  • Validated on Linux.
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
Copy Markdown
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 introduces a mechanism to suppress console output in headless modes, which is a good improvement for non-interactive use cases. The implementation is straightforward, adding a suppressConsoleOutput flag to ConsolePatcher and applying it in both interactive and non-interactive entry points. The changes are accompanied by new unit tests. I've found one issue in the new tests that should be addressed to ensure they correctly validate the new behavior.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

Size Change: +161 B (0%)

Total Size: 26.2 MB

Filename Size Change
./bundle/chunk-3EBZQUWF.js 0 B -3.4 kB (removed) 🏆
./bundle/chunk-J62W2CY2.js 0 B -14.6 MB (removed) 🏆
./bundle/chunk-SPQGM7WQ.js 0 B -3.64 MB (removed) 🏆
./bundle/core-QOQXIKZ3.js 0 B -43.4 kB (removed) 🏆
./bundle/devtoolsService-FPRO3DVZ.js 0 B -27.7 kB (removed) 🏆
./bundle/gemini-O3ISHK2A.js 0 B -521 kB (removed) 🏆
./bundle/interactiveCli-CT5XPBWF.js 0 B -1.62 MB (removed) 🏆
./bundle/oauth2-provider-A3YOST6V.js 0 B -9.16 kB (removed) 🏆
./bundle/chunk-CFQV3USK.js 14.6 MB +14.6 MB (new file) 🆕
./bundle/chunk-PN7NQLUS.js 3.4 kB +3.4 kB (new file) 🆕
./bundle/chunk-XPPJSF4Z.js 3.64 MB +3.64 MB (new file) 🆕
./bundle/core-3X266CQA.js 43.4 kB +43.4 kB (new file) 🆕
./bundle/devtoolsService-H4BX64P7.js 27.7 kB +27.7 kB (new file) 🆕
./bundle/gemini-UJYJTYQW.js 521 kB +521 kB (new file) 🆕
./bundle/interactiveCli-FGRCQEIH.js 1.62 MB +1.62 MB (new file) 🆕
./bundle/oauth2-provider-PMSNL57F.js 9.16 kB +9.16 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size Change
./bundle/chunk-34MYV7JD.js 2.45 kB 0 B
./bundle/chunk-5AUYMPVF.js 858 B 0 B
./bundle/chunk-664ZODQF.js 124 kB 0 B
./bundle/chunk-DAHVX5MI.js 206 kB 0 B
./bundle/chunk-IUUIT4SU.js 56.5 kB 0 B
./bundle/chunk-PVQN7ZVP.js 1.96 MB 0 B
./bundle/chunk-RJTRUG2J.js 39.8 kB 0 B
./bundle/cleanup-M32IKNW4.js 0 B -856 B (removed) 🏆
./bundle/devtools-36NN55EP.js 696 kB 0 B
./bundle/dist-T73EYRDX.js 356 B 0 B
./bundle/gemini.js 2.06 kB 0 B
./bundle/getMachineId-bsd-TXG52NKR.js 1.55 kB 0 B
./bundle/getMachineId-darwin-7OE4DDZ6.js 1.55 kB 0 B
./bundle/getMachineId-linux-SHIFKOOX.js 1.34 kB 0 B
./bundle/getMachineId-unsupported-5U5DOEYY.js 1.06 kB 0 B
./bundle/getMachineId-win-6KLLGOI4.js 1.72 kB 0 B
./bundle/memoryDiscovery-WPGC7DAZ.js 922 B 0 B
./bundle/multipart-parser-KPBZEGQU.js 11.7 kB 0 B
./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
./bundle/src-QVCVGIUX.js 47 kB 0 B
./bundle/tree-sitter-7U6MW5PS.js 274 kB 0 B
./bundle/tree-sitter-bash-34ZGLXVX.js 1.84 MB 0 B
./bundle/cleanup-ZVPG3PJP.js 856 B +856 B (new file) 🆕

compressed-size-action

@gemini-cli gemini-cli bot added area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Mar 16, 2026
@cynthialong0-0 cynthialong0-0 changed the title fix(cli): suppress console output in headless modes fix(cli): skip console log/info in headless modes Mar 17, 2026
@cynthialong0-0 cynthialong0-0 changed the title fix(cli): skip console log/info in headless modes fix(cli): skip console log/info in headless mode Mar 17, 2026
Copy link
Copy Markdown
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 introduces a headlessMode to the ConsolePatcher utility, which suppresses console.log and console.info messages when active and not in debug mode. The main CLI entry point (gemini.tsx) now dynamically enables this mode based on isHeadlessMode(), while the non-interactive CLI (nonInteractiveCli.ts) always sets headlessMode: true. Corresponding integration tests and non-interactive CLI tests are updated to run in debug mode to ensure visibility of logs. A new comprehensive test file (ConsolePatcher.test.ts) has been added to validate the behavior of ConsolePatcher with the new headlessMode and existing stderr and debugMode parameters.

@cynthialong0-0 cynthialong0-0 marked this pull request as ready for review March 17, 2026 16:51
Copy link
Copy Markdown
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

The pull request introduces a headlessMode parameter to the ConsolePatcher to control console output, specifically to suppress log and info messages when in headless mode and not in debug mode. This involved adding a new test file for ConsolePatcher, importing isHeadlessMode in gemini.tsx, and configuring ConsolePatcher with headlessMode in gemini.tsx and nonInteractiveCli.ts, along with adding --debug flags to integration tests and updating mock configurations. However, a critical issue was identified in gemini.tsx where the ConsolePatcher is incorrectly configured with stderr: true unconditionally, which would prevent console logs from reaching the UI's debug console. The reviewer suggests making stderr conditional based on isHeadlessMode() and simplifying the headlessMode assignment.

@cynthialong0-0 cynthialong0-0 requested a review from jerop March 23, 2026 15:07
Copy link
Copy Markdown
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

LGTM ✅

Tested and works 😄

@cynthialong0-0 cynthialong0-0 added this pull request to the merge queue Mar 24, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 24, 2026
@cynthialong0-0 cynthialong0-0 added this pull request to the merge queue Mar 24, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 24, 2026
@cynthialong0-0 cynthialong0-0 added this pull request to the merge queue Mar 24, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 24, 2026
@cynthialong0-0 cynthialong0-0 added this pull request to the merge queue Mar 25, 2026
Merged via the queue into main with commit 5e186bf Mar 25, 2026
27 checks passed
@cynthialong0-0 cynthialong0-0 deleted the fix/headless-log branch March 25, 2026 14:04
ProthamD pushed a commit to ProthamD/gemini-cli that referenced this pull request Mar 29, 2026
afanty2021 pushed a commit to afanty2021/gemini-cli that referenced this pull request Apr 4, 2026
warrenzhu25 pushed a commit to warrenzhu25/gemini-cli that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/non-interactive Issues related to GitHub Actions, SDK, 3P Integrations, Shell Scripting, Command line automation 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Headless mode is too verbose

3 participants