Skip to content

Windows: bash tool cannot correctly handle cmd.exe GBK output #26882

Closed as not planned

Description

@moyaspace

Bug Report: Windows cmd.exe GBK output displayed as garbled text in bash tool

Bug Description:
When executing Windows native commands (via cmd /c) or system utilities like ipconfig in OpenCode's bash tool on Windows, Chinese characters are displayed as garbled text (mojibake) instead of proper Chinese text.

Steps to Reproduce:

  1. Open OpenCode on Windows 11
  2. Execute the following command in the bash tool:
    cmd /c "echo Windows IP 配置"
  3. Observe the output shows garbled characters instead of proper Chinese text

Expected Behavior:
Chinese characters should be displayed correctly.

Actual Behavior:
Chinese characters are displayed as garbled text (mojibake), indicating encoding mismatch.

Technical Details:

The same command works correctly when executed directly in pwsh 7.6.1 terminal, but fails in OpenCode's bash tool:

Environment Command Result
pwsh terminal cmd /c "echo Windows IP 配置" ✅ Correct
OpenCode bash tool cmd /c "echo Windows IP 配置" ❌ Garbled
OpenCode bash tool ipconfig ❌ Garbled

Raw byte analysis confirms ipconfig outputs GBK (CP936) encoding, which is standard for Windows system commands.

Root Cause:
OpenCode's bash tool captures cmd.exe output as raw bytes but processes them with incorrect encoding assumption (expecting UTF-8 instead of detecting GBK). PowerShell 7 correctly uses UTF-8 internally, but the OpenCode rendering layer fails to transcode the GBK output from native Windows commands.

Environment:

  • OpenCode: 1.14.48
  • Windows: 11
  • PowerShell: 7.6.1
  • Shell: PowerShell 7 (confirmed via $PSVersionTable.PSVersion)

Additional Context:

  • PowerShell native commands output correctly (e.g., Get-NetIPAddress)
  • Only Windows native commands (.exe files like ipconfig.exe, cmd.exe) have this issue
  • The problem occurs even when PowerShell 7's encoding is set to UTF-8
  • File redirection with GBK decoding works: [System.Text.Encoding]::GetEncoding(936).GetString([System.IO.File]::ReadAllBytes("file")) correctly displays Chinese

Suggested Fix:
Implement encoding detection or transcoding for Windows native command output in the bash tool, or add a configuration option to specify the console output encoding (GBK/CP936 for Windows).

Activity

  1. github-actions commented on May 11, 2026

    @github-actions
    Contributor

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

  2. github-actions commented on Jul 11, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions