Repository navigation
fix(hooks): quote CLAUDE_PLUGIN_ROOT in the four hook commands - #154
sydevs-bot wants to merge 2 commits into
Conversation
The repo's only automated gate has been failing on `main`.
`claude plugin validate ./workflow --strict` exits 1 on four warnings,
one per hook command, because each interpolates
`${CLAUDE_PLUGIN_ROOT}` into a shell command unquoted.
The failure is not cosmetic. With a space anywhere in the plugin root
the command splits into words and the hook never runs:
$ sh -c "$P/hooks/block-wrong-bash.mjs" # $P holds a space
sh: 1: /tmp/.../dir: not found
$ sh -c "\"$P/hooks/block-wrong-bash.mjs\""
(runs, exit 0)
Two of the four are PreToolUse blockers, so a silent non-run is a guard
that stops guarding. `~/Library/Application Support` and any user
directory with a space in it reach this.
Quoting is the validator's own first suggestion and the smaller of the
two it offers; the exec form would change how the command is invoked.
It cannot affect matcher logic. The gate now passes, and hooks are
still validated — checked by breaking a hook `type` deliberately and
seeing the validator reject it.
Found while implementing #146, in a file that ticket does not touch, so
it ships on its own.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01He4xaTae1P7ecgGPccgwBn
|
Adversarial review skipped: 1 file(s), 8 changed line(s), under 🤖 sydevs dispatcher |
`main` #147 landed the identical fix before this branch could, as its last commit ("fix(hooks): quote CLAUDE_PLUGIN_ROOT, so the lean gate can pass again"). Both sides edited the same four `hooks.json` commands for the same reason, in two spellings: main: "${CLAUDE_PLUGIN_ROOT}"/hooks/block-wrong-bash.mjs branch: "${CLAUDE_PLUGIN_ROOT}/hooks/block-wrong-bash.mjs" They are equivalent. The only component that can carry a space or a glob is the variable, which both quote; the literal `/hooks/<name>.mjs` suffix has no shell metacharacter. Verified against a path containing a space: the unquoted form exits 127 without running the hook, and both quoted forms run it and exit 0. So all four hunks take main's form — it is the spelling already committed, and #147 chose it deliberately ("the path is otherwise byte-identical"). No behaviour of this branch is lost by that, because main already has it. The merged tree is byte-identical to `origin/main`, so this PR now carries no net change and is superseded by #147. Lean gate `claude plugin validate ./workflow --strict` exits 0. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01VUoEJ16yrBt261JwbB5Vhs
|
Resolved, and the result is empty: the merged tree is byte-identical to #147 landed the same fix first, in its last commit. Both sides quoted the same four
They are equivalent. Only the variable can carry a space or a glob, and both sides quote it. The literal So all four hunks took main's form. It is the spelling already committed, and this branch loses no behaviour by it. This PR is superseded by #147 and carries no change. Closing it is yours. The lean gate exits 0. 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Summary
claude plugin validate ./workflow --strict— this repo's entire automated gate — has been exiting 1 onmain. This makes it pass.Change outline
Contract — how each hook command is handed to the shell
workflow/hooks/hooks.json, all four entries, one per line:Matchers, hook types, script bodies and the hook set are untouched. Quoting suppresses word-splitting and glob expansion of the path; it cannot reach matcher evaluation.
Test results
claude plugin validate ./workflow --strictexits 0. It exits 1 onmain, on exactly these four warnings.typedeliberately still gets a hard rejection naming thePreToolUseentry. The validator simply stops printing its "Validating hooks" line once it has nothing to report./security-review: triggered bysecurityReview.triggerPattern(^workflow/hooks/), no findings. The change removes two shell expansion steps and adds none.claude-workflowhas no test suite and is inci.noCi.Manual verification
claude plugin validate ./workflow --stricton this branch, then onmain. Exit 0 here, exit 1 there, same four warnings.claude --plugin-dir ./workflowstill loads the plugin, and anEditin a loaded session still triggersblock-generated-files.Notes for reviewer
Why this is not folded into #152. It is a defect found while implementing #146, in a file that ticket does not touch. One behaviour per PR, and this one reverts on its own.
Why quoting rather than the exec form. The validator offers both. Quoting is the smaller change and leaves invocation semantics alone;
{"command": …, "args": […]}would stop going through a shell at all, which is a bigger change to make unattended on a file whose hooks run in a maintainer's own session.Worth knowing the blast radius. Two of the four are
PreToolUseblockers, includingblock-wrong-bash.mjs, whichAGENTS.mdnotes has inverted once before (#16). A hook that fails to execute fails open — the tool call proceeds unguarded — so this was a guard that stopped guarding on any install path containing a space,~/Library/Application Supportamong them. That is why it is worth a PR rather than a ticket.🤖 Generated with Claude Code
https://claude.ai/code/session_01He4xaTae1P7ecgGPccgwBn
Generated by Claude Code