Conversation
bash 3.2's $(...) scanner does not recognise a heredoc opened inside it: it
scans the body as shell text while hunting for the matching ')', so an
apostrophe in the body ("company's") opens a quote it never closes. Bash 5
parses it fine, so bash -n on a bash-5-only machine cannot reproduce this.
Rebuilt block="$(cat <<EOF ...)" as IFS= read -r -d '' block <<EOF ... EOF,
which keeps every caller's byte-identical output (verified against
init-company-brain.sh + init-project.sh --company: word count, path
resolution, registry, re-wire idempotency, re-point rewrite all unchanged).
The same trap was live in claude-hooks/hooks/context-ceiling.sh and
context-watch.sh (a heredoc feeding python's stdin inside $(...)); fixed the
same way and re-verified end to end against a synthetic transcript (both
correctly computed ctx=6000 from the newest usage record).
Added a bin/check-portability.sh check for the pattern. The raw grep
(\$\([^)]*<<[^<]) false-triggered on $((...)) arithmetic left-shift and <<<
here-strings, so both are stripped before matching; the refined check has
zero hits on the fixed tree and correctly flags a synthetic reintroduction
of the bug.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VJgWP5vEoAsNsJYqCDMGNw
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lane: Direct
What changed and why (one paragraph)
A colleague's
doctor.shrun on macOS reportedbin/wire-company-brain.shunparseable (lines 82/85). Root cause: the script built its marker block with a heredoc inside$(cat <<BLK … BLK). bash 3.2's command-substitution scanner does not recognise a heredoc opened inside$(...); it reads the body as shell text, and the apostrophe in "company's" opens a quote it never closes. bash 5 parses it fine, which is whybash -nhere never caught it. The block is now read withIFS= read -r -d '' block <<BLK || trueand the trailing newline stripped, so the output is byte-identical. The same trap was live inclaude-hooks/hooks/context-ceiling.shandcontext-watch.sh(a heredoc feeding python's stdin inside$(...)); both fixed the same way.bin/check-portability.shgains a rule for the pattern so it cannot come back, with<<<here-strings and$((...))arithmetic stripped first because both false-triggered the raw grep.Field evidence
doctor.shFAIL on macOS stock bash 3.2.57 (screenshot, chat-only).bash -nclean on all four scripts;bin/check-portability.shclean on the branch (163 files).$(cat <<BLK)form; the two hooks re-verified against a synthetic transcript.<<<and$((x<<2))are not.read -d '') is bash 3.2-native and used elsewhere in this repo.Checklist
check-portability.shchange is a new rule with the false-positive exclusions it needed; no new artifact consumer## Unreleased🤖 Generated with Claude Code
https://claude.ai/code/session_01VJgWP5vEoAsNsJYqCDMGNw
Generated by Claude Code