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
在 Window 环境下 AI 使用 PowerShell 修改文件添加中文内容会有乱码出现 #30205
The related issues here are all about garbled output (reading a child process's stdout back through a CP936 decoder). What you're hitting is different: the file on disk is actually written with the wrong encoding, so chcp 65001 and [Console]::OutputEncoding don't help.
The cause is PowerShell's default write encoding, not the console code page:
Out-File, >, Set-Content, and Add-Content in Windows PowerShell 5.1 default to UTF-16LE or the legacy ANSI page (CP936 on zh-CN), so Chinese text gets mangled the moment it's written.
PowerShell 7 defaults these to UTF-8 without BOM, which is usually what you want.
Set-Content -Encoding utf8 looks like a fix but on 5.1 it writes a BOM, which then breaks some toolchains; on 7 the same flag writes no BOM.
Two reliable ways to pin it down when the agent shells out:
Or just have the agent write files through the editing tool / Node fs rather than redirecting PowerShell output, which sidesteps the per-cmdlet encoding entirely. The underlying trigger is still the ACP being 936, but for the file-content case the knob is the cmdlet's -Encoding, not the console.
In PawWork we sidestepped this entirely by routing all file writes through Node fs with explicit UTF-8, never through shell redirection — one less platform-dependent knob to worry about.
Activity
github-actions commentedon Jun 1, 2026
This issue might be a duplicate of existing issues. Please check:
Please review those issues and consider adding your details there if they cover the same problem.
realsharpswing commentedon Jun 1, 2026
同样遇到这个问题。我让opencode写了个 OpenCode 插件自动检测 GBK 文件并转换为 UTF-8,实测可行,分享出来:
https://github.com/realsharpswing/opencode-encoding-guard
原理是拦截 read 和 edit 工具的 hook,编码检测后自动修正,对 LLM 透明。希望对你有帮助。
PowerShell对话过程中也会显示乱码, 让opencode自己查找方案在agents.md中添加规则也解决了. 你可以试试让opencode自己分析提供方法.
Astro-Han commentedon Jun 3, 2026
The related issues here are all about garbled output (reading a child process's stdout back through a CP936 decoder). What you're hitting is different: the file on disk is actually written with the wrong encoding, so
chcp 65001and[Console]::OutputEncodingdon't help.The cause is PowerShell's default write encoding, not the console code page:
Out-File,>,Set-Content, andAdd-Contentin Windows PowerShell 5.1 default to UTF-16LE or the legacy ANSI page (CP936 on zh-CN), so Chinese text gets mangled the moment it's written.Set-Content -Encoding utf8looks like a fix but on 5.1 it writes a BOM, which then breaks some toolchains; on 7 the same flag writes no BOM.Two reliable ways to pin it down when the agent shells out:
Or just have the agent write files through the editing tool / Node
fsrather than redirecting PowerShell output, which sidesteps the per-cmdlet encoding entirely. The underlying trigger is still the ACP being 936, but for the file-content case the knob is the cmdlet's-Encoding, not the console.In PawWork we sidestepped this entirely by routing all file writes through Node
fswith explicit UTF-8, never through shell redirection — one less platform-dependent knob to worry about.github-actions commentedon Aug 4, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.