Skip to content

Windows: opencode fails in non-ASCII (Chinese) directory with invalid x-opencode-directory header #13023

Closed

Description

@baodexiang

Environment: opencode 1.1.55 on Windows (PowerShell), locale zh-CN, working directory C:\Users\baode\OneDrive\桌面. Repro steps: (1) cd C:\Users\baode\OneDrive\桌面 (2) run opencode. Actual result: startup fails with TypeError: Header 'x-opencode-directory' has invalid value containing Chinese path characters. Expected result: opencode should start normally in Unicode/non-ASCII paths. Workaround: running from ASCII-only path works (for example C:\work\test).

Activity

  1. baodexiang commented on Feb 10, 2026

    @baodexiang
    Author

    Additional details from reproduction (PowerShell in Chinese path):\n\n\n\nASCII path workaround still works.

  2. baodexiang commented on Feb 10, 2026

    @baodexiang
    Author

    Corrected stack trace from reproduction:

    UnknownError
    TypeError: Header x-opencode-directory has invalid value: C:\Users�aode\OneDrive\桌面
    at set (unknown)
    at mergeHeaders (../sdk/js/src/gen/client/utils.gen.ts:184:23)
    at mergeConfigs (../sdk/js/src/gen/client/utils.gen.ts:161:20)
    at createClient (../sdk/js/src/gen/client/client.gen.ts:21:17)
    at createOpencodeClient (../sdk/js/src/client.ts:28:18)
    at (src/plugin/index.ts:25:20)
    at (src/project/state.ts:22:21)
    at init2 (src/plugin/index.ts:123:25)
    at InstanceBootstrap (src/project/bootstrap.ts:19:16)
    at (src/project/instance.ts:34:23)
    at async provide (src/project/instance.ts:40:23)

    ASCII path workaround still works.

  3. github-actions commented on Feb 10, 2026

    @github-actions
    Contributor

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

    All three issues involve non-ASCII character handling on Windows. This issue specifically mentions the x-opencode-directory header, which provides additional specificity about the root cause. You may want to consolidate these issues or check if one of the existing issues has already been fixed or is being actively worked on.

  4. baodexiang commented on Feb 10, 2026

    @baodexiang
    Author

    Path value correction (literal): 'C:\Users\baode\OneDrive\桌面'

  5. KolbyML commented on Feb 11, 2026

    @KolbyML

    I get this bug too, but in linux with japanese text

  6. canyue7897 commented on Feb 11, 2026

    @canyue7897

    同样问题,gemini cli已经修复:
    gemini cli给出的意见:
    结论完全反转:这不是你的路径问题,是 OpenCode 1.1.55 的回归 Bug
    铁证
    我刚才用你机器上保留的旧版本 1.1.53 在 完全相同的中文路径 下启动:
    "C:\Scoop\apps\opencode\1.1.53\opencode.exe"

    工作目录: D:\python\控制

    结果:完美启动,TUI 正常渲染,状态栏正确显示 D:\python\控制:win7-legacy,MCP 服务连接正常。
    时间线还原

    时间 事件 中文路径支持
    之前 OpenCode 1.1.53 ✅ 正常工作
    2026-02-11 05:41 scoop 自动更新到 1.1.55 ❌ 崩溃
    今早 你发现启动失败 —
    根因:OpenCode 1.1.55 的 SDK 客户端代码(sdk/js/src/gen/client/utils.gen.ts)中 mergeHeaders 函数新增或修改了 HTTP Header 值的校验逻辑,对 x-opencode-directory 这个 Header 启用了严格的 ASCII-only 校验,导致包含中文的路径被拒绝。这是 1.1.55 引入的回归 Bug,不是你的项目问题。

    立即修复:回滚到 1.1.53
    scoop reset [email protected]
    这会将 current 符号链接重新指向 1.1.53 目录,零数据丢失、零配置变更。
    如果你想锁定版本防止再次被自动更新覆盖:
    scoop hold opencode
    之后手动升级时用 scoop unhold opencode && scoop update opencode。
    gemini cli解决方法:
    修复完成。以下是完整状态总结:

    修复摘要
    根因
    OpenCode 1.1.55 的 v1 SDK 客户端(sdk/js/src/client.ts)在设置 x-opencode-directory HTTP Header 时未对非 ASCII 字符编码,而 1.1.55 内嵌的 Bun 运行时对 Header 值启用了严格的 ASCII-only 校验,导致中文路径崩溃。
    补丁内容
    在二进制中定位并修补了两处 v1 客户端代码(config5 @ 0x7317C8C,config4 @ 0x8459C03),将:
    "x-opencode-directory": config5.directory
    替换为:
    "x-opencode-directory": encodeURIComponent(config5.directory)
    等长替换(134 字节 → 134 字节),零偏移量变动。
    文件状态

    文件 说明
    opencode.exe 当前被进程锁定(未修改)
    opencode.exe.bak 原始备份
    opencode_patched.exe 已修补的版本
    apply_patch.cmd 替换脚本
    下一步
    1. 关闭当前 OpenCode(Ctrl+C 或退出 TUI)
    2. 运行替换脚本:
      C:\Scoop\apps\opencode\1.1.55\apply_patch.cmd
      3. 在中文路径下重新启动 OpenCode 验证修复
      ⚠ 已知局限
    3. 数字签名失效:补丁后 SmartScreen 可能报"未知发布者"——预期行为,不影响功能
    4. 版本锁定:补丁仅适用于 1.1.55,升级后需重新评估。建议 scoop hold opencode 防止自动更新覆盖
      执行指令
    5. 关闭当前 OpenCode(Ctrl+C)
    6. 运行: C:\Scoop\apps\opencode\1.1.55\apply_patch.cmd
    7. 在 D:\python\gemini控制 下启动 OpenCode 验证
    8. 可选: scoop hold opencode(锁定版本)
  7. canyue7897 commented on Feb 11, 2026

    @canyue7897

    经gemini cli修复已经正常
    希望官人尽快修复
    不然下次更新又要重新修复

  8. passwa11 commented on Feb 11, 2026

    @passwa11

    I also encountered the same problem in zh-Hant

  9. added a commit that references this issue on Feb 11, 2026
    f328ed4
  10. mml1988 commented on Feb 11, 2026

    @mml1988

    When is it expected to be resolved?

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions