Skip to content

fix(hooks): quote CLAUDE_PLUGIN_ROOT in the four hook commands - #154

Closed
sydevs-bot wants to merge 2 commits into
mainfrom
claude/fix-hooks-quote-plugin-root
Closed

sydevs-bot wants to merge 2 commits into
mainfrom
claude/fix-hooks-quote-plugin-root

Conversation

@sydevs-bot

Copy link
Copy Markdown
Contributor

Summary

  • claude plugin validate ./workflow --strict — this repo's entire automated gate — has been exiting 1 on main. This makes it pass.
  • The four warnings were real: with a space in the plugin root, a hook command splits into words and the hook silently never runs.

Change outline

Contract — how each hook command is handed to the shell

workflow/hooks/hooks.json, all four entries, one per line:

- command: ${CLAUDE_PLUGIN_ROOT}/hooks/block-generated-files.mjs      PreToolUse  Edit|Write
- command: ${CLAUDE_PLUGIN_ROOT}/hooks/block-wrong-bash.mjs           PreToolUse  Bash
- command: ${CLAUDE_PLUGIN_ROOT}/hooks/prettier-format.mjs            PostToolUse Edit|Write
- command: ${CLAUDE_PLUGIN_ROOT}/hooks/eslint-fix.mjs                 PostToolUse Edit|Write
+ command: "${CLAUDE_PLUGIN_ROOT}/hooks/block-generated-files.mjs"    PreToolUse  Edit|Write
+ command: "${CLAUDE_PLUGIN_ROOT}/hooks/block-wrong-bash.mjs"         PreToolUse  Bash
+ command: "${CLAUDE_PLUGIN_ROOT}/hooks/prettier-format.mjs"          PostToolUse Edit|Write
+ command: "${CLAUDE_PLUGIN_ROOT}/hooks/eslint-fix.mjs"               PostToolUse Edit|Write

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

  • Lean gate: ✓ claude plugin validate ./workflow --strict exits 0. It exits 1 on main, on exactly these four warnings.
  • Reproduced the underlying failure first, with a space in the path:
$ sh -c "$P/hooks/block-wrong-bash.mjs"          # unquoted, $P contains a space
sh: 1: /tmp/.../dir: not found                   # hook does not run
$ sh -c "\"$P/hooks/block-wrong-bash.mjs\""      # quoted
(runs, exit 0)
  • Hooks are still validated after the change, not skipped: breaking a hook's type deliberately still gets a hard rejection naming the PreToolUse entry. The validator simply stops printing its "Validating hooks" line once it has nothing to report.
  • /security-review: triggered by securityReview.triggerPattern (^workflow/hooks/), no findings. The change removes two shell expansion steps and adds none.
  • Targeted specs: none — claude-workflow has no test suite and is in ci.noCi.

Manual verification

  1. Confirm the gate: claude plugin validate ./workflow --strict on this branch, then on main. Exit 0 here, exit 1 there, same four warnings.
  2. claude --plugin-dir ./workflow still loads the plugin, and an Edit in a loaded session still triggers block-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 PreToolUse blockers, including block-wrong-bash.mjs, which AGENTS.md notes 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 Support among 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

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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Adversarial review skipped: 1 file(s), 8 changed line(s), under review.skipWhen. Say @sydevs-bot review to force one.

🤖 sydevs dispatcher

@sydevs-bot sydevs-bot added bot:working Lock: a cloud session is running on this item. Removed when it ends. and removed awaiting labels Oct 5, 2026
@sydevs-bot

sydevs-bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 23:53Z resolve-conflicts · attempt 1 · session · done
  • 23:53Z resolve-conflicts · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

`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
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Resolved, and the result is empty: the merged tree is byte-identical to main.

#147 landed the same fix first, in its last commit. Both sides quoted the same four hooks.json commands, in two spellings:

  • main: "${CLAUDE_PLUGIN_ROOT}"/hooks/block-wrong-bash.mjs
  • here: "${CLAUDE_PLUGIN_ROOT}/hooks/block-wrong-bash.mjs"

They are equivalent. Only the variable can carry a space or a glob, and both sides quote it. The literal /hooks/<name>.mjs suffix has no shell metacharacter. Checked against a path containing a space: the unquoted form exits 127 without running the hook, and both quoted forms exit 0.

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

@sydevs-bot sydevs-bot added awaiting and removed bot:working Lock: a cloud session is running on this item. Removed when it ends. labels Oct 5, 2026
@Ardnived Ardnived closed this Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants