Skip to content

fix: CJK characters garbled in TUI on Windows with non-UTF8 locale #14768

Closed as not planned

Description

@Xio-Shark

Bug description

On Windows systems with Chinese/Japanese/Korean locales, CJK characters (中文、日本語、한국어) appear garbled in the OpenCode TUI input box. This happens because Windows console defaults to local code pages (e.g., GBK 936 for Chinese Windows) instead of UTF-8.

Reproduction

  1. Use Windows with Chinese locale (or any non-UTF-8 locale)
  2. Run opencode in terminal
  3. Try typing CJK characters in the TUI input box
  4. Observe garbled text or unexpected character insertion

Expected behavior

CJK characters should display correctly as UTF-8 in the TUI input box.

Environment

  • OS: Windows 10/11
  • Locale: zh-CN, ja-JP, ko-KR
  • OpenCode version: latest

Root cause

Windows console code page is not set to UTF-8 (65001) before TUI initialization. The console uses the system's default code page (e.g., 936 for Chinese GBK), causing UTF-8 encoded CJK characters to be misinterpreted.

Proposed fix

Call SetConsoleCP(CP_UTF8) and SetConsoleOutputCP(CP_UTF8) Windows API functions in win32.ts and invoke them in TUI entry points (thread.ts and attach.ts).

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Feb 23, 2026
  2. github-actions commented on Feb 23, 2026

    @github-actions
    Contributor

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

    Please review the above issues to see if your problem is already tracked. If your issue is distinct (specifically about the SetConsoleCP/SetConsoleOutputCP fix not being applied at TUI initialization), feel free to clarify how it differs.

  3. skywalker-35 commented on Mar 27, 2026

    @skywalker-35

    I'm helping with downstream documentation for the encoding issue. Any updates on the proposed fix (SetConsoleCP/OutputCP)?

  4. PhoenixZeng commented on Apr 20, 2026

    @PhoenixZeng

    opencode app也有类似的问题 表现于在 执行shell命令的回显上 其他地方倒是能正常显示 (那也只是因为代码文件通常用utf8编写 如果是非UTF8的特殊脚本应该也不可以)

  5. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on May 3, 2026
  6. github-actions commented on Jul 4, 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