Skip to content

Plugin hooks not registered when another plugin already registered hooks with same matcher #3048

Description

@xiaolongzuo

Before submitting


📝 Manual Bug Report

Bug Description

When claude-mem is installed alongside another plugin that has already registered hooks with
matcher: "*", the npx claude-mem repair command does not register claude-mem's hooks into
settings.json. This results in observations never being captured, making the memory system
non-functional.

Additionally, even after manually fixing the hooks registration, there's a model compatibility
issue
: when using a corporate LLM proxy that doesn't support Claude models, the SDK returns 401
error and observations are discarded.

Steps to Reproduce

Part 1: Hooks not registered

  1. Install another plugin (e.g., a corporate wrapper like my-corp-cli) that registers hooks with
    matcher: "*" in settings.json:
    {
      "hooks": {
        "PostToolUse": [
          {
            "matcher": "*",
            "_source": "my-corp-cli",
            "hooks": [...]
          }
        ]
      }
    }
    
  2. Install claude-mem:
    npx claude-mem install
  3. Run repair:
    npx claude-mem repair
  4. Output shows success: claude-mem repair complete.
  5. Check settings.json - claude-mem hooks are NOT added.

Part 2: Model compatibility issue

  1. Configure gateway auth in ~/.claude-mem/.env:
    ANTHROPIC_BASE_URL=http://your-corporate-llm-proxy.example.com
    ANTHROPIC_AUTH_TOKEN=your-key
  2. Update ~/.claude-mem/settings.json:
    {
    "CLAUDE_MEM_PROVIDER": "claude",
    "CLAUDE_MEM_CLAUDE_AUTH_METHOD": "gateway"
    }
  3. Restart worker:
    npx claude-mem restart
  4. Check logs - SDK returns 401 error:
    [SDK] ← Response received: Failed to authenticate. API Error: 401 key not allowed to access model

Expected Behavior

  1. npx claude-mem repair should detect and merge hooks alongside existing plugins
  2. When using gateway auth with a non-Claude proxy, SDK should either:
    - Support configurable model names (e.g., glm-5-external, gpt-4o)
    - Or provide clear error message about model incompatibility

Actual Behavior

Issue 1: Hooks not registered

  • settings.json only contains hooks from the first plugin (my-corp-cli)
  • claude-mem's PostToolUse hook never fires
  • Observations are never captured
  • Memory search returns empty results

Issue 2: Model incompatibility

After manually fixing hooks, observations are enqueued but SDK fails:
[SDK] ← Response received: Failed to authenticate. API Error: 401 key not allowed to access model.
This key can only access...

The SDK tries to use claude-haiku-4-5-20251001 but corporate proxy only supports non-Claude models
(e.g., glm, kimi, minimax, deepseek).

Environment

  • Claude-mem version: 13.8.0
  • Claude Code version: Latest
  • OS: macOS (Darwin 23.5.0)
  • Node.js: v20.x
  • Bun: 1.3.14
  • Corporate proxy: Supports glm/kimi/minimax/deepseek, NOT Claude models

Additional Context

Root Cause Analysis:

Issue 1 - The repair command appears to:

  1. ✅ Create .install-version file
  2. ✅ Verify runtime dependencies (Bun, uv)
  3. ❌ NOT check if hooks are registered in settings.json
  4. ❌ NOT merge hooks when another plugin already registered same matcher

Issue 2 - The SDK:

  1. ✅ Correctly receives environment variables (ANTHROPIC_BASE_URL, ANTHROPIC_AUTH_TOKEN)
  2. ❌ Hardcodes model to claude-haiku-4-5-20251001
  3. ❌ Cannot work with proxies that don't support Claude models

Evidence - Worker logs:
[SDK] Starting SDK query {authMethod=Gateway auth token (from ~/.claude-mem/.env)}
[SDK] ← Response received: Failed to authenticate. API Error: 401 key not allowed to access model

Workaround for Issue 1:

Manually add claude-mem hooks to settings.json, appending to existing hook arrays:

{
"hooks": {
"PostToolUse": [
{ "matcher": "", "_source": "my-corp-cli", "hooks": [...] },
{ "matcher": "
", "_source": "claude-mem", "hooks": [...] }
]
}
}

Workaround for Issue 2:

None currently. Users with corporate proxies that don't support Claude models cannot use claude-mem.

Suggested Fix:

For Issue 1:

  1. repair command should verify hooks are registered, not just files exist
  2. Hook registration should append to arrays, not assume exclusive ownership
  3. Consider using _source field to detect and update existing claude-mem hooks
  4. Add a --verify-hooks flag to check if hooks are properly registered

For Issue 2:

  1. Allow configurable model via CLAUDE_MEM_MODEL when using gateway auth
  2. Support OpenAI-compatible APIs directly (not just via OpenRouter)
  3. Provide clear error message when model is incompatible with the gateway

Impact:

This affects any user who:

  • Uses Claude Code with multiple plugins
  • Has a corporate/internal wrapper that registers global hooks
  • Uses a corporate LLM proxy that doesn't support Claude models
  • Expects claude-mem to work alongside their existing tooling

Without observations being captured, the entire memory system is non-functional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugConfirmed bug

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions