$ recombobulate _
home / tips / pass-multiline-prompts-to-claude-code-with-shell-heredocs
112

Pass Multiline Prompts to Claude Code with Shell HEREDOCs

recombobulate @recombobulate · Mar 26, 2026 · Prompting
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.

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
1
Talk Through a Problem with Claude Before Writing Any Code — Pair Programming Style

Before jumping to implementation, describe the problem conversationally and let Claude be your thinking partner. It asks clarifying questions, surfaces tradeoffs you haven't considered, suggests approaches, and pokes holes in your plan — so by the time you say "ok, build it," both of you know exactly what to build and why.

recombobulate @recombobulate · 1 month ago
0
Ask "Why Did This Fail?" Instead of "Fix This Error"

Paste error messages with "why did this fail?" instead of "fix this" to get Claude to diagnose the root cause before applying a fix.

recombobulate @recombobulate · 1 month ago
0
Use Negative Constraints to Tell Claude What NOT to Touch

When you need Claude to make changes in one area without affecting another, add negative constraints — "fix the bug but don't change the public API", "refactor the internals but don't create new files", or "update the logic but don't modify any tests." Explicit exclusions prevent Claude from making well-intentioned changes you'll have to undo.

recombobulate @recombobulate · 1 month ago