Skip to content

Windows CJK characters garbled in bash tool output #24080

Closed

Description

@fkyah3

Summary

On Windows with CJK locales (zh-CN, ja-JP, ko-KR), the bash tool spawns child processes that inherit the system default code page (e.g. 936 GBK) instead of UTF-8. The parent process may have chcp 65001 set, but it is NOT inherited by spawned child processes. This causes non-ASCII output to be encoded in the system ANSI encoding while OpenCode reads it as UTF-8, producing garbled text.

Changes

One file: packages/opencode/src/tool/bash.ts, in the cmd() function.

PowerShell branch: Adds chcp 65001, [Console]::OutputEncoding, and $OutputEncoding — all three are needed because:

Setting Scope
chcp 65001 Console code page
[Console]::OutputEncoding .NET output encoding
$OutputEncoding PowerShell pipeline encoding

cmd.exe branch: chcp 65001 alone is sufficient (no .NET encoding layer).

Reproducing

On a Chinese/Japanese/Korean Windows system:

# Without fix: garbled output
Write-Output "你好世界"
# outputs garbled text like "ä½ å¥½ä¸ç\U+fffd\U+fffd"

# With fix: correct output
Write-Output "你好世界"
# outputs "你好世界"

Testing

  • A single file change in cmd() function
  • Win32-only code path, does not affect macOS/Linux
  • Only modifies the spawned command prefix, does not change tool behavior

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 24, 2026
  2. github-actions commented on Apr 24, 2026

    @github-actions
    Contributor

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

    Please review these issues before proceeding, as your report covers the same problem and proposed fix as #23636 in particular.

  3. fkyah3 commented on Apr 24, 2026

    @fkyah3
    Author

    Duplicate of #23636. The fix is already implemented and tested on my fork — I added a comment on that issue with the complete implementation details including the cmd.exe branch fix that the original proposal missed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions