CLI Crashes on Windows with ERR_ENCODING_NOT_SUPPORTED When Running Shell Commands
๐ 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
-
Use a Windows machine. The issue is confirmed on systems using various codepages, including:
cp850(German)cp437(US-English)
-
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:
dirgit logls -F(if using a compatiblels)
- Box-drawing characters (e.g., from
โ 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.exeorpowershell.exepipe output using the systemโs active codepage, which may becp437,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.
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!
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
-
System: Run Gemini CLI on a standard Windows machine
- Terminal:
cmd.exeorPowerShell - Codepage: 850 (German) or 437 (US-English)
- Terminal:
-
Gemini Version: Use
0.1.13-nightly.250727.3e81359cor newer. -
Execute a native command:
!dir
-
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
!diris corrupted โ most lines are invisible or overwritten. -
In contrast, the output of
!lsis 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
diremit 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\nline endings) -
!lsโ OK (\nline 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!
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!
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
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.
Thanks
Hi @secprobe , I am closing the issue as of now, please re-open it if you are still facing the issue.