When creating GitHub PRs, issues, or comments via gh CLI commands with multi-line markdown content, newlines are being escaped as literal \n strings instead of actual line breaks.
## Summary\n\nFix duplicate symbol errors...\n\n## Problem\n\nclip.cpp was being compiled twice...Instead of proper markdown with actual line breaks.
When passing multi-line strings to shell commands (especially via tool calls or string interpolation), the shell or the tool interprets newlines incorrectly:
- Direct string interpolation: Passing multi-line strings directly as arguments
- Tool call escaping: Some tools escape newlines as
\nliterals - Bash string handling: Unquoted or improperly quoted strings lose formatting
- Heredoc syntax errors: Missing quotes around EOF delimiter causes variable expansion
# CORRECT - quotes around EOF prevent interpretation
cat << 'EOF'
Line 1
Line 2
EOF
# WRONG - without quotes, variables get expanded
cat << EOF
$content
EOF# Create file with proper formatting
cat > /tmp/pr-body.md << 'MARKDOWN'
## Summary
Fix duplicate symbol errors.
## Changes
- Removed clip.cpp from server build
MARKDOWN
# Then use with gh CLI
gh pr create --body-file /tmp/pr-body.md# BEST PRACTICE - avoids all escaping issues
gh pr create --body-file /tmp/pr-body.md
gh issue comment 123 --body-file /tmp/comment.md# For short strings
gh pr create --body $'## Summary\n\nFix errors.\n\n## Changes\n\n- Fixed'# WRONG - newlines become literal \n
gh pr create --body "## Summary
Fix errors."
# WRONG - backslash escaping
gh pr create --body "## Summary\n\nFix errors"To detect if your markdown has this issue:
# Check raw PR body
gh pr view <number> --json body
# Test before posting
echo "$BODY_CONTENT"
# Look for literal \n in outputSymptoms:
- Rendered output shows
\nas text - No line breaks in markdown
- Lists appear as single line
- Always use
--body-filefor multi-line content - Use heredocs with quoted EOF:
<< 'EOF' - Test with echo before creating PRs
- Quote heredoc delimiters:
<< 'EOF'not<< EOF - Use
$'...'for embedded newlines in short strings - Avoid string concatenation with newlines
- Write to file first, then reference
- Use heredoc syntax when available
- Test output before final submission
- Prefer
--body-fileover inline body
#!/bin/bash
# Create PR with proper markdown formatting
# Step 1: Write body to file using heredoc
cat > /tmp/pr-body.md << 'MARKDOWN'
## Summary
Fix duplicate symbol errors by removing duplicate clip.cpp compilation.
## Problem
The clip.cpp file was being compiled twice:
1. In build_llama.zig (llama library)
2. In build_server.zig (server executable)
This caused duplicate symbol errors on Linux/BSD/Windows.
## Solution
Removed clip.cpp from build_server.zig since it's already included in the llama library.
## Impact
- ✅ Linux builds (gnu, musl)
- ✅ Windows builds (x86_64, aarch64)
- ✅ FreeBSD builds
- ✅ macOS builds (already working)
## Related
- Fixes CI failures in release workflow v0.3.1
MARKDOWN
# Step 2: Create PR using file
gh pr create \
--title "fix: Remove duplicate clip.cpp from server build" \
--body-file /tmp/pr-body.md \
--base master \
--head fix/duplicate-clip-symbols
# Cleanup
rm /tmp/pr-body.mdWhen AI agents execute tool calls with multi-line strings:
- The tool receives the string with escaped newlines (
\n) - Shell doesn't interpret
\nas newline without special handling - Result: literal backslash-n appears in output
Fix: Use file-based approach or proper heredoc syntax.
- See: SKILL: oh-my-opencode (OMO) Ralph Wiggum Loop & Agent Invocation
- See: SKILL: Spawning & Monitoring Background Coding Agents from Claude Code