Pass Multiline Prompts to Claude Code with Shell HEREDOCs
When you're scripting with claude --print, trying to cram a multi-point prompt into a single quoted string gets ugly fast. Shell HEREDOCs give you clean, readable multi-line prompts with no escaping.
claude --print << 'EOF'
Review the following code for:
1. Security vulnerabilities
2. Performance bottlenecks
3. Missing error handling
Respond with a bullet list for each category.
EOF
Single-quoting the delimiter ('EOF') prevents the shell from expanding variables inside the HEREDOC — useful when your prompt contains dollar signs or backticks. Drop the quotes when you want variable interpolation:
FILE="src/auth/middleware.ts"
CONTEXT="This is a financial application handling PII data."
claude --print << EOF
Context: $CONTEXT
Review $(basename $FILE) for security issues only.
Be brief — one sentence per issue.
$(cat $FILE)
EOF
This pattern works well in Makefiles too:
review:
@claude --print << 'EOF'
Summarise what changed in the last 5 commits and flag anything risky.
$(shell git log --oneline -5)
EOF
HEREDOCs make Claude automation scripts dramatically more readable than escaped single-liners.
Log in to leave a comment.
Before asking Claude to scaffold a new feature, point it at your existing code first — it will match your naming, structure, error handling, and test patterns exactly rather than defaulting to framework boilerplate.
Give Claude the full picture upfront before it writes any code, so it builds the right thing the first time with fewer correction rounds.
Long multi-step prompts with lots of context are harder to type than to speak — your brain can narrate relationships and constraints faster than your fingers can type them.