unicode-safe-file-writing
できること
このスキルは、テキストに絵文字や特殊記号が含まれると失敗するファイル保存の回避策を説明します。AIエージェントがそのようなファイルを保存するのに苦労している人向けです。
使う場面
- ✓テキストに絵文字や特殊記号が含まれ、ファイルの保存が原因不明のエラーで失敗するとき。
- ✓矢印やダッシュなどの記号を含むファイルを、正しく保存する必要があるとき。
- ✓ファイルツールが扱えない記号について、プレーンテキストの置き換えがほしいとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/unicode-safe-file-writing/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“絵文字と矢印があるため失敗し続けていますが、このファイルを保存してもらえますか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、テキストをそのまま渡すシェルコマンドでファイルを書きます。また、先に記号をプレーンテキストの代替に置き換えることもできます。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Unicode-Safe File Writing
Problem
The write_file tool may fail with 'unknown error' when the file content
contains multi-byte Unicode characters such as:
- Emoji (e.g.
🚀,✅,❌) - Special typographic symbols (e.g.
→,•,—,©) - Non-ASCII characters outside the Latin-1 range
This is a known encoding limitation of write_file.
Solution
Fall back to run_shell and write the file using a shell heredoc
(cat > file << 'EOF' ... EOF). The single-quoted delimiter 'EOF'
prevents the shell from interpreting any special characters inside the
block.
Step-by-Step Recovery
Step 1 — Detect the failure
If write_file returns an error such as:
Error: unknown error
and the content contains non-ASCII characters, assume a Unicode encoding issue and proceed to the heredoc fallback.
Step 2 — Strip or replace problematic characters (if needed)
Before embedding content in the heredoc, decide whether to:
- Keep the characters as-is (works if the shell/terminal is UTF-8 aware)
- Replace emoji/symbols with ASCII equivalents (safest, most portable)
- Remove them entirely
Common replacements:
| Original | Replacement |
|---|---|
✅ |
[OK] |
❌ |
[ERROR] |
🚀 |
[START] |
→ |
-> |
• |
- |
— |
-- |
Step 3 — Write the file via heredoc
Use run_shell with the following pattern:
cat > path/to/file.ext << 'EOF'
...file content here (with Unicode stripped/replaced if needed)...
EOF
Key details:
- Use
'EOF'(single-quoted) as the heredoc delimiter — this disables all shell variable expansion and special character interpretation inside the block. - Do not indent the closing
EOF(it must start at column 0). - For deeply nested content, choose a delimiter that cannot appear in the
content itself (e.g.
'HEREDOC_END','FILEEND').
Example
Failing call
write_file(
path="src/components/StatusPanel.ts",
content="// Status icons\nconst icons = { ok: '✅', err: '❌', run: '🚀' };\n"
)
# → Error: unknown error
Recovery via heredoc
cat > src/components/StatusPanel.ts << 'EOF'
// Status icons
const icons = { ok: '[OK]', err: '[ERROR]', run: '[START]' };
EOF
Or, if UTF-8 output is acceptable in the environment:
cat > src/components/StatusPanel.ts << 'EOF'
// Status icons
const icons = { ok: '✅', err: '❌', run: '🚀' };
EOF
Multi-File Scenario
When writing several files and one fails, write the others with write_file
as normal and apply the heredoc fallback only to the failing file(s):
# Write multiple files that contain Unicode
cat > src/utils/icons.ts << 'EOF'
export const ICONS = {
success: '[OK]',
failure: '[FAIL]',
pending: '[...]',
};
EOF
cat > src/utils/labels.ts << 'EOF'
export const LABELS = {
title: 'Dashboard',
subtitle: 'Real-time status',
};
EOF
Important Notes
- Always prefer
write_filefirst — only fall back to the heredoc approach whenwrite_filefails. - Verify after writing — use
run_shellwithcat path/to/fileorhead -5 path/to/fileto confirm the content was written correctly. - Directory creation —
write_fileauto-creates parent directories; the heredoc approach does not. Pre-create directories withmkdir -p path/to/dirif needed. - Large files — heredocs work well for files of any practical size; there is no meaningful shell limit.
- Escaping backslashes — inside a single-quoted heredoc, backslashes are treated literally (no escaping needed), which is usually desirable.
よくある質問
絵文字は表示されたままになりますか?
ほとんどのターミナルで動くため残せますが、安全のためにプレーンテキストに置き換えることもできます。
失敗の原因は何ですか?
通常のファイル書き込みツールは、マルチバイト文字で失敗することがあるとスキルは述べています。
この方法は安全ですか?
指定されたファイルにだけ書き込むので、単純な保存の手順です。
詳細
作者による元の説明
How to reliably write files containing multi-byte Unicode (emoji, special symbols) when write_file fails with 'unknown error' by falling back to run_shell with a heredoc.
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #13087
- ライセンス
- MIT
- 更新日
- 2026/11/1
コメント
- …
このリポジトリの他のスキル
agentpilot
7.8kエージェントが、作業を準備し、変更案を提案してテストし、評価するAgentPilotのループを実行することで、プロジェクトを段階的に改善できるよう支援します。
openspace
7.8kエージェントが、スキルを保存し取り出すツールであるOpenSpaceをセットアップし、MCPを通じてAIアプリに接続できるよう支援します。
rsi-arena
7.8kエージェントが、AIMEやTerminal-Benchなどの標準的なAIベンチマークテストをセットアップして実行し、異なる改善方法を比較できるよう支援します。
experiment-guide
7.8kエージェントが、プログラムを改善する方法を調べる間に、小さな実験を計画し、その結果を読み、発見を記録できるよう支援します。
似ているスキル
diffs
394k編集内容の実際の共有可能な差分を、手書きの要約ではなく、ビューアーのリンクや画像ファイルとして作成するようエージェントを支援します。
coding-agent
394kCodex、Claude Code、OpenCodeに大きめのコーディング作業をバックグラウンドのワーカーとして渡し、その進捗を確認するようエージェントを支援します。
gh-issues
394kGitHubのイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。