fix(hooks): use ${CLAUDE_PLUGIN_ROOT} instead of ${CLAUDE_SKILL_DIR}#968
Open
ivansamartino wants to merge 1 commit intogarrytan:mainfrom
Open
fix(hooks): use ${CLAUDE_PLUGIN_ROOT} instead of ${CLAUDE_SKILL_DIR}#968ivansamartino wants to merge 1 commit intogarrytan:mainfrom
ivansamartino wants to merge 1 commit intogarrytan:mainfrom
Conversation
Claude Code's skill-hook runtime only substitutes and exports
${CLAUDE_PLUGIN_ROOT} for hooks registered via a skill's frontmatter —
${CLAUDE_SKILL_DIR} is not a recognized variable. It is never exported
and never template-expanded, so bash expands it to the empty string at
hook-execution time, producing paths like "/../freeze/bin/check-freeze.sh"
and failing every PreToolUse Write/Edit/Bash invocation while the skill
is active. Because gstack marks these hooks as non-blocking, the error
was cosmetic rather than catastrophic — but it also meant the freeze
and careful boundary checks these hooks were supposed to enforce never
actually ran for any user.
Substituting ${CLAUDE_PLUGIN_ROOT} resolves the variable against the
skill's own install directory, which is exactly what the sibling-path
references (guard, investigate, ship) and own-dir references (freeze,
careful) both need.
Changes:
- freeze/SKILL.md.tmpl: own-dir hook commands
- careful/SKILL.md.tmpl: own-dir hook command
- guard/SKILL.md.tmpl: sibling hook commands (3×)
- investigate/SKILL.md.tmpl: sibling hook commands (2×) + availability probe
- ship/SKILL.md.tmpl: document-release cat reference in Step 8.5
- scripts/resolvers/review.ts: qa-only cat reference in ship Step 5.3
- Regenerated corresponding SKILL.md files via `bun run gen:skill-docs`
Tests: hook-scripts.test.ts passes 32/32. host-config.test.ts shows the
same 3 pre-existing golden-file-regression failures that exist on main
(stale test/fixtures/golden/*.md) — unrelated to this change.
Fixes garrytan#961
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.
Summary
Replaces
\${CLAUDE_SKILL_DIR}with\${CLAUDE_PLUGIN_ROOT}throughout the skill-registered hook commands (and adjacent skill-body references) infreeze,careful,guard,investigate, andship. Claude Code does not define\${CLAUDE_SKILL_DIR}— the only variable it substitutes for hooks registered via a skill's frontmatter is\${CLAUDE_PLUGIN_ROOT}, which points at the skill's install directory.Fixes #961.
What was broken
Every time a skill with a
\${CLAUDE_SKILL_DIR}hook was loaded into a Claude Code session, the subsequentWrite/Edit/Bashtool calls failed with:```
PreToolUse:Write hook error
Failed with non-blocking status code: bash: /../freeze/bin/check-freeze.sh: No such file or directory
```
Bash expanded the undefined
\${CLAUDE_SKILL_DIR}to the empty string at hook execution time, producing paths rooted at/that don't exist. Because the hooks are non-blocking, tool calls still succeeded — so this presented as noise in the transcript rather than a hard failure. But it also meant the freeze-boundary and careful-command checks these hooks were supposed to enforce never actually ran for any user: thecheck-freeze.sh/check-careful.shscript was never reached.I reproduced this on gstack `0.16.2.0` (commit `dbd7aee5`, branch base) with Claude Code `2.1.101` native binary on macOS (arm64), where I verified against the compiled binary that:
\${CLAUDE_PLUGIN_ROOT}is whitelisted, substituted, and exported into the hook process env (value = skill install directory).\${CLAUDE_PLUGIN_DATA}is plugin-scoped and rejected for skill hooks (error message: `Hook command references ${...} but only ${CLAUDE_PLUGIN_ROOT} is available for skill hooks (${CLAUDE_PLUGIN_DATA} is plugin-only)`).\${CLAUDE_SKILL_DIR}is not referenced anywhere in the binary — it isn't substituted and isn't exported.The fix is a mechanical `s/CLAUDE_SKILL_DIR/CLAUDE_PLUGIN_ROOT/` across the 6 source files that feed the generator, followed by regenerating the committed `SKILL.md` outputs via `bun run gen:skill-docs --host all`. The sibling-path structure (`${CLAUDE_PLUGIN_ROOT}/../freeze/bin/check-freeze.sh` in `guard`/`investigate`) continues to work because Claude Code points `${CLAUDE_PLUGIN_ROOT}` at the skill's own directory and its siblings are reachable via `..`.
Files changed
22 lines changed across 11 files.
Testing
Notes for reviewers
name: ...frontmatter in the 5 patched `SKILL.md` files is unchanged, so skill routing/discovery is unaffected.