fix(hook): macOS bash 3.2 compatibility (mapfile + empty-array under set -u)#9
Merged
Merged
Conversation
mapfile is a bash 4.0+ builtin but macOS ships bash 3.2.57, so the
SessionStart hook died with "mapfile: command not found" on every Mac.
- Replace `mapfile -t apps` with a portable `while IFS= read -r` loop.
- Init `local apps=()` + guard ${#apps[@]} before "${apps[@]}" expansion,
which raises "unbound variable" on empty arrays under bash 3.2 + set -u.
- CI: add macos-latest matrix + a step that runs the hook under system
/bin/bash (3.2) and fails on command-not-found / unbound-variable.
Fixes MakFly#8
|
BTW it will work if my main terminal is with zsh? |
Owner
|
Thanks for the thorough fix — and especially for adding the macOS / bash 3.2 regression guard in CI. That Linux-only matrix was exactly the gap that let this slip through. Reviewed the diff: the Merging now — it'll ship in v0.0.1. Appreciate the clean write-up. 🙌 |
This was referenced Jun 16, 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.
Problem
The
SessionStarthook crashes on macOS withsession-start.sh: line 229: mapfile: command not found, producing aSessionStart:startup hook erroron every Claude Code session start on a Mac.mapfile/readarrayis a bash 4.0+ builtin; macOS ships bash 3.2.57 as the system bash at/bin/bash, and#!/usr/bin/env bashresolves to it on a stock Mac.Closes #8.
Changes
hooks/session-start.shmapfile -t apps < <(...)with a portablewhile IFS= read -rloop — works on bash 3.2, 4 and 5.local apps=()and guardif [[ ${#apps[@]} -gt 0 ]]beforeprintf '%s\n' "${apps[@]}". Underset -u(the script usesset -euo pipefail), expanding an empty array as"${apps[@]}"raisesapps[@]: unbound variableon bash < 4.4 — this was a second latent instance of the same class, surfacing whenever the hook runs outside a Symfony project..github/workflows/test-session-start.yml(regression guard — this is why the bug slipped through: CI was Linux-only / bash 5)[ubuntu-latest, macos-latest]matrix./bin/bash(3.2 on macOS) for both the empty-dir and mock-Symfony cases, and fails on anycommand not found/unbound variable/mapfilein output.bash -nlint now also runs under/bin/bashwhere present.Verification (local, macOS
/bin/bash3.2.57)The new CI step was confirmed to fail against the current (unfixed) script and pass against this branch, so it genuinely guards the regression.
Notes
mapfile+ unguarded expansion there.