large-file-write-mkdir
Ce qu’il fait
Cette compétence complète la méthode de secours pour les gros fichiers en s'assurant que le dossier cible existe avant l'écriture. Elle s'adresse aux personnes qui enregistrent de longs fichiers dans des dossiers qui n'existent peut-être pas encore.
Quand l’utiliser
- ✓Quand l'outil d'écriture habituel échoue sur un gros fichier.
- ✓Quand le dossier du nouveau fichier n'existe pas encore.
- ✓Quand une écriture Python échoue avec une erreur FileNotFoundError sur un dossier manquant.
Lien du skill
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-mkdir/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Enregistre ce long rapport dans un nouveau sous-dossier reports. L'écriture a échoué la fois précédente, donc crée le dossier puis écris le fichier.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'agent exécute mkdir -p sur le dossier parent, ce qui crée tous les dossiers manquants, puis lance un heredoc Python qui écrit le fichier. Si le dossier parent n'est pas connu, il peut le trouver avec dirname.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis 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.
Questions fréquentes
Pourquoi exécuter mkdir d'abord ?
Python échoue avec FileNotFoundError si une partie du chemin du dossier cible est absente.
Que fait mkdir -p ?
L'option -p crée tous les dossiers parents manquants en une commande, et ne fait rien s'ils existent déjà.
Et si je ne connais pas le dossier ?
La compétence montre comment utiliser dirname sur le chemin cible pour trouver le dossier parent.
Détails
Description originale de l’auteur
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
Popularité
- Étoiles GitHub
- 7.8k
- Position au classement
- #13058
- Licence
- MIT
- Mis à jour
- 01/11/2026
Commentaires
- …
Autres skills de ce dépôt
agentpilot
7.8kAide votre agent à améliorer un projet étape par étape, en préparant une tâche et en lançant la boucle AgentPilot qui propose, teste et note les changements.
openspace
7.8kAide votre agent à installer OpenSpace, un outil qui enregistre et retrouve les skills des agents, et à le relier à votre application IA grâce à MCP.
rsi-arena
7.8kAide votre agent à configurer et lancer des tests de référence standard en IA, comme AIME et Terminal-Bench, pour comparer différentes méthodes d'amélioration.
experiment-guide
7.8kAide votre agent à planifier de petites expériences, à lire leurs résultats et à noter les conclusions pendant qu'il cherche comment améliorer un programme.
Skills similaires
diffs
394kPermet à votre agent de produire un diff réel et partageable de vos modifications, sous forme de lien ou d'image, plutôt qu'un résumé écrit à la main.
coding-agent
394kAide votre agent à confier une tâche de programmation plus importante à Codex, Claude Code ou OpenCode comme travailleur en arrière-plan, puis à suivre sa progression.
gh-issues
394kAide votre agent à trouver des tickets GitHub, choisir ceux à traiter et ouvrir des pull requests avec des correctifs, y compris le suivi des commentaires de relecture.