fix(hookify): fall back to __file__ when CLAUDE_PLUGIN_ROOT is unset#1441
Closed
adelaidasofia wants to merge 1 commit intoanthropics:mainfrom
Closed
fix(hookify): fall back to __file__ when CLAUDE_PLUGIN_ROOT is unset#1441adelaidasofia wants to merge 1 commit intoanthropics:mainfrom
adelaidasofia wants to merge 1 commit intoanthropics:mainfrom
Conversation
Hook scripts depend on CLAUDE_PLUGIN_ROOT to add the plugin directory to sys.path so they can import core.config_loader and core.rule_engine. In some Claude Code contexts (observed in git worktrees and certain subagent subprocesses) the env var is not set on the spawned hook process. When that happens the imports fail, the script emits a systemMessage, and PreToolUse defaults to BLOCK, silently blocking every Write, Edit, and Bash call for the session. Since the script already knows its own location, it can derive the plugin root from __file__ as a fallback. This preserves the existing env-var path, adds no runtime cost, and makes the hooks robust to any spawning context. Verified: all four hook scripts now return an empty JSON object and exit 0 when piped stdin input with CLAUDE_PLUGIN_ROOT unset.
|
Thanks for your interest! This repo only accepts contributions from Anthropic team members. If you'd like to submit a plugin to the marketplace, please submit your plugin here. |
adelaidasofia
added a commit
to adelaidasofia/ai-brain-starter
that referenced
this pull request
Apr 16, 2026
The links pointed to anthropics/claude-code/tree/main/plugins/hookify. The hookify plugin actually lives in the separate marketplace repo anthropics/claude-plugins-official. Both references updated. Found while filing anthropics/claude-plugins-official#1441 (unrelated CLAUDE_PLUGIN_ROOT fallback fix in hookify itself). Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Problem
The four hook scripts in
plugins/hookify/hooks/depend onCLAUDE_PLUGIN_ROOTto add the plugin directory tosys.pathso they can importcore.config_loaderandcore.rule_engine:In some contexts Claude Code does not set
CLAUDE_PLUGIN_ROOTon the subprocess it spawns for the hook. When that happens the imports fail, the script emits asystemMessage, and PreToolUse defaults to BLOCK, silently blocking everyWrite,Edit, andBashcall for the session.I hit this reliably in git worktree sessions and some subagent contexts. The error the user sees is:
Even with
sys.exit(0), the non-emptysystemMessageand failed import are enough for the host to treat the PreToolUse hook as failed.Fix
Since the script already knows its own location, it can derive the plugin root from
__file__as a fallback. The env-var path still takes precedence, so existing behavior is preserved.Same pattern applied to all four hook scripts (
pretooluse.py,posttooluse.py,stop.py,userpromptsubmit.py).Verification
All four scripts return
{}and exit 0 when piped stdin input withCLAUDE_PLUGIN_ROOTunset:Before the patch the same commands produced
{"systemMessage": "Hookify import error: No module named 'core'"}.