gemini-cli - 💡(How to fix) Fix run_shell_command continuously garbles UTF-8 stdout on systems with non-UTF8 ANSI code pages (e.g., CP936)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

Root Cause Analysis: The CLI relies on powershell.exe -NoProfile -Command as the default wrapper and relies on Node's child_process.exec or spawn without explicitly setting the { encoding: 'utf8' } parameter for the stdout stream capture, or it fails to synchronize the chcp 65001 code page with the Node.js stream decoder.

RAW_BUFFERClick to expand / collapse

What happened?


标题: [Windows] run_shell_command continuously garbles UTF-8 stdout on systems with non-UTF8 ANSI code pages (e.g., CP936)

Environment:

  • OS: Windows 10/11 (with Chinese localization, System Locale CP936/GBK)
  • Gemini CLI Version: 0.42.0 (and previous versions)
  • Node.js Environment: Standard Windows Node.js implementation

Issue Description: The run_shell_command tool in Gemini CLI consistently fails to properly decode UTF-8 stdout from child processes on Windows systems where the active code page is not 65001. When executing commands (even pwsh, python, or node) that correctly output UTF-8 text, the CLI captures the byte stream and decodes it using the system's default ANSI code page (e.g., CP936/GBK) instead of UTF-8. This results in severe "mojibake" (garbled text) being passed back to the LLM context and printed to the user's console.

Steps to Reproduce:

  1. On a Windows machine with a Chinese locale (CP936 code page default).
  2. Ensure a text file containing UTF-8 Chinese characters exists (e.g., test.md).
  3. Ask the agent to read the file using run_shell_command: run_shell_command(command="node -e "console.log(require('fs').readFileSync('test.md', 'utf8'))"")
  4. The output returned to the context and terminal is severely garbled, double-decoded garbage.

Root Cause Analysis: The CLI relies on powershell.exe -NoProfile -Command as the default wrapper and relies on Node's child_process.exec or spawn without explicitly setting the { encoding: 'utf8' } parameter for the stdout stream capture, or it fails to synchronize the chcp 65001 code page with the Node.js stream decoder.

Impact:

  • AI agents hallucinate or fail tasks because the context is filled with garbled text.
  • Users cannot trust the terminal output when the agent verifies files.
  • Forces the adoption of strict memory rules to avoid run_shell_command for file reading, crippling the agent's utility for complex grep or shell tasks.

Suggested Fix: Ensure that the Node.js process capturing the shell output explicitly forces UTF-8 decoding for stdout/stderr streams, regardless of the underlying Windows ANSI code page, and consider wrapping the default Windows shell call in a code page override (e.g., configuring [Console]::OutputEncoding). [ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.

What did you expect to happen?

修复该问题,以gemini cli 正确显示中文输出。

Client information

  • CLI Version: 0.42.0
  • Git Commit: 68e2196d5
  • Session ID: b1622858-6396-4229-bd65-0729f2e2c9b5
  • Operating System: win32 v24.15.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: gemini-api-key
  • Memory Usage: 285.7 MB
  • Terminal Name: Unknown
  • Terminal Background: #1e1e1e
  • Kitty Keyboard Protocol: Supported

Login information

No response

Anything else we need to know?

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING