Skip to content

fix(hookify): fix Python import path for cached plugins#13681

Open
saasom wants to merge 1 commit intoanthropics:mainfrom
saasom:fix/hookify-python-import-path
Open

fix(hookify): fix Python import path for cached plugins#13681
saasom wants to merge 1 commit intoanthropics:mainfrom
saasom:fix/hookify-python-import-path

Conversation

@saasom
Copy link
Copy Markdown

@saasom saasom commented Dec 11, 2025

Summary

Fixes the hookify plugin's Python import path issue that occurs when plugins are cached by Claude Code.

The Problem:
When Claude Code caches plugins, it creates a versioned directory structure:

~/.claude/plugins/cache/claude-code-plugins/hookify/0.1.0/core/config_loader.py

The original code tried to import using package-style imports:

from hookify.core.config_loader import load_rules

This fails because:

  1. CLAUDE_PLUGIN_ROOT points to .../hookify/0.1.0/
  2. The code adds parent_dir (.../hookify/) to sys.path
  3. Python looks for a hookify directory with core/ inside it
  4. But the actual structure is hookify/0.1.0/core/ - the version directory breaks the package path

The Fix:
Since PLUGIN_ROOT is already added to sys.path and points directly to the versioned directory (.../0.1.0/), we can import directly:

from core.config_loader import load_rules

This works because core/ is a direct child of PLUGIN_ROOT.

Files Changed

  • plugins/hookify/hooks/stop.py - Updated imports and path setup
  • plugins/hookify/hooks/pretooluse.py - Updated imports and path setup
  • plugins/hookify/hooks/posttooluse.py - Updated imports and path setup
  • plugins/hookify/hooks/userpromptsubmit.py - Updated imports and path setup
  • plugins/hookify/core/rule_engine.py - Updated internal imports

Test Plan

  • Verified imports work with simulated cached plugin structure
  • Manual testing with fresh plugin installation
  • Verify all hook events (Stop, PreToolUse, PostToolUse, UserPromptSubmit) work correctly

Reproduction Steps (for the original bug)

  1. Install the hookify plugin via marketplace
  2. Observe error on Stop hook: Hookify import error: No module named 'hookify'
  3. Check ~/.claude/plugins/cache/claude-code-plugins/hookify/ to see versioned structure

When plugins are cached by Claude Code, the directory structure becomes
`hookify/<version>/core/` instead of `hookify/core/`. This breaks the
`from hookify.core.X import Y` imports because Python looks for a
`hookify` subdirectory within the paths in sys.path.

The fix changes imports to use direct module paths (`from core.X import Y`)
since CLAUDE_PLUGIN_ROOT is already added to sys.path and points to the
versioned directory containing the `core/` module.

Affected files:
- hooks/stop.py
- hooks/pretooluse.py
- hooks/posttooluse.py
- hooks/userpromptsubmit.py
- core/rule_engine.py

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@adrozdenko
Copy link
Copy Markdown

Hey @saasom! 👋

The import path issue you're fixing is handled in hookify-plus via symlink installation.

hookify-plus aggregates community fixes that Anthropic hasn't merged (10+ PRs sitting open). Feel free to use it while waiting for upstream review! 🚀

ln -s /path/to/hookify-plus ~/.claude/plugins/cache/claude-code-plugins/hookify/0.1.0

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.

2 participants