charset-fix
Windows環境でAIエージェントを使う際、文字コードが原因で中国語やUnicode文字が正しく表示されない問題を、PythonやPowerShellなどの出力を調整して解決し、文字化けを防ぐSkill。
📜 元の英語説明(参考)
Fix Chinese/Unicode character encoding issues when running AI agents on Windows via POSIX shells (Git Bash, MSYS2, WSL, BusyBox, etc.). Handles Python, PowerShell, and cmd.exe GBK/CP936 output encoding mismatch with UTF-8 terminals.
🇯🇵 日本人クリエイター向け解説
Windows環境でAIエージェントを使う際、文字コードが原因で中国語やUnicode文字が正しく表示されない問題を、PythonやPowerShellなどの出力を調整して解決し、文字化けを防ぐSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o charset-fix.zip https://jpskill.com/download/19162.zip && unzip -o charset-fix.zip && rm charset-fix.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/19162.zip -OutFile "$d\charset-fix.zip"; Expand-Archive "$d\charset-fix.zip" -DestinationPath $d -Force; ri "$d\charset-fix.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
charset-fix.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
charset-fixフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 4
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
AIエージェント向けWindows文字エンコーディング修正
POSIX互換シェルを介してWindows上でAIエージェントを実行する際に発生する、文字化けした中国語/Unicodeテキスト出力を修正します。
問題
AIエージェントがPOSIXシェル(Git Bash、MSYS2、BusyBox、または任意のUnixライクなシェルレイヤー)を介してWindows上でコマンドを実行すると、中国語や拡張Unicode文字を含むテキスト出力が文字化けすることがよくあります。
$ python3 -c "print('中文测试')"
���IJ��� ← 文字化け
$ echo "中文测试"
中文测试 ← 正しい
根本原因
| レイヤー | エンコーディング | 理由 |
|---|---|---|
| Windowsシステム | GBK/GB2312 (CP936) | 中国語版Windowsのデフォルトコードページ |
| Python 3 | GBK | sys.stdout.encodingがシステムコードページを自動検出 |
| PowerShell (powershell.exe) | GB2312 | [Console]::OutputEncodingがシステムCPにデフォルト設定 |
| cmd.exe | GBK | Windowsネイティブのコマンドプロセッサ |
| POSIXシェル (Git Bash, BusyBox, MSYS2) | UTF-8 | UTF-8入力を期待 |
| PowerShell Core (pwsh.exe) | UTF-8 | ✅ デフォルトでUTF-8、修正不要 |
不一致:WindowsネイティブツールはGBKエンコードされたテキストを出力しますが、POSIXシェルターミナルはそれをUTF-8として読み取るため、文字化けが発生します。
クイックフィックス
Python
PYTHONIOENCODING=utf-8 python3 -c "print('中文测试 ✅')"
セッション全体に設定する場合:
export PYTHONIOENCODING=utf-8
python3 script.py
PowerShell (Windows PowerShell、Coreではない)
powershell.exe -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Write-Host '中文测试'"
cmd.exe / Windowsネイティブツール
PythonのsubprocessをGBK→UTF-8ブリッジとして使用します。
PYTHONIOENCODING=utf-8 python3 -c "
import subprocess
r = subprocess.run(['cmd.exe', '/c', 'systeminfo | findstr 系统'],
capture_output=True, text=True, encoding='gbk')
print(r.stdout)
"
コードレベルでの修正 (Python)
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
検証
PYTHONIOENCODING=utf-8 python3 -c "print('charset-fix: 中文测试成功 ✅')"
期待される出力: charset-fix: 中文测试成功 ✅
仕組み
| 修正 | メカニズム |
|---|---|
PYTHONIOENCODING=utf-8 |
Pythonのstdoutエンコーディング検出を上書きします |
[Console]::OutputEncoding = UTF8 |
PowerShellのコンソール出力をUTF-8に設定します |
subprocess(..., encoding='gbk') |
cmd.exeの出力を正しくデコードし、UTF-8として出力します |
互換性
| プラットフォーム | ステータス |
|---|---|
| Windows + Git Bash | ✅ 動作します |
| Windows + BusyBox | ✅ 動作します |
| Windows + MSYS2 | ✅ 動作します |
| Windows + WSL | ✅ 動作します |
| macOS / Linux | ⬜ 不要です |
| PowerShell Core (pwsh) | ⬜ 不要です |
Claude Code、Codex CLI、Cline、Cursor、GitHub Copilot、OpenClawエージェントで動作します。
デバッグ
# コードページの確認
powershell.exe -NoProfile -Command "chcp"
# Pythonエンコーディングの確認
python3 -c "import sys; print(sys.stdout.encoding)"
# 生のシェル出力のテスト
echo "中文测试"
ライセンス
MIT
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
Windows Character Encoding Fix for AI Agents
Fix garbled Chinese/Unicode text output when running AI agents on Windows through POSIX-compatible shells.
Problem
When AI agents run commands on Windows through POSIX shells (Git Bash, MSYS2, BusyBox, or any Unix-like shell layer), text output containing Chinese or extended Unicode characters often appears garbled:
$ python3 -c "print('中文测试')"
���IJ��� ← garbled
$ echo "中文测试"
中文测试 ← correct
Root Cause
| Layer | Encoding | Why |
|---|---|---|
| Windows system | GBK/GB2312 (CP936) | Default code page for Chinese Windows |
| Python 3 | GBK | sys.stdout.encoding auto-detects system code page |
| PowerShell (powershell.exe) | GB2312 | [Console]::OutputEncoding defaults to system CP |
| cmd.exe | GBK | Native Windows command processor |
| POSIX shell (Git Bash, BusyBox, MSYS2) | UTF-8 | Expects UTF-8 input |
| PowerShell Core (pwsh.exe) | UTF-8 | ✅ Defaults to UTF-8, no fix needed |
The mismatch: Windows-native tools output GBK-encoded text, but the POSIX shell terminal reads it as UTF-8, producing garbled characters.
Quick Fix
Python
PYTHONIOENCODING=utf-8 python3 -c "print('中文测试 ✅')"
Set it for the whole session:
export PYTHONIOENCODING=utf-8
python3 script.py
PowerShell (Windows PowerShell, not Core)
powershell.exe -NoProfile -Command "[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Write-Host '中文测试'"
cmd.exe / Windows native tools
Use Python's subprocess as a GBK→UTF-8 bridge:
PYTHONIOENCODING=utf-8 python3 -c "
import subprocess
r = subprocess.run(['cmd.exe', '/c', 'systeminfo | findstr 系统'],
capture_output=True, text=True, encoding='gbk')
print(r.stdout)
"
Code-level fix (Python)
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
Verification
PYTHONIOENCODING=utf-8 python3 -c "print('charset-fix: 中文测试成功 ✅')"
Expected: charset-fix: 中文测试成功 ✅
How It Works
| Fix | Mechanism |
|---|---|
PYTHONIOENCODING=utf-8 |
Overrides Python's stdout encoding detection |
[Console]::OutputEncoding = UTF8 |
Sets PowerShell's console output to UTF-8 |
subprocess(..., encoding='gbk') |
Decodes cmd.exe output correctly, then emits as UTF-8 |
Compatibility
| Platform | Status |
|---|---|
| Windows + Git Bash | ✅ Works |
| Windows + BusyBox | ✅ Works |
| Windows + MSYS2 | ✅ Works |
| Windows + WSL | ✅ Works |
| macOS / Linux | ⬜ Not needed |
| PowerShell Core (pwsh) | ⬜ Not needed |
Works with: Claude Code, Codex CLI, Cline, Cursor, GitHub Copilot, OpenClaw agents.
Debugging
# Check code page
powershell.exe -NoProfile -Command "chcp"
# Check Python encoding
python3 -c "import sys; print(sys.stdout.encoding)"
# Test raw shell output
echo "中文测试"
License
MIT
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (3,450 bytes)
- 📎 LICENSE (1,065 bytes)
- 📎 README.md (2,350 bytes)
- 📎 scripts/fix.py (2,156 bytes)