Skip to content
Skillpedia
General coding7.8k · #12891

heredoc-file-write

What it does

This skill gives the AI a backup way to save code files when the normal file writer keeps failing on quotes, escapes or special characters. It is for people whose AI tasks create React, TypeScript or JSON files.

When to use it

  • ✓When the file writer fails repeatedly on the same code file with an unknown error.
  • ✓When a code file has nested quotes, escape characters or other tricky syntax.
  • ✓When I need a reliable way to create a code file from the shell.

Skill link

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/heredoc-file-write/SKILL.md

Copy 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

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/heredoc-file-write/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“The file writer keeps failing on my React component file because of the quotes. Please save it another way.”

5 new skills a week. 1 minute to read.

How it works

The AI runs a cat command with a quoted heredoc marker, which writes the code exactly as given, without the shell changing any characters inside it.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Heredoc File Write Workaround

When to Use This Skill

Use this pattern when:

  • write_file repeatedly fails with "unknown error" or similar messages
  • The target file contains complex code (TypeScript, JSX, JSON with special characters, etc.)
  • Standard file writing approaches encounter encoding or escaping issues
  • You need a reliable fallback method to create files

Core Technique

Switch from write_file to run_shell using heredoc syntax with cat. The heredoc approach handles special characters, quotes, and complex content more reliably.

Step-by-Step Instructions

Step 1: Identify Write Failures

When write_file fails repeatedly on the same file:

  1. Note the error message (e.g., "unknown error", encoding issues)
  2. Review the file content for special characters, nested quotes, or complex syntax
  3. Attempt the heredoc workaround below

Step 2: Use Heredoc Syntax

Execute shell command with heredoc:

cat > /path/to/file.tsx << 'EOF'
// Your file content here
import React from 'react';
const Component = () => {
  return <div>Hello</div>;
};
export default Component;
EOF

Step 3: Key Heredoc Rules

  1. Use quoted delimiter ('EOF' not EOF) to prevent variable expansion:

    • 'EOF' = literal content (recommended for code files)
    • EOF = allows variable expansion (use only if needed)
  2. Match delimiters exactly: Opening and closing EOF must be on their own lines with no leading/trailing whitespace

  3. No escaping needed: Content between delimiters is taken literally when using quoted delimiter

Step 4: Verify File Creation

After executing the heredoc command:

  1. Check if file exists: ls -la /path/to/file.tsx
  2. Verify content: cat /path/to/file.tsx or head -20 /path/to/file.tsx
  3. Proceed with subsequent tasks once confirmed

Example Scenarios

TypeScript/JSX Component

cat > src/components/Button.tsx << 'EOF'
import React from 'react';

interface ButtonProps {
  label: string;
  onClick: () => void;
}

export const Button: React.FC<ButtonProps> = ({ label, onClick }) => {
  return (
    <button onClick={onClick} className="btn-primary">
      {label}
    </button>
  );
};
EOF

JSON Configuration

cat > tsconfig.json << 'EOF'
{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true
  },
  "include": ["src/**/*"]
}
EOF

Complex Shell Script

cat > deploy.sh << 'EOF'
#!/bin/bash
set -e

echo "Deploying..."
if [ "$ENV" = "production" ]; then
  echo "Production deployment"
fi
EOF

Advantages Over write_file

  1. No escaping complexity: Quotes, backslashes, and special characters work naturally
  2. Preserves formatting: Indentation and line breaks remain exact
  3. Handles multi-line content: No need to concatenate strings or use base64
  4. More reliable: Shell handles file I/O directly with fewer abstraction layers

Limitations

  • Creates files in shell execution context (ensure correct working directory)
  • Less programmatic than write_file for dynamic content generation
  • Requires shell access (may not work in restricted environments)

Troubleshooting

Problem: File not created at expected path

  • Solution: Use absolute paths or verify current working directory with pwd

Problem: Content appears corrupted

  • Solution: Ensure delimiter is quoted ('EOF') and closing delimiter has no trailing whitespace

Problem: Permission denied

  • Solution: Ensure target directory exists and you have write permissions
FAQ

Why does the quoted marker matter?

A quoted marker stops the shell from changing dollar signs or other symbols inside the code.

Which code types are mentioned?

The guide mentions TypeScript, JSX and JSON files with special characters.

What must the closing marker look like?

The closing marker must match the opening marker exactly and sit on its own line.

Details

Original description by the author

Use shell heredoc syntax as a workaround when write_file fails on complex TypeScript/JSX/code files with encoding or escaping issues

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12891
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills