gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

CLI Crashes on Windows with ERR_ENCODING_NOT_SUPPORTED When Running Shell Commands

Open secprobe opened this issue 1 year ago โ€ข 6 comments


๐Ÿ“„ Description

The Gemini CLI consistently crashes on Windows when executing shell commands that produce output using standard, non-UTF-8 Windows console codepages (e.g., cp437 for US-English, cp850 for Western Europe/German). This makes the shell integration feature unreliable and often unusable on many Windows systems.


๐Ÿ” Steps to Reproduce

  1. Use a Windows machine. The issue is confirmed on systems using various codepages, including:

    • cp850 (German)
    • cp437 (US-English)
  2. From within the Gemini CLI, run a common shell command that produces output with any non-ASCII characters, such as:

    • Box-drawing characters (e.g., from dir)
    • Accented characters (e.g., from git log)

    Example commands:

    • dir
    • git log
    • ls -F (if using a compatible ls)

โœ… Expected Behavior

The commandโ€™s output should be successfully captured and displayed within the Gemini CLI interface.


โŒ Actual Behavior

The CLI process immediately crashes and exits, printing an error to the terminal. The specific error varies depending on the systemโ€™s language and codepage settings.


๐Ÿงพ Error Log (Example using cp850)

node:internal/encoding:409
      throw new ERR_ENCODING_NOT_SUPPORTED(encoding);
      ^

RangeError [ERR_ENCODING_NOT_SUPPORTED]: The "cp850" encoding is not supported
    at new TextDecoder (node:internal/encoding:409:15)
    at handleOutput (file:///C:/Users/Dan/AppData/Roaming/npm/node_modules/@google
      /gemini-cli/dist/src/ui/hooks/shellCommandProcessor.js:62:33)
    at Socket.<anonymous> (file:///C:/Users/Dan/AppData/Roaming/npm/node_modules/@google
      /gemini-cli/dist/src/ui/hooks/shellCommandProcessor.js:96:43)
    at Socket.emit (node:events:507:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at Pipe.onStreamRead (node:internal/stream_base_commons:189:23) {
  code: 'ERR_ENCODING_NOT_SUPPORTED'
}

๐Ÿ” Analysis

The root cause is that the TextDecoder used in shellCommandProcessor.js (Gemini CLI) does not support legacy Windows OEM codepages.

  • Shells like cmd.exe or powershell.exe pipe output using the systemโ€™s active codepage, which may be cp437, cp850, etc.
  • When the CLI attempts to decode this output, Node.js throws an exception if the encoding is unsupported.
  • This leads to an unhandled exception and process termination.

This issue appears to be the root cause of:

  • #4944
  • #4943

๐Ÿ’ก Recommendation

Implement a more robust decoding mechanism by:

  • Detecting the shell's output encoding dynamically
  • Or using a library like iconv-lite, which supports legacy encodings

This would allow converting the shell output to UTF-8 before further processing, preventing the crash and enabling full CLI functionality across Windows locales.


secprobe avatar Jul 26 '25 20:07 secprobe

Hey, thanks for filing this! Would you be able to check to see if this happens at the main branch? Or possibly even the nightly version? There were some changes made for the shell command execution that may have fixed this.

If not, I can look into it!

abhipatel12 avatar Jul 27 '25 04:07 abhipatel12

Hey, thanks for filing this! Would you be able to check to see if this happens at the main branch? Or possibly even the nightly version? There were some changes made for the shell command execution that may have fixed this.

If not, I can look into it!

Hi, thanks again for the quick fix on my previous issue regarding the cp850 encoding crash.

As you suggested, I tested the latest nightly build:

  • Version: 0.1.13-nightly.250727.3e81359c

I can confirm that the changes resolved the previous crash related to shell command output encodings. Thank you for that!

However, these changes have introduced a new rendering issue that affects native Windows console commands such as dir. The output is now visually corrupted.


๐Ÿงช Steps to Reproduce

  1. System: Run Gemini CLI on a standard Windows machine

    • Terminal: cmd.exe or PowerShell
    • Codepage: 850 (German) or 437 (US-English)
  2. Gemini Version: Use 0.1.13-nightly.250727.3e81359c or newer.

  3. Execute a native command:

    !dir
    

  1. Compare with a Unix-style command (works fine):

    !ls
    

โœ… Expected Behavior

All shell commands should render cleanly in the Gemini CLI, regardless of their origin or line endings.


โŒ Actual Behavior

  • The output of the native command !dir is corrupted โ€“ most lines are invisible or overwritten.

  • In contrast, the output of !ls is rendered correctly.

Visual Example (actual rendering):

$ dir
 โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
 โ”‚ โœ”  Shell Command dir                                                                                                         โ”‚
 โ”‚                                                                                                                              โ”‚
                                                                                          โ”‚
                                                                                             โ”‚
                                                                                                                       โ”‚
                                                                                              โ”‚
                                                                                                                       โ”‚
                                                                                      โ”‚
                                                                                     โ”‚
                                                                               โ”‚
                                                                           โ”‚
                                                                         โ”‚
                                                                          โ”‚
                                                                           โ”‚
 โ”‚        6 Verzeichnis(se), 1.311.845.785.600 Bytes frei                                                                 โ”‚
 โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

๐Ÿ” Analysis: Regression Caused by Previous Fix

This appears to be a regression introduced by changes to fix a prior bug related to ! interpretation in multiline output:

๐Ÿž Previous Bug

The CLI misinterpreted lines starting with ! as new commands.
Example:

Hello World\r\n! This is a test

โ†’ ! This is a test was wrongly treated as a command.

๐Ÿ›  Fix Implemented

The shell output parser was updated to process output line-by-line and ignore ! unless at the beginning of a new line.

๐Ÿ’ฅ New Bug (This One)

This new logic does not handle Windows-style line endings (\r\n) correctly:

  • Native commands like dir emit lines ending with \r\n.

  • The CLI appears to treat \r (Carriage Return) as-is, without removing it.

  • This causes overwriting of previously rendered lines.

๐Ÿ“Œ Confirmation

  • !dir โ†’ corrupted (\r\n line endings)

  • !ls โ†’ OK (\n line endings)


๐Ÿ’ก Recommendation

Update the Gemini CLIโ€™s shell output processor to:

  • Strip or sanitize carriage return characters (\r) from all lines before rendering

  • This ensures compatibility with native Windows commands while retaining the fix for ! interpretation


โ„น๏ธ System Details

Component Value
OS Windows 10 (22H2)
Terminal cmd.exe, PowerShell, or Windows Terminal
Codepage 850 (German), 437 (US-English)
Gemini CLI 0.1.13-nightly.250727.3e81359c

Thanks for investigating this regression and for your continued work on improving Gemini CLI!

secprobe avatar Jul 27 '25 17:07 secprobe

I have the same issues. I upgraded the version of Gemini CLI with no fix. It does not crash for me rather everything will keep spinning until I Ctrl+C x2 to quit the gemini cli. I get the same experience whether I use an Admin Pshell, CMD, VScode Terminal. Even asking to not using shell mode will not resolve.

Thanks for looking into this!

Sneed-Carl avatar Jul 30 '25 21:07 Sneed-Carl

This output being corrupted is likely not a windows issue or a encoding issue. that is probably due to control characters in the terminal output not being handled correctly. The most robust solution for this would be to use the https://www.npmjs.com/package/@xterm/headless package. This would also be a helpful step towards https://github.com/google-gemini/gemini-cli/issues/5132

jacob314 avatar Jul 31 '25 19:07 jacob314

Hi @secprobe , I am not able to reproduce the issue, I tried executing dir command in gemini on a directory which had non-utf8 but did not face any issues. Attaching a screenshot for you reference. If you are still facing the issue can you please provide a screenshot of the directory, want want to see which non-utf8 characters could be causing the issue.

Image

Thanks

gsehgal avatar Oct 12 '25 11:10 gsehgal

Hi @secprobe , I am closing the issue as of now, please re-open it if you are still facing the issue.

gsehgal avatar Oct 13 '25 00:10 gsehgal