Fix CJK character display issues in Windows terminals #7503

Open
opened 2026-02-16 18:07:22 -05:00 by yindo · 1 comment
Owner

Originally created by @Observer-GGboy on GitHub (Jan 25, 2026).

Originally assigned to: @rekram1-node on GitHub.

Problem

OpenCode terminals on Windows do not properly display CJK (Chinese, Japanese, Korean) characters. Instead, they appear as gibberish, question marks, or cause encoding errors.

Affected Scenarios

  1. Terminal Output

    $ echo "你好世界"
    ?????
    
  2. Python Scripts

    $ python -c "print('你好')"
    UnicodeEncodeError: 'ascii' codec can't encode characters
    
  3. Git Operations

    $ git status
    ?? "\346\226\346\231\230.md"
    

Root Cause

Windows historically uses GBK/GB2312 encoding by default, not UTF-8. This causes issues when:

  • Terminal code page is not set to UTF-8 (CP65001)
  • Environment variables (LANG, LC_ALL) are not configured
  • Python's UTF-8 mode is not enabled
  • Shell encoding (PowerShell/CMD) is not configured

Proposed Solution

Add platform-specific UTF-8 defaults for Windows PTY (pseudo-terminal) creation:

  1. Environment Variables

    • Set LANG=en_US.UTF-8
    • Set LC_ALL=en_US.UTF-8
    • Set PYTHONUTF8=1 (Python 3.7+)
    • Set PYTHONIOENCODING=utf-8
  2. Shell Startup Arguments

    • CMD.exe: Run chcp 65001 to set code page to UTF-8
    • PowerShell: Configure OutputEncoding and InputEncoding to UTF-8

Impact

  • Target Platform: Windows only (no impact on macOS/Linux)
  • User-Visible: Yes (fixes CJK character display)
  • Backwards Compatible: Yes (only sets defaults, users can override via env parameter)

Related

Originally created by @Observer-GGboy on GitHub (Jan 25, 2026). Originally assigned to: @rekram1-node on GitHub. ## Problem OpenCode terminals on Windows do not properly display CJK (Chinese, Japanese, Korean) characters. Instead, they appear as gibberish, question marks, or cause encoding errors. ### Affected Scenarios 1. **Terminal Output** ``` $ echo "你好世界" ????? ``` 2. **Python Scripts** ``` $ python -c "print('你好')" UnicodeEncodeError: 'ascii' codec can't encode characters ``` 3. **Git Operations** ``` $ git status ?? "\346\226\346\231\230.md" ``` ### Root Cause Windows historically uses GBK/GB2312 encoding by default, not UTF-8. This causes issues when: - Terminal code page is not set to UTF-8 (CP65001) - Environment variables (LANG, LC_ALL) are not configured - Python's UTF-8 mode is not enabled - Shell encoding (PowerShell/CMD) is not configured ## Proposed Solution Add platform-specific UTF-8 defaults for Windows PTY (pseudo-terminal) creation: 1. **Environment Variables** - Set `LANG=en_US.UTF-8` - Set `LC_ALL=en_US.UTF-8` - Set `PYTHONUTF8=1` (Python 3.7+) - Set `PYTHONIOENCODING=utf-8` 2. **Shell Startup Arguments** - **CMD.exe**: Run `chcp 65001` to set code page to UTF-8 - **PowerShell**: Configure OutputEncoding and InputEncoding to UTF-8 ## Impact - **Target Platform**: Windows only (no impact on macOS/Linux) - **User-Visible**: Yes (fixes CJK character display) - **Backwards Compatible**: Yes (only sets defaults, users can override via env parameter) ## Related - PR: #10489
yindo added the windows label 2026-02-16 18:07:22 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 25, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #10414: OpenCode crashes during use on Windows (garbled console output) - Similar garbled output on Windows
  • #10486: Chinese Characters - CJK characters appearing unexpectedly in output
  • #9814: Garbled characters appear after launching the program on Windows system
  • #10265: Ctrl+C during response causes terminal to print endless garbage and become unresponsive - Related terminal encoding issue
  • #10341: Scoop-fixes-opencode-windows-x64-garbled-output-issue-but-cause-unknown - Windows-specific garbled output issue
  • #9793: 命令行模式下中文显示突然全部变成乱码 (Chinese characters display as garbled in CLI mode) - CJK display issue on Windows
  • #10210: Undo/revert fails for files with non-ASCII filenames on Windows - Related non-ASCII handling issue

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Jan 25, 2026): This issue might be a duplicate of existing issues. Please check: - #10414: OpenCode crashes during use on Windows (garbled console output) - Similar garbled output on Windows - #10486: Chinese Characters - CJK characters appearing unexpectedly in output - #9814: Garbled characters appear after launching the program on Windows system - #10265: Ctrl+C during response causes terminal to print endless garbage and become unresponsive - Related terminal encoding issue - #10341: Scoop-fixes-opencode-windows-x64-garbled-output-issue-but-cause-unknown - Windows-specific garbled output issue - #9793: 命令行模式下中文显示突然全部变成乱码 (Chinese characters display as garbled in CLI mode) - CJK display issue on Windows - #10210: Undo/revert fails for files with non-ASCII filenames on Windows - Related non-ASCII handling issue Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7503