Repository navigation
Conversation
bash >= 5.1 writes heredocs into a pipe pre-fork; under macOS pipe pressure the kernel hands out 512-byte pipes and the wrapper's 1.4KB CMDBLOCK heredoc deadlocks every hook. Label lines parse nowhere: cmd.exe skips them as labels, POSIX shells exec away before the batch block. Also: silent fail-open when bash or the script name is missing, and CDPATH-proof directory resolution.
4 of 5 tasks
Owner
|
@arittr Full review pipeline ran on this today — summary before we merge:
Two questions before merging:
Holding until you confirm. — Claude Fable 5, Claude Code 2.1.228, reviewing on behalf of @obra |
4 of 5 tasks
arittr
added a commit
that referenced
this pull request
Nov 24, 2026
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.
Who is submitting this PR? (required)
claude-fable-5)What problem are you trying to solve?
hooks/run-hook.cmd— the wrapper every hook runs through — contained a~1.4KB heredoc (
: << 'CMDBLOCK'). On macOS, when the shell parsing it isbash >= 5.1 (e.g. Homebrew bash on PATH), the wrapper could deadlock before
any hook logic ran. #571 fixed this class of bug inside
hooks/session-startby switching to
printf, but the wrapper itself kept its heredoc, so thesame failure chain was still exposed at every compaction/session-start on
affected machines. This PR completes the fix #571 started by removing the
last heredoc from the hook delivery chain.
Mechanism (verified)
build-time pipe size (65536 on macOS) are written into a pipe before
the consumer is forked (
redir.c,here_document_to_fd). Linux re-checksthe live pipe capacity with
F_GETPIPE_SZ; macOS has no such fcntl.buffers. Bash's pre-fork write of a larger document then blocks forever.
For
: << 'X'the target is a builtin — no reader will ever exist todrain the pipe.
unreproducible at the time; session-start hook hangs on bash 5.3+ due to heredoc bug with large variable expansion #571's own ~512-byte idle threshold is
evidence the original reporter's machine was already under pipe pressure.
Session startup — many concurrent processes and pipes — is exactly when
it triggers.
BASH_COMPAT=50forces the temp-filedelivery path and sidesteps the hang; bash 5.1 and 5.2 have no escape
hatch.
Reproduction
Host: Darwin 25.6.0 (macOS 26.6), arm64-apple-darwin25 (aarch64-apple-darwin25.6.0
for self-built shells). Reproducer is the exact #571 case: a 520-byte
printf-generated heredoc body (s=$(printf "%0.s=" $(seq 520)); cat <<EOF\n${s}\nEOF) — the same heredoc-into-a-builtin shaperun-hook.cmd's: << 'CMDBLOCK'used — run once idle and once after holding filled pipesuntil macOS handed fresh pipes a shrunken 512-byte buffer, then released:
--version)GNU bash, version 5.1.16(1)-release (aarch64-apple-darwin25.6.0)GNU bash, version 5.2.37(1)-release (aarch64-apple-darwin25.6.0)GNU bash, version 5.3.9(1)-release (aarch64-apple-darwin25.6.0)GNU bash, version 3.2.57(1)-release (arm64-apple-darwin25)Every shell passes idle and only bash >= 5.1 hangs under pressure; capacity
was confirmed restored to 65536 immediately after release.
The wrapper itself was also driven directly, not just the abstracted case,
using the same pressure harness on the same machine (from-source bash
5.3.9, same build as above).
bash53/bash32/dashbelow are thefrom-source GNU bash 5.3.9 build, system
/bin/bash3.2.57, and/bin/dash; each invocation is<shell> run-hook.cmd <hook-name>with acompact JSON payload on stdin:
The shipped wrapper hangs under the same pressure condition that leaves
system bash 3.2 and dash unaffected parsing the identical file — confirming
the mechanism above against the actual
run-hook.cmd, not just theisolated reproducer.
Affected surfaces
hooks/hooks.jsonruns the wrapper with"shell": "bash"(PATH-resolved — Homebrew bash wins over
/bin/bashwhen installed).$SHELL -lc; a shebang-less wrapper reaches theENOEXEC fallback of whatever
$SHELLis. (Known pre-existing edge: a$SHELLwith no sh-fallback, e.g. fish, fails noisily either way — outof scope for this PR.)
from a hang to a silent 10s stall per fire, rather than fixing it.
What does this PR change?
Replaces the heredoc-based Unix half of
hooks/run-hook.cmdwith:;label lines: cmd.exe treats them as no-op labels and skips straight to the
batch block, while POSIX shells execute them as real commands and
execinto the target hook script before ever reaching the batch block — so no
heredoc exists anywhere in the parse path. Adds a repo-wide fence test
(
tests/hooks/test-no-heredocs-in-hooks.sh) that fails if anyhooks/executable contains a heredoc operator, a no-bash-on-PATH regression case
to
tests/hooks/test-session-start.sh, and updatesdocs/porting-to-a-new-harness.mdanddocs/windows/polyglot-hooks.mdtodescribe the new mechanism (they previously described the heredoc).
Behavior changes
Two silent-behavior changes fall out of the rewrite, both intentional:
shebang-less file would hit the ENOEXEC fallback and fail noisily with
exit 127 in most shells.
this was shell-dependent noisy nonzero (e.g. an unbound-variable error
under
set -u, or a bash usage error).run-hook.cmd: missing script name/ exit 1 error on zero args.Rationale: hooks are optional context injection, never a session breaker —
this matches the philosophy the Windows side already used (silent exit 0
when bash can't be found at all). Making the POSIX side consistent with
that philosophy, rather than leaving it to fail noisily depending on the
invoking shell, is a deliberate part of this fix, not a side effect.
Is this change appropriate for the core library?
Yes.
hooks/run-hook.cmdis the dispatcher every hook (session-start,etc.) runs through on every currently supported harness — it is core
infrastructure, not project-specific. Anyone running Superpowers on macOS
with a newer bash ahead of
/bin/bashon PATH (Homebrew's defaultinstallation location) is exposed to this hang; the fix benefits every
user in that configuration regardless of what they're building.
What alternatives did you consider?
the pressure condition can shrink a fresh pipe's buffer to as little as
512 bytes, which is smaller than the batch block content already needs
to be; the failure mode is triggered by the runtime environment, not
something the wrapper's own code size can reliably stay under.
BASH_COMPAT=50to force bash onto the temp-file deliverypath. Rejected: confirmed as a working escape hatch on bash 5.3 only
(see Diagnostic above) — bash 5.1 and 5.2 have no equivalent knob, so
this would leave two of the three affected versions still broken.
/bin/bash3.2. Rejected:fragile (requires locating a specific system binary that may not exist
or may itself be a newer bash on non-macOS systems), doesn't address
Linux users with bash >= 5.1 as their default
/bin/bash, and addsre-exec complexity to a wrapper that should stay minimal.
of this file. Rejected: fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175 has been open without merging, and this is
a correctness bug affecting every hook invocation on affected machines —
not a reason to block on an unrelated open PR. See Existing PRs below for
the conflict and rebase plan.
:;label-line polyglot (chosen). No heredoc exists anywhere in theparse path on either platform. Verified across bash 3.2.57, 5.1.16,
5.2.37, 5.3.9, and dash on the POSIX side, and cmd.exe with Git-for-Windows
bash on the Windows side (see Evaluation below).
Does this PR contain multiple unrelated changes?
No. Every file changed is required by this single fix: the wrapper rewrite
itself, the fence test and regression case that prove the heredoc is gone
and stays gone, and the two doc files that describe
run-hook.cmd'smechanism in prose and would otherwise describe the removed heredoc
incorrectly. (
git diff origin/dev...HEAD --stat—hooks/run-hook.cmd,tests/hooks/test-no-heredocs-in-hooks.sh,tests/hooks/test-session-start.sh,docs/porting-to-a-new-harness.md,docs/windows/polyglot-hooks.md.) Nothing here touches the Codex hookrevision work being tracked separately.
Existing PRs
I have reviewed all open AND closed PRs for duplicates or prior art
Related PRs: fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175, fix(hooks): discover per-user Git Bash and skip WSL stub on Windows #1864, docs: align Windows hook wrapper examples #1753, hooks: add explicit 10s timeout to SessionStart hooks #2020 (history: session-start hook hangs on bash 5.3+ due to heredoc bug with large variable expansion #571, run-hook.cmd bash discovery misses per-user Git install (%LOCALAPPDATA%\Programs\Git), falls through to WSL bash stub #1863, Codex SessionStart hook fails on Windows sandbox when run-hook.cmd invokes Git Bash #1867)
fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175 (open) rewrites the same Unix-half lines of
run-hook.cmd, andalso touches
hooks-codex.json/codex-tools.md. This PR conflictstextually with fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175 — if fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175 lands first, this PR will need a rebase.
The conflict is mechanical, not architectural: the
:;mechanism this PRships is compatible with fix(hooks): use SCRIPT_NAME variable in run-hook.cmd to avoid arg-par… #1175's
SCRIPT_NAME-variable approach, whichthis PR's wrapper already adopts (see the
SCRIPT_NAME="$1"line).fix(hooks): discover per-user Git Bash and skip WSL stub on Windows #1864 (open) batch-blocks Git-bash discovery in the same file but
doesn't touch the lines this PR changes — no conflict.
docs: align Windows hook wrapper examples #1753 wrapper doc examples — adjacent only, no textual conflict.
hooks: add explicit 10s timeout to SessionStart hooks #2020 (open) adds a 10s SessionStart timeout — complementary, not
conflicting: absent this PR, hooks: add explicit 10s timeout to SessionStart hooks #2020 would turn the heredoc hang into a
silent 10s stall on every affected fire rather than fixing it.
History: session-start hook hangs on bash 5.3+ due to heredoc bug with large variable expansion #571 is the partial fix this PR completes (it fixed the
heredoc-deadlock class inside
hooks/session-startbut left thiswrapper's own heredoc in place). run-hook.cmd bash discovery misses per-user Git install (%LOCALAPPDATA%\Programs\Git), falls through to WSL bash stub #1863/Codex SessionStart hook fails on Windows sandbox when run-hook.cmd invokes Git Bash #1867 are the related
Windows bash-discovery threads; untouched by this PR.
Environment tested
claude-fable-5New harness support (required if this PR adds a new harness)
Not applicable. This PR does not add support for a new harness — it fixes
a dispatch bug in the existing cross-platform wrapper (
hooks/run-hook.cmd)already used by every currently supported harness.
Evaluation
Initial prompt: This PR originated from a structured investigation
(SDD brief
2026-08-05-heredoc-hardening-and-codex-hook-revision) intowhether the heredoc-deadlock class fixed in #571 for
hooks/session-startwas still present anywhere else in the hook dispatch chain.
hooks/run-hook.cmd'sown
: << 'CMDBLOCK'heredoc was identified and confirmed as the samedefect class via the mechanism and reproduction evidence above.
Eval sessions run after making the change: four independent
verification passes against the final committed wrapper (commit
d80fc180):POSIX matrix (dash, system bash 3.2.57, and self-built bash 5.1.16 /
5.2.37 / 5.3.9 — 5 shells x direct-invocation +
-lc= 10 cases, plus ano-bash-on-PATH case and a zero-arg case):
(Bash-path lines abbreviated to
.../bash-5.N/bash, matching the sourcematrix file's own abbreviation.) All 10 direct/
-lcinvocations printthe expected
PROBE-OKline; the no-bash and zero-arg cases both printnothing and exit 0, as designed.
Pressure A/B — old (heredoc) wrapper vs. new (
:;label) wrapper,the direct before/after comparison, run once under a single pipe-pressure
window across bash 5.1.16 / 5.2.37 / 5.3.9 (6 shell x wrapper combos):
Windows 11 cmd.exe matrix (physical Windows 11 10.0.26200 host,
Git-for-Windows bash, files transferred LF-only, executed via
cmd /c):Repo test suites, run locally:
tests/hooks/test-no-heredocs-in-hooks.sh(
[PASS] hooks/run-hook.cmd is heredoc-free,[PASS] hooks/session-start is heredoc-free,STATUS: PASSED) andtests/hooks/test-session-start.sh,7/7 passing including the new
wrapper with no bash on PATH is silent and exits 0case.Outcome change compared to before: the pressure A/B is the clean
before/after — under identical pipe pressure, the old heredoc-based wrapper
hangs on all 3 tested bash versions (5.1, 5.2, 5.3.9) and the new wrapper
succeeds on all 3, with zero regressions across dash, system bash 3.2.57,
and cmd.exe in every matrix. Every invocation across all four passes
matched its expected outcome exactly; the only deviations from prior
behavior are the two intentional silent-exit-0 changes documented above.
Rigor
content, only
hooks/,tests/hooks/, and two doc files.pipe-pressure deadlock condition, no-bash-on-PATH, zero-argument
invocation, and a physical Windows 11 host were all exercised, not
just the straight-line success case.
rationalizations, "human partner" language) — this PR does not touch
any skill files.
Human review
Drew Ritter reviewed the complete diff and this PR body on 2026-08-05
before the PR was opened.