large-file-write-mkdir
Was er macht
Dieser Skill erweitert den Ersatzweg für große Dateien, indem er vor dem Schreiben sicherstellt, dass der Zielordner existiert. Er richtet sich an Menschen, die lange Dateien in Ordner speichern, die vielleicht noch nicht existieren.
Wann du ihn nutzt
- ✓Wenn das normale Schreibwerkzeug bei einer großen Datei scheitert.
- ✓Wenn der Ordner für die neue Datei noch nicht existiert.
- ✓Wenn ein Python-Schreibvorgang mit FileNotFoundError an einem fehlenden Ordner scheitert.
Link zum Skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-mkdir/SKILL.mdKopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.
So nutzt du ihn
Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.
Fertige Nachricht zum Einfügen
Für Claude Code, Codex oder Cursor: Führe den Befehl in deinem Projektordner aus, dann wird der Skill installiert.
Lade die SKILL.md herunter und lege sie in den Skills-Ordner deines Agenten.
Beispielanfrage an deine KI
“Speichere diesen langen Bericht in einem neuen Unterordner reports. Vorher ist das Schreiben gescheitert, also lege den Ordner an und schreibe die Datei.”
5 neue Skills pro Woche. 1 Minute Lesezeit.
So funktioniert es
Der Agent führt mkdir -p für den übergeordneten Ordner aus, das legt alle fehlenden Ordner an, und startet dann ein Python-Heredoc, das die Datei schreibt. Ist der übergeordnete Ordner nicht bekannt, findet er ihn zuerst mit dirname.
Technischer Inhalt (originale SKILL.md)
Originaltext des Autors, auf Englisch, direkt von GitHub.
Large File Write Fallback (with Directory Pre-creation)
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.
A second class of failure occurs when the target directory does not exist:
Python's open() will raise FileNotFoundError if any intermediate directory
is missing. Always pre-create the parent directory to prevent this.
Solution
Use run_shell with a mkdir -p prefix and a Python heredoc pattern.
The mkdir -p ensures the target directory exists; the heredoc streams the
file content through stdin directly into Python's open(), bypassing the
payload constraints of the other tools.
Template
mkdir -p "<PARENT DIRECTORY OF TARGET PATH>" && 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.
Tip: If the parent directory is not known in advance, use the shell
dirnamehelper:mkdir -p "$(dirname '<TARGET PATH>')" && python3 - << 'EOF'
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:- Pre-create the parent directory with
mkdir -p <parent_dir>. This is a no-op when the directory already exists, so it is always safe to include. Skipping this step causes Python'sopen()to raiseFileNotFoundErrorfor any new or deeply-nested path. - Embed the full file content inside a Python triple-quoted string.
- Specify the target path inside the
open()call. - Pass the entire block (mkdir + heredoc) as the
commandtorun_shell.
- Pre-create the parent directory with
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:
mkdir -p "src/components" && 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 + mkdir -p + Python heredoc |
shell_agent also fails on large inline content |
run_shell + mkdir -p + Python heredoc |
| Target directory may not exist | Always add mkdir -p <parent_dir> first |
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. - The
mkdir -pcommand is idempotent: it succeeds whether or not the directory already exists, so it is always safe to include. - To derive the parent directory from a target path in shell:
mkdir -p "$(dirname '<TARGET PATH>')"works as a generic alternative when the parent path is not already known.
Häufige Fragen
Warum zuerst mkdir ausführen?
Python scheitert mit FileNotFoundError, wenn ein Teil des Zielpfads fehlt.
Was macht mkdir -p?
Die Option -p legt alle fehlenden übergeordneten Ordner in einem Befehl an und tut nichts, wenn sie schon existieren.
Was, wenn ich den Ordner nicht kenne?
Der Skill zeigt, wie man mit dirname den übergeordneten Ordner des Zielpfads ermittelt.
Details
Originalbeschreibung des Autors
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, with an explicit mkdir -p step to ensure the target directory exists before writing.
repo: HKUDS/AgentPilot
Beliebtheit
- GitHub-Sterne
- 7.8k
- Platz im Ranking
- #13058
- Lizenz
- MIT
- Aktualisiert
- 1.11.2026
Kommentare
- …
Weitere Skills aus diesem Repository
agentpilot
7.8kHilft deinem Agenten, ein Projekt Schritt für Schritt zu verbessern: Er bereitet eine Aufgabe vor und startet die AgentPilot-Schleife, die Änderungen testet und bewertet.
openspace
7.8kHilft deinem Agenten, OpenSpace einzurichten, ein Werkzeug, das Agenten-Skills speichert und abruft, und es über MCP mit deiner KI-App zu verbinden.
rsi-arena
7.8kHilft deinem Agenten, Standard-Benchmarks für KI wie AIME und Terminal-Bench einzurichten und auszuführen, um Verbesserungsmethoden zu vergleichen.
experiment-guide
7.8kHilft deinem Agenten, kleine Experimente zu planen, Ergebnisse auszuwerten und Erkenntnisse festzuhalten, während er ein Programm verbessern will.
Ähnliche Skills
diffs
394kLässt deinen Agenten einen echten, teilbaren Diff seiner Änderungen als Viewer-Link oder Bilddatei erstellen, statt einer handgeschriebenen Zusammenfassung.
coding-agent
394kHilft deinem Agenten, eine größere Programmieraufgabe als Hintergrund-Worker an Codex, Claude Code oder OpenCode zu übergeben und danach den Fortschritt zu prüfen.
gh-issues
394kHilft deinem Agenten, GitHub-Issues zu finden, die zu bearbeitenden auszuwählen und Pull Requests mit Korrekturen zu öffnen, einschließlich der Nacharbeit an Review-Kommentaren.