Skip to content

Fix hookify plugin imports missing CLAUDE_PLUGIN_ROOT fallback#31721

Open
RyanAlberts wants to merge 1 commit intoanthropics:mainfrom
RyanAlberts:fix-hookify-plugin-root-import
Open

Fix hookify plugin imports missing CLAUDE_PLUGIN_ROOT fallback#31721
RyanAlberts wants to merge 1 commit intoanthropics:mainfrom
RyanAlberts:fix-hookify-plugin-root-import

Conversation

@RyanAlberts
Copy link

Fixes #29842

When executing python hooks for the hookify plugin (pretooluse.py, posttooluse.py, stop.py, userpromptsubmit.py), the environment variable CLAUDE_PLUGIN_ROOT might not be present because it is only interpolated in the command string but not necessarily exported to the Python environment. This leads to Hookify import error: No module named 'core' because sys.path does not get updated correctly.

Changes Made

  • Modified the 4 python hook scripts to include a reliable __file__-based fallback: PLUGIN_ROOT = os.environ.get('CLAUDE_PLUGIN_ROOT') or os.path.dirname(os.path.dirname(os.path.abspath(__file__))).
  • This ensures that even if the CLAUDE_PLUGIN_ROOT environment variable is null, the script dynamically resolves the correct directory and updates sys.path, fixing the import crashes.

Made with Cursor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hookify plugin: Import error due to CLAUDE_PLUGIN_ROOT not available as env var

2 participants