opencode-plugin-encoding-auto
v1.0.1
Published
OpenCode plugin that auto-detects file encoding (EUC-KR, CP949, Shift-JIS, etc) and handles read/edit/write without garbled text on Windows
Maintainers
Readme
opencode-plugin-encoding-auto
OpenCode plugin that auto-detects file encoding (EUC-KR, CP949, Shift-JIS, GB2312, etc) and handles read/edit/write without garbled text on Windows.
Problem
On Windows, when working with files saved in non-UTF-8 encodings (e.g. Korean EUC-KR, Japanese Shift-JIS, Chinese GB2312), opencode's built-in tools produce garbled text (mojibake) because they assume UTF-8.
Solution
This plugin:
- Read — Auto-detects file encoding using chardet, decodes with iconv-lite, and outputs proper text to the console.
- Edit/Write — Temporarily converts the file to UTF-8 so opencode's built-in edit/write tools run normally (including diff display), then converts back to the original encoding after the operation completes.
- Bash (PowerShell) — Prepends
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8to PowerShell commands for proper console output.
Installation
Add to your opencode.json:
{
"plugin": ["opencode-plugin-encoding-auto"]
}Or use a local path:
{
"plugin": ["./plugins/encoding-auto.ts"]
}Dependencies
- chardet — character encoding detection
- iconv-lite — encoding/decoding
How It Works
tool.execute.before (edit/write):
file.enc → detect encoding → convert to UTF-8 temp
↓
built-in edit/write runs (diff shown)
↓
tool.execute.after (edit/write):
file.utf8 → read UTF-8 → convert back to original encoding → savetool.execute.after (read):
file.enc → detect encoding → decode → output to consoleSupported Encodings
Any encoding supported by iconv-lite, including:
- EUC-KR / CP949 (Korean)
- Shift-JIS / CP932 (Japanese)
- GB2312 / GBK (Chinese)
- ISO-8859-1 / Windows-1252 (Western)
- And many more
License
MIT
