large-file-write-via-temp-script
What it does
This skill shows the AI agent how to save large files that contain tricky characters, such as backticks, template literals or emoji. It is for developers saving TypeScript, TSX or similar files that fail when passed inline.
When to use it
- βWhen file content includes backticks, dollar-brace template literals or emoji that break inline commands.
- βWhen inline write attempts fail with unknown errors or silently empty the file.
- βWhen a large TypeScript or TSX file must be saved exactly as written.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/legacy/v1/showcase/skills/large-file-write-via-temp-script/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agentβs skills folder.
Example of what to ask your AI
βSave this TSX component to my project. It has backticks and template literals, and the inline writes keep breaking.β
5 new skills a week. 1 minute to read.
How it works
The agent writes a small Python helper script to a temp file. The file content sits inside a raw string in that script, so special characters are kept, and the agent then runs the helper to write the target file.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Large File Write via Temp Script
Problem
Writing large files β especially TypeScript, TSX, or any content containing
Unicode emoji, backticks, ${} template literals, or multi-line heredoc
conflicts β can silently fail or truncate content when passed inline.
Failure modes observed:
write_filereturns[ERROR] unknown erroron large payloadsnode -e '...'with backtick template literals silently empties the target filepython3 -c '...'breaks on unescaped quotes or special charactersshell_agentmay time out or fail when the inline content is too large
Solution: Write a Python Script to a Temp File First
Instead of passing file content inline, write a small Python helper script to
/tmp/write_task.py (or similar), then execute it. The helper script holds
the target file content as a raw Python string or via base64 decoding.
Approach A β Python Triple-Quoted String (preferred for readability)
Use write_file or a heredoc to create the helper, then run it:
# Step 1: Write the helper script to /tmp
cat > /tmp/write_task.py << 'PYEOF'
import pathlib
content = r"""
// Your TypeScript / file content goes here
// Backticks `like this`, ${template} literals, and emoji π are all safe
export const MyComponent = () => {
const msg = `Hello, world!`;
return <div>{msg}</div>;
};
"""
pathlib.Path("/path/to/target/file.ts").write_text(content.lstrip("\n"), encoding="utf-8")
print("Written successfully.")
PYEOF
# Step 2: Execute the helper
python3 /tmp/write_task.py
Why
r"""? A raw triple-quoted string avoids all backslash escaping issues. The only content that cannot appear verbatim is"""itself β if needed, split the string or escape that sequence only.
Approach B β Base64-Encoded Content (most robust for binary/complex content)
When the content contains """ or other Python string edge cases:
# Step 1: Base64-encode your content (done once, outside the target system)
# python3 -c "import base64; print(base64.b64encode(open('file.ts').read().encode()).decode())"
# Step 2: Embed the base64 blob in the helper script
cat > /tmp/write_task.py << 'PYEOF'
import base64, pathlib
b64 = (
"aW1wb3J0IFJlYWN0IGZyb20gJ3JlYWN0JzsKCmV4cG9ydCBjb25zdCBNeUNvbXBvbmVudCA9"
"ICgpID0+IHsKICByZXR1cm4gPGRpdj5IZWxsbzwvZGl2PjsKfTsK"
# ... more lines if needed
)
content = base64.b64decode(b64).decode("utf-8")
pathlib.Path("/path/to/target/file.ts").write_text(content, encoding="utf-8")
print(f"Written {len(content)} bytes successfully.")
PYEOF
python3 /tmp/write_task.py
Approach C β shell_agent Delegation (simplest for agents)
Ask shell_agent to perform the write using the temp-script pattern:
"Write the following TypeScript content to
/src/components/MyPanel.ts. Do NOT usenode -eor inline Python. Instead write a Python script to/tmp/write_panel.pyusing a triple-quoted raw string, then execute it."
Decision Guide
| Situation | Recommended Approach |
|---|---|
Content has backticks / ${} template literals |
Approach A (raw r""") |
Content has """ sequences |
Approach B (base64) |
| Content is binary or non-UTF-8 | Approach B (base64) |
| Delegating to shell_agent | Approach C with explicit instructions |
| Quick small file | Direct write_file (no workaround needed) |
Anti-Patterns to Avoid
# β DANGEROUS β backtick template literals will break node -e
node -e "const fs = require('fs'); fs.writeFileSync('out.ts', \`${content}\`);"
# β FRAGILE β breaks on unescaped quotes and special characters
python3 -c "open('out.ts','w').write('${content}')"
# β UNRELIABLE for large payloads β may silently truncate
echo "${large_content}" > out.ts
Verification Step
Always verify the write succeeded:
# Check file exists and has non-zero size
python3 -c "
import pathlib
p = pathlib.Path('/path/to/target/file.ts')
assert p.exists() and p.stat().st_size > 0, f'Write failed: {p}'
print(f'OK β {p.stat().st_size} bytes written to {p}')
"
Notes
- The temp script approach works for any file type:
.ts,.tsx,.js,.json,.md,.py, etc. - Always
lstrip("\n")the triple-quoted string to avoid a leading blank line. - For very large files (>50 KB), prefer base64 to avoid any risk of heredoc conflicts.
- Clean up temp scripts after use:
rm /tmp/write_task.py
FAQ
Why does inline writing break?
The skill says backticks, template literals and quotes can be cut off or mangled when passed inline.
What is a raw string?
It is a Python string that keeps backslashes and special characters exactly as typed.
Where does the helper script go?
The skill uses a temp location such as /tmp, though a similar temp path can be used.
Details
Original description by the author
Reliable fallback technique for writing large or special-character-heavy file content when inline write_file or shell_agent calls fail with unknown errors β uses a Python helper script written to a temp file to avoid escaping and truncation pitfalls.
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #13059
- License
- MIT
- Updated
- 11/1/2026
Comments
- β¦
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.