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

Closed
opened 2026-02-16 18:11:22 -05:00 by yindo · 9 comments
Owner

Originally created by @baodexiang on GitHub (Feb 10, 2026).

Originally assigned to: @rekram1-node on GitHub.

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).

Originally created by @baodexiang on GitHub (Feb 10, 2026). Originally assigned to: @rekram1-node on GitHub. 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).
yindo added the windows label 2026-02-16 18:11:22 -05:00
yindo closed this issue 2026-02-16 18:11:22 -05:00
Author
Owner

@baodexiang commented on GitHub (Feb 10, 2026):

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

@baodexiang commented on GitHub (Feb 10, 2026): Additional details from reproduction (PowerShell in Chinese path):\n\n\n\nASCII path workaround still works.
Author
Owner

@baodexiang commented on GitHub (Feb 10, 2026):

Corrected stack trace from reproduction:

UnknownError
TypeError: Header x-opencode-directory has invalid value: C:\Usersaode\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.

@baodexiang commented on GitHub (Feb 10, 2026): Corrected stack trace from reproduction: UnknownError TypeError: Header x-opencode-directory has invalid value: C:\Usersaode\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 <anonymous> (src/plugin/index.ts:25:20) at <anonymous> (src/project/state.ts:22:21) at init2 (src/plugin/index.ts:123:25) at InstanceBootstrap (src/project/bootstrap.ts:19:16) at <anonymous> (src/project/instance.ts:34:23) at async provide (src/project/instance.ts:40:23) ASCII path workaround still works.
Author
Owner

@github-actions[bot] commented on GitHub (Feb 10, 2026):

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

  • #6906: bug: cant open folders on desktop w/ chinese characters in path (v1.1.1)
  • #5926: Windows version of the .exe terminal will report an error when opening a project folder with Chinese characters (v1.0.185)
  • #10210: Undo/revert fails for files with non-ASCII filenames on Windows (v1.1.34)

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.

@github-actions[bot] commented on GitHub (Feb 10, 2026): This issue might be a duplicate of existing issues. Please check: - #6906: bug: cant open folders on desktop w/ chinese characters in path (v1.1.1) - #5926: Windows version of the .exe terminal will report an error when opening a project folder with Chinese characters (v1.0.185) - #10210: Undo/revert fails for files with non-ASCII filenames on Windows (v1.1.34) 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.
Author
Owner

@baodexiang commented on GitHub (Feb 10, 2026):

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

@baodexiang commented on GitHub (Feb 10, 2026): Path value correction (literal): 'C:\Users\baode\OneDrive\桌面'
Author
Owner

@KolbyML commented on GitHub (Feb 10, 2026):

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

@KolbyML commented on GitHub (Feb 10, 2026): I get this bug too, but in linux with japanese text
Author
Owner

@canyue7897 commented on GitHub (Feb 10, 2026):

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

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

时间 事件 中文路径支持
之前 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,不是你的项目问题。

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

立即修复:回滚到 1.1.53
scoop reset opencode@1.1.53
这会将 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(锁定版本)
@canyue7897 commented on GitHub (Feb 10, 2026): 同样问题,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 opencode@1.1.53 这会将 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 验证修复 ⚠ 已知局限 1. 数字签名失效:补丁后 SmartScreen 可能报"未知发布者"——预期行为,不影响功能 2. 版本锁定:补丁仅适用于 1.1.55,升级后需重新评估。建议 scoop hold opencode 防止自动更新覆盖 执行指令 1. 关闭当前 OpenCode(Ctrl+C) 2. 运行: C:\Scoop\apps\opencode\1.1.55\apply_patch.cmd 3. 在 D:\python\gemini控制 下启动 OpenCode 验证 4. 可选: scoop hold opencode(锁定版本)
Author
Owner

@canyue7897 commented on GitHub (Feb 10, 2026):

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

@canyue7897 commented on GitHub (Feb 10, 2026): 经gemini cli修复已经正常 希望官人尽快修复 不然下次更新又要重新修复
Author
Owner

@passwa11 commented on GitHub (Feb 11, 2026):

I also encountered the same problem in zh-Hant

@passwa11 commented on GitHub (Feb 11, 2026): I also encountered the same problem in zh-Hant
Author
Owner

@mml1988 commented on GitHub (Feb 11, 2026):

When is it expected to be resolved?

@mml1988 commented on GitHub (Feb 11, 2026): When is it expected to be resolved?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9006