bug: x-opencode-directory header invalid on Windows Chinese path #9135

Open
opened 2026-02-16 18:11:43 -05:00 by yindo · 2 comments
Owner

Originally created by @hexuansun43-dotcom on GitHub (Feb 11, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

Describe the bug

On Windows system, starting opencode in a directory with Chinese characters (e.g., 待办) or using default backslash path (\) triggers a TypeError for invalid x-opencode-directory header value.

To Reproduce

Steps to reproduce the behavior:

  1. Create a folder with Chinese characters: C:\Users\KC\Desktop\MyFile\待办
  2. Navigate to the folder: cd C:\Users\KC\Desktop\MyFile\待办
  3. Run command: opencode
  4. See error: TypeError: Header 'x-opencode-directory' has invalid value: 'C:\Users\KC\Desktop\MyFile\待办'

Expected behavior

opencode should support Windows paths with Chinese characters and backslashes, start normally without errors.

Actual behavior

Error log:
{
"name": "UnknownError",
"data": {
"message": "TypeError: Header 'x-opencode-directory' has invalid value: 'C:\Users\KC\Desktop\MyFile\待办'\n at set (unknown)\n at mergeHeaders (../sdk/js/src/gen/client/utils.gen.ts:184:23)\n at mergeConfigs (../sdk/js/src/gen/client/utils.gen.ts:161:20)\n at createClient (../sdk/js/src/gen/client/client.gen.ts:21:17)\n at createOpencodeClient (../sdk/js/src/client.ts:28:18)\n at (src/plugin/index.ts:25:20)\n at (src/project/state.ts:22:21)\n at init2 (src/plugin/index.ts:123:25)\n at InstanceBootstrap (src/project/bootstrap.ts:19:16)\n at (src/project/instance.ts:34:23)\n at async provide (src/project/instance.ts:40:23)"
}
}

Environment

  • OS: Windows 10/11
  • Shell: PowerShell
  • opencode version: 1.1.56

Workaround

  1. Rename folder to English (e.g., todo) → works
  2. Use forward slash path: opencode --directory "C:/Users/KC/Desktop/MyFile/待办" → works

Suggested fix

The issue may be caused by:

  • Missing escape for Windows backslash (\) in HTTP header value
  • No handling for Chinese character encoding in path

Plugins

oh-my-opencode@3.5.2

OpenCode version

1.1.56

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a folder with Chinese characters: C:\Users\KC\Desktop\MyFile\待办
  2. Navigate to the folder: cd C:\Users\KC\Desktop\MyFile\待办
  3. Run command: opencode
  4. See error: TypeError: Header 'x-opencode-directory' has invalid value: 'C:\Users\KC\Desktop\MyFile\待办'

Screenshot and/or share link

Image

Operating System

Windows11

Terminal

Windows PowerShell

Originally created by @hexuansun43-dotcom on GitHub (Feb 11, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description ### Describe the bug On Windows system, starting opencode in a directory with Chinese characters (e.g., `待办`) or using default backslash path (`\`) triggers a TypeError for invalid `x-opencode-directory` header value. ### To Reproduce Steps to reproduce the behavior: 1. Create a folder with Chinese characters: `C:\Users\KC\Desktop\MyFile\待办` 2. Navigate to the folder: `cd C:\Users\KC\Desktop\MyFile\待办` 3. Run command: `opencode` 4. See error: `TypeError: Header 'x-opencode-directory' has invalid value: 'C:\Users\KC\Desktop\MyFile\待办'` ### Expected behavior opencode should support Windows paths with Chinese characters and backslashes, start normally without errors. ### Actual behavior Error log: { "name": "UnknownError", "data": { "message": "TypeError: Header 'x-opencode-directory' has invalid value: 'C:\\Users\\KC\\Desktop\\MyFile\\待办'\n at set (unknown)\n at mergeHeaders (../sdk/js/src/gen/client/utils.gen.ts:184:23)\n at mergeConfigs (../sdk/js/src/gen/client/utils.gen.ts:161:20)\n at createClient (../sdk/js/src/gen/client/client.gen.ts:21:17)\n at createOpencodeClient (../sdk/js/src/client.ts:28:18)\n at <anonymous> (src/plugin/index.ts:25:20)\n at <anonymous> (src/project/state.ts:22:21)\n at init2 (src/plugin/index.ts:123:25)\n at InstanceBootstrap (src/project/bootstrap.ts:19:16)\n at <anonymous> (src/project/instance.ts:34:23)\n at async provide (src/project/instance.ts:40:23)" } } ### Environment - OS: Windows 10/11 - Shell: PowerShell - opencode version: 1.1.56 ### Workaround 1. Rename folder to English (e.g., `todo`) → works 2. Use forward slash path: `opencode --directory "C:/Users/KC/Desktop/MyFile/待办"` → works ### Suggested fix The issue may be caused by: - Missing escape for Windows backslash (`\`) in HTTP header value - No handling for Chinese character encoding in path ### Plugins oh-my-opencode@3.5.2 ### OpenCode version 1.1.56 ### Steps to reproduce Steps to reproduce the behavior: 1. Create a folder with Chinese characters: `C:\Users\KC\Desktop\MyFile\待办` 2. Navigate to the folder: `cd C:\Users\KC\Desktop\MyFile\待办` 3. Run command: `opencode` 4. See error: `TypeError: Header 'x-opencode-directory' has invalid value: 'C:\Users\KC\Desktop\MyFile\待办'` ### Screenshot and/or share link <img width="1093" height="289" alt="Image" src="https://github.com/user-attachments/assets/39beea8e-025f-47d6-b465-6fb45b3699fd" /> ### Operating System Windows11 ### Terminal Windows PowerShell
yindo added the windowsbug labels 2026-02-16 18:11:43 -05:00
Author
Owner

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

This issue appears to be a duplicate of existing reports about non-ASCII characters in directory paths. Please check:

  • #13167: Non-ASCII (Korean/CJK) characters in directory path cause "Header has invalid value" error (regression in v1.1.56)
  • #13087: [Crash] Crash when working directory path contains non-ASCII characters (e.g. Chinese)
  • #13063: opencode在带有中文路径的文件下无法打开 (Chinese paths issue)
  • #6906: bug: cant open folders on desktop w/ chinese characters in path

These are all the same root cause: the x-opencode-directory HTTP header is set with raw path strings containing non-ASCII characters, violating RFC 7230 (headers must contain only visible ASCII). The suggested fix in #13167 (using encodeURIComponent) appears viable.

Consider consolidating these reports to avoid duplicate work.

@github-actions[bot] commented on GitHub (Feb 11, 2026): This issue appears to be a duplicate of existing reports about non-ASCII characters in directory paths. Please check: - #13167: Non-ASCII (Korean/CJK) characters in directory path cause "Header has invalid value" error (regression in v1.1.56) - #13087: [Crash] Crash when working directory path contains non-ASCII characters (e.g. Chinese) - #13063: opencode在带有中文路径的文件下无法打开 (Chinese paths issue) - #6906: bug: cant open folders on desktop w/ chinese characters in path These are all the same root cause: the `x-opencode-directory` HTTP header is set with raw path strings containing non-ASCII characters, violating RFC 7230 (headers must contain only visible ASCII). The suggested fix in #13167 (using `encodeURIComponent`) appears viable. Consider consolidating these reports to avoid duplicate work.
Author
Owner

@hexuansun43-dotcom commented on GitHub (Feb 11, 2026):

Hi,

After submitting this issue, I was informed it's a duplicate of existing reports (#13167, #13087, #13063, #6906) about non-ASCII characters in directory paths violating RFC 7230. I will close this duplicate issue and add my details to #13063 to consolidate feedback.

The root cause is confirmed: raw non-ASCII paths in the x-opencode-directory HTTP header. The encodeURIComponent fix suggested in #13167 is a viable solution.

Thanks for pointing this out!

@hexuansun43-dotcom commented on GitHub (Feb 11, 2026): Hi, After submitting this issue, I was informed it's a duplicate of existing reports (#13167, #13087, #13063, #6906) about non-ASCII characters in directory paths violating RFC 7230. I will close this duplicate issue and add my details to #13063 to consolidate feedback. The root cause is confirmed: raw non-ASCII paths in the `x-opencode-directory` HTTP header. The `encodeURIComponent` fix suggested in #13167 is a viable solution. Thanks for pointing this out!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9135