Skip to content

hookify: Rules not loaded - config_loader.py uses relative path instead of CLAUDE_PROJECT_DIR #309

@MrBogomips

Description

@MrBogomips

Bug Description

The hookify plugin's config_loader.py uses a relative path to find rule files, which fails because hooks execute from the plugin's cache directory, not the project directory.

Current Behavior

In core/config_loader.py line 210-211:

pattern = os.path.join('.claude', 'hookify.*.local.md')
files = glob.glob(pattern)

This glob searches relative to the current working directory. When hooks run, the CWD is not the user's project directory, so no rule files are found.

Expected Behavior

The plugin should use CLAUDE_PROJECT_DIR environment variable (which is available to hook subprocesses) to construct an absolute path:

project_dir = os.environ.get('CLAUDE_PROJECT_DIR', '.')
pattern = os.path.join(project_dir, '.claude', 'hookify.*.local.md')
files = glob.glob(pattern)

Steps to Reproduce

  1. Create a hookify rule file: .claude/hookify.test-rule.local.md
  2. Run /hookify:list - the rule appears correctly
  3. Trigger the rule (e.g., run a git commit that matches the pattern)
  4. The rule doesn't fire because load_rules() finds no files

Environment

  • Claude Code version: Latest
  • Hookify plugin version: 0.1.0
  • OS: macOS

Suggested Fix

Update load_rules() in core/config_loader.py:

def load_rules(event: Optional[str] = None) -> List[Rule]:
    """Load all hookify rules from .claude directory."""
    rules = []

    # Use CLAUDE_PROJECT_DIR when available (hook execution context)
    project_dir = os.environ.get('CLAUDE_PROJECT_DIR', '.')
    pattern = os.path.join(project_dir, '.claude', 'hookify.*.local.md')
    files = glob.glob(pattern)
    # ... rest of function

This change ensures rules are found whether the code runs from the project directory or from a hook subprocess.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions