Skip to content

Conversation

@ajbmachon
Copy link

Summary

Fixes Python import errors (No module named 'hookify') in the hookify plugin when running in Claude Code's versioned plugin cache.

Problem

The hookify plugin's Python hooks fail to import core modules because:

  1. Original code assumed: parent_dir/hookify/core/... exists
  2. Claude Code's actual structure: .../cache/{marketplace}/{plugin}/{version}/core/...
  3. CLAUDE_PLUGIN_ROOT points to the versioned directory (e.g., .../hookify/0.1.0/)
  4. There's no nested hookify/ package inside - the code lives directly under the version directory
# Original (broken)
from hookify.core.config_loader import load_rules  # ❌ No 'hookify' package

# Fixed
from core.config_loader import load_rules  # ✅ Relative to PLUGIN_ROOT

Solution

  1. Add hooks/common.py - Centralizes import logic with correct sys.path handling
  2. Update all hook scripts - Import from common module (DRY principle)
  3. Fix core/rule_engine.py - Use relative imports (.config_loader)

Changes

File Change
hooks/common.py New shared module for imports and utilities
hooks/*.py Simplified to use common module
core/rule_engine.py Changed to relative import

Testing

Verified imports work correctly:

CLAUDE_PLUGIN_ROOT=.../hookify/0.1.0 python3 -c "from common import load_rules; print('OK')"
# Output: OK

Test plan

  • Install hookify plugin fresh
  • Verify no import errors on tool use
  • Test rule evaluation works correctly

The hookify plugin's Python hooks fail with "No module named 'hookify'"
in Claude Code's versioned plugin cache structure.

## Root Cause

The original code assumed a deployment structure where the parent directory
would contain a `hookify/` package:

```
expected: .../hookify/hookify/core/...  (parent has hookify package)
actual:   .../hookify/0.1.0/core/...    (CLAUDE_PLUGIN_ROOT is versioned dir)
```

Claude Code's plugin cache uses: `.../cache/{marketplace}/{plugin}/{version}/`
where `{version}/` IS the CLAUDE_PLUGIN_ROOT - there's no nested package.

## Solution

1. Add `hooks/common.py` - centralizes import logic and uses correct paths
2. Update all hook scripts to import from `common` module
3. Fix `core/rule_engine.py` to use relative imports (`.config_loader`)

This follows DRY principles - import logic is now in one place instead of
duplicated across 4 hook files.

## Changes

- `hooks/common.py` (new): Shared imports with correct sys.path handling
- `hooks/*.py`: Simplified to import from common module
- `core/rule_engine.py`: Changed to relative import for config_loader

Tested with CLAUDE_PLUGIN_ROOT pointing to versioned directory - imports
now resolve correctly.
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.

1 participant