Skip to content

[BUG] Windows: text files in system code page encoding (GBK/Shift-JIS) produce garbled output when read as UTF-8 #31765

Closed

Description

Description

On non-English Windows systems, text files (including AGENTS.md) may be saved in the system's active code page encoding (e.g., GBK for Chinese, Shift-JIS for Japanese) instead of UTF-8. The fs.readFileString() function always decodes as UTF-8, producing garbled characters (mojibake) for non-UTF-8 files.

Affected code

packages/core/src/fs-util.ts - the readFileString method delegates to the platform's fs.readFileString() which assumes UTF-8.

Also packages/opencode/src/session/instruction.ts:91 - the read helper used to load AGENTS.md uses fs.readFileString(filepath).

Impact

  • Users who create AGENTS.md using Windows Notepad (which defaults to ANSI/GBK encoding on Chinese Windows) will see garbled text
  • CI/test files saved in non-UTF-8 encodings will produce corrupted output
  • This affects all file reading, not just instruction files

Suggested fix

Read the file as raw bytes, attempt UTF-8 decoding first, and if replacement characters (U+FFFD) are present, fall back to the system's active code page encoding detected via chcp.com.

Steps to reproduce

  1. On a Chinese Windows system (code page 936)
  2. Create a file with Chinese text using Notepad (saves as GBK by default)
  3. fs.readFileString() decodes GBK bytes as UTF-8, producing garbled text like ���IJ���

OpenCode version

1.17.3

Operating System

Windows 11 (zh-CN)

Activity

  1. github-actions commented on Jun 10, 2026

    @github-actions
    Contributor

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

    If your issue is distinct from these, please clarify what is different so maintainers can keep it open.

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