You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
CLI shell uses GBK encoding by default, causing Chinese characters garbled; want to set default encoding to UTF-8 #30055
When executing shell commands via the OpenCode CLI, the shell defaults to GBK encoding. This leads to garbled display for output containing Chinese characters.
I can manually switch the encoding to UTF-8 to fix the garbling for the current command session. However, the encoding will revert back to GBK automatically the next time I run shell commands.
Could you please support setting UTF-8 as the default encoding for the shell environment in OpenCode CLI permanently?
The root cause here is the Windows active code page (ACP), not the shell choice. On zh-CN Windows the ACP is 936 (GBK), and a spawned child process inherits it for both stdin and stdout. So when a tool writes UTF-8 bytes, the parent reads them back through a GBK decoder and you get mojibake. Switching cmd to PowerShell or back won't fix it on its own, because both inherit the same ACP.
Two layers usually have to be handled together:
Force the child's console code page to UTF-8 before the command runs.
cmd: prefix with chcp 65001 >nul & ...
Windows PowerShell 5.1: $OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::new($false); ... (PowerShell 7+ already defaults to UTF-8, so detect the host before injecting this)
Stop assuming the byte encoding on the Node side. Read stdout as a Buffer rather than a string, detect the real code page (e.g. via chcp), and decode with iconv-lite. If you hardcode utf8 you just move the mojibake onto the GBK-only tools; if you hardcode gbk you break everything else.
A couple of env vars help the common subtools emit UTF-8 in the first place: PYTHONUTF8=1 and PYTHONIOENCODING=utf-8 for Python. Leaving LANG/LC_ALL unset is usually safer than forcing a POSIX locale that the native Windows tools don't honor.
The reason this only bites on Windows is that macOS and Linux default to a UTF-8 ACP, so the inherited-code-page path is invisible there.
For reference, PawWork (a desktop fork targeting Windows/macOS) ended up combining chcp 65001 injection with Buffer-based reading on the Node side — the dual approach is the only thing that held up across cmd, PowerShell 5.1, and 7.
Activity
github-actions commentedon May 31, 2026
This issue might be a duplicate of existing issues. Please check:
If your issue is not covered by any of the above, please let us know what makes your case different.
Astro-Han commentedon Jun 3, 2026
The root cause here is the Windows active code page (ACP), not the shell choice. On zh-CN Windows the ACP is 936 (GBK), and a spawned child process inherits it for both stdin and stdout. So when a tool writes UTF-8 bytes, the parent reads them back through a GBK decoder and you get mojibake. Switching cmd to PowerShell or back won't fix it on its own, because both inherit the same ACP.
Two layers usually have to be handled together:
Force the child's console code page to UTF-8 before the command runs.
chcp 65001 >nul & ...$OutputEncoding = [Console]::OutputEncoding = [Text.UTF8Encoding]::new($false); ...(PowerShell 7+ already defaults to UTF-8, so detect the host before injecting this)Stop assuming the byte encoding on the Node side. Read stdout as a Buffer rather than a string, detect the real code page (e.g. via
chcp), and decode with iconv-lite. If you hardcodeutf8you just move the mojibake onto the GBK-only tools; if you hardcodegbkyou break everything else.A couple of env vars help the common subtools emit UTF-8 in the first place:
PYTHONUTF8=1andPYTHONIOENCODING=utf-8for Python. LeavingLANG/LC_ALLunset is usually safer than forcing a POSIX locale that the native Windows tools don't honor.The reason this only bites on Windows is that macOS and Linux default to a UTF-8 ACP, so the inherited-code-page path is invisible there.
For reference, PawWork (a desktop fork targeting Windows/macOS) ended up combining
chcp 65001injection with Buffer-based reading on the Node side — the dual approach is the only thing that held up across cmd, PowerShell 5.1, and 7.