large-file-write-heredoc
できること
このスキルは、AIエージェントの書き込みツールが原因不明のエラーで失敗したとき、大きなファイルを書くための代替方法を示します。長い文書やコードのファイルを保存したい人向けです。
使う場面
- ✓大きなファイルで、書き込みツールが原因不明のエラーを出したとき。
- ✓インラインの内容が大きすぎて、シェルエージェントも失敗するとき。
- ✓長いファイルを、渡された内容どおりに保存する必要があるとき。
スキルのリンク
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-heredoc/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“この長い設定ファイルをプロジェクトに保存してください。書き込みツールがサイズで失敗し続けるので、別の方法を使ってください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
エージェントは、まず通常の書き込みツールを試します。失敗したら、ファイルの全内容をPythonのヒアドキュメントを通して、ファイルを書く処理に渡します。これにより、ほかのツールのサイズ制限を回避します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Large File Write Fallback
Problem
When writing large files (typically several KB or more), two common tools may
fail with unknown error due to internal payload size limits:
write_file— has a maximum content size it can handle in a single call.shell_agent— may also hit payload limits when the task description includes large inline content.
Solution
Use run_shell with a Python heredoc pattern. This streams the file
content through stdin directly into Python's open(), bypassing the payload
constraints of the other tools.
Template
python3 - << 'EOF'
content = """<FILE CONTENTS HERE>"""
with open("<TARGET PATH>", "w") as f:
f.write(content)
EOF
Pass this as the command parameter to run_shell.
Step-by-Step Instructions
Attempt the normal write using
write_filefirst. If it succeeds, you are done.If
write_filefails (especially withunknown erroror a timeout on large content), do NOT retry withshell_agentusing inline content — it will likely fail for the same reason.Use the
run_shellheredoc fallback:- Embed the full file content inside a Python triple-quoted string.
- Specify the target path inside the
open()call. - Pass the entire block as the
commandtorun_shell.
Escape carefully inside the heredoc:
- Backslashes that should be literal in the file must be doubled (
\\). - Triple-quotes inside the content must be escaped (
\"\"\"). - The heredoc delimiter
EOFmust not appear on a line by itself inside the content (rename it toPYEOForFILEEOFif needed).
- Backslashes that should be literal in the file must be doubled (
Verify the write by following up with a
run_shellcall such as:wc -l <TARGET PATH> && head -5 <TARGET PATH>
Full Example
Suppose you need to write a large TypeScript file to
src/components/Dashboard.ts:
python3 - << 'PYEOF'
content = """import { foo } from './foo';
export interface DashboardData {
title: string;
items: string[];
}
export function createDashboard(data: DashboardData): string {
return `<div>${data.title}</div>`;
}
"""
with open("src/components/Dashboard.ts", "w") as f:
f.write(content)
PYEOF
Pass the above (without the surrounding code fence) as the command
argument to run_shell.
When to Use This Pattern
| Situation | Recommended tool |
|---|---|
| Small file (< ~2 KB) | write_file |
| Medium file, no errors yet | write_file (try first) |
Large file or write_file failed |
run_shell + Python heredoc |
shell_agent also fails on large inline content |
run_shell + Python heredoc |
Notes
- This pattern works for any text-based file (TypeScript, Python, JSON, YAML, Markdown, etc.).
- For binary files, adapt the approach to use
base64decoding inside the Python script. - The heredoc delimiter (
EOF,PYEOF,FILEEOF) can be any string not present as a standalone line in your content — choose accordingly. - This technique is also useful when content contains characters that would
need heavy shell escaping in a plain
echoorprintfapproach.
よくある質問
なぜ通常の書き込みは失敗するのですか?
1回の呼び出しで扱える内容の上限があり、大きなファイルはそれを超えることがあるからだとスキルは述べています。
エスケープが必要なものは何ですか?
ファイルの内容にあるバックスラッシュや引用符は、意図どおりに保存されるよう注意が必要です。
エージェントはシェルエージェントで再試行すべきですか?
いいえ。インラインの内容は同じ理由でそこでも失敗しやすいため、スキルは再試行しないよう述べています。
詳細
作者による元の説明
Reliable fallback technique for writing large file contents when write_file and shell_agent both fail with 'unknown error' due to payload size limits — uses run_shell with a Python heredoc to bypass tool constraints.
repo: HKUDS/AgentPilot
人気
- GitHubのスター
- 7.8k
- ランキング
- #13057
- ライセンス
- 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のイシューを探し、取り組むものを選び、修正を含むプルリクエストを開くようエージェントを支援します。レビューコメントへの対応も含みます。