Skip to content

fix: use tmpfile to avoid bash 3.2 apostrophe bug in agent launcher#262

Open
imsickofmaps wants to merge 1 commit into
marcus:mainfrom
imsickofmaps:fix/bash32-apostrophe-launcher
Open

fix: use tmpfile to avoid bash 3.2 apostrophe bug in agent launcher#262
imsickofmaps wants to merge 1 commit into
marcus:mainfrom
imsickofmaps:fix/bash32-apostrophe-launcher

Conversation

@imsickofmaps

Copy link
Copy Markdown

Problem

writeAgentLauncher generates start.sh scripts using a heredoc nested inside a $(...) command substitution:

claude "$(cat <<'SIDECAR_PROMPT_EOF'
...prompt with today's apostrophe...
SIDECAR_PROMPT_EOF
)"

macOS ships bash 3.2 (GPL2 constraint). Bash 3.2 has a known lexer bug: when scanning ahead for the closing )", it incorrectly tracks single-quote state across the heredoc body. Any apostrophe in the prompt — today's, don't, it's — causes:

start.sh: line N: unexpected EOF while looking for matching `''
start.sh: line N: syntax error: unexpected end of file

This silently breaks agent launch for any task description containing an apostrophe, which is extremely common.

Fix

Replace the nested heredoc with a tmpfile approach — write the prompt via a top-level heredoc (safe on all bash versions), then read it with a plain $(cat "$TMPFILE"):

TMPFILE=$(mktemp /tmp/sidecar-prompt.XXXXXX)
cat > "$TMPFILE" <<'SIDECAR_PROMPT_EOF'
...prompt with today's apostrophe...
SIDECAR_PROMPT_EOF
claude "$(cat "$TMPFILE")"
rm -f "$TMPFILE"

Applied to AgentAider, AgentOpenCode, and the default case. AgentAmp is unaffected — it already uses top-level stdin piping.

A regression test case with apostrophes in the prompt is included, along with assertions that non-Amp scripts use the tmpfile pattern.


A note on provenance: I'm not a Go programmer — I'm just an avid and very happy Sidecar user who hit this bug. This fix was written with Claude Code (with me pointing it at the bug report and reviewing the output). I've done my best to follow the project's patterns and test conventions, but please scrutinise the diff accordingly. Happy to iterate if anything's off.

macOS ships bash 3.2 which has a lexer bug: apostrophes inside heredoc
content nested within \$(...) cause a syntax error. Replace the nested
heredoc pattern with a tmpfile approach (top-level heredoc + cat) for
AgentAider, AgentOpenCode, and the default case. AgentAmp is unaffected
as it already uses top-level stdin piping.

Adds a regression test case with apostrophes in the prompt.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant