fix(hookify): make hook entrypoints runnable without CLAUDE_PLUGIN_ROOT - #79889
Open
adelaidasofia wants to merge 1 commit into
Open
fix(hookify): make hook entrypoints runnable without CLAUDE_PLUGIN_ROOT#79889adelaidasofia wants to merge 1 commit into
adelaidasofia wants to merge 1 commit into
Conversation
All four hook entrypoints add the plugin to sys.path only when
CLAUDE_PLUGIN_ROOT is set:
PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT')
if PLUGIN_ROOT:
... sys.path.insert(...)
When the variable is absent the guard silently skips path setup, the
following `from hookify.core...` import fails, and the hook prints
{"systemMessage": "Hookify import error: No module named 'hookify'"} and
exits 0 - every rule for that event is inert.
The practical consequence is that the hooks are not runnable outside the
plugin harness. Piping a payload into pretooluse.py to test a rule fails
unless the caller happens to know to set the variable first, which makes
local rule development and debugging harder than it needs to be.
Fall back to the file's own location. Behavior is unchanged when
CLAUDE_PLUGIN_ROOT is set.
Verified on all four entrypoints with a real payload:
official + env var -> rule fires; official without -> import error
patched + env var -> rule fires; patched without -> rule fires
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
All four hook entrypoints add the plugin to
sys.pathonly whenCLAUDE_PLUGIN_ROOTis set:When the variable is absent the guard silently skips path setup, the following
from hookify.core...import fails, and the hook prints{"systemMessage": "Hookify import error: No module named 'hookify'"}and exits 0 — every rule for that event is inert.The practical consequence is that the hooks are not runnable outside the plugin harness. Piping a payload into
pretooluse.pyto test a rule fails unless the caller happens to know to set the variable first, which makes local rule development and debugging harder than it needs to be. (I hit this twice while testing rules against this plugin, and it silently masked an unrelated result until I noticed theimport errorstring in the output.)Fix
Fall back to the file's own location:
The
if PLUGIN_ROOT:guard becomes unnecessary (the value is now always resolvable), so its body is dedented. Behavior is unchanged whenCLAUDE_PLUGIN_ROOTis set — the env var still wins.Applied identically to
pretooluse.py,posttooluse.py,stop.py, anduserpromptsubmit.py.Verification
Real payload (
rm -rfagainst aevent: bashrule), official vs patched, with and without the variable:CLAUDE_PLUGIN_ROOTsetThe other three entrypoints were each driven with their own payload without the variable set and returned clean
{}instead of an import error.python3 -m py_compileclean on all four.🤖 Generated with Claude Code