Skip to content

[BUG] Plugin-registered hooks are executed twice with different PIDs #10871

Description

@otolab

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When hooks are registered via plugins, they are executed twice with different process IDs. This affects all hook types including SessionStart, Notification, and PreCompact.

Key symptoms:

  • Each hook execution spawns two separate processes (different PIDs)
  • The /hooks command shows duplicate hook registrations (e.g., "2 hooks" when only 1 is defined)
  • This appears to have been occurring since the plugin system was implemented
  • Both executions actually run (verified via log files with different PIDs)

This is NOT a display-only issue - the hooks are genuinely executed twice, causing:

  • Duplicate notifications
  • Duplicate audio playback (if hooks trigger sounds)
  • Duplicate file writes/modifications

What Should Happen?

Each hook defined in a plugin should be:

  1. Registered once in the hooks system
  2. Displayed once in /hooks command output
  3. Executed once when triggered

Error Messages/Logs

**Log file evidence (`~/claude-hook-duplicate-test.log`):**


[2025-11-03 05:19:02.918] Hook: SessionStart | PID: 63864
[2025-11-03 05:19:02.919] Hook: SessionStart | PID: 63865
[2025-11-03 05:19:37.800] Hook: Notification | PID: 64293
[2025-11-03 05:19:37.800] Hook: Notification | PID: 64292


**Observations:**
- SessionStart executed twice (PID 63864 and 63865) within 1ms
- Notification executed twice (PID 64292 and 64293) at identical timestamp
- Each pair has **different PIDs**, proving these are separate process executions

**`/hooks` command output:**

Shows "2 hooks" for PreCompact when only 1 hook is defined in the plugin (see attached screenshot).

Steps to Reproduce

Reproduction repository: https://github.com/otolab/hook-duplicate-test-plugin

Quick reproduction steps:

  1. Install the test plugin:

    /plugin marketplace add otolab/hook-duplicate-test-plugin
    /plugin install hook-duplicate-test@otolab-marketplace
  2. Check hook registration:

    /hooks

    Expected: Each hook type shows "1 hook"
    Actual: Shows "2 hooks" (duplicate registration)

  3. Clear log file and trigger hooks:

    rm -f ~/claude-hook-duplicate-test.log
    # Start new session (triggers SessionStart)
    # Or trigger notification (triggers Notification)
  4. Check execution log:

    cat ~/claude-hook-duplicate-test.log

    Expected: One entry per hook execution
    Actual: Two entries with different PIDs

Screenshot of /hooks command showing duplicate registration:

PreCompact showing 2 hooks when only 1 is defined

As shown in the screenshot, the PreCompact section displays "[Plugin] 2 hooks" even though only one PreCompact hook is defined in the plugin configuration.

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

Unknown

Claude Code Version

2.0.31 (Claude Code)

Platform

Google Vertex AI

Operating System

macOS

Terminal/Shell

iTerm2

Additional Information

Affected hook types (confirmed):

  • SessionStart
  • Notification
  • PreCompact
  • Likely affects all hook types

Related but different issues:

This issue is distinct because it involves actual duplicate execution with separate processes, not just display problems.

Impact:

  • Medium severity
  • Causes duplicate side effects (notifications, file writes, audio, etc.)
  • Appears to have been present since plugin system launch

Test plugin details:

  • Simple hooks that log timestamp + PID to file
  • Demonstrates the issue is in the hook registration/execution system, not in hook implementation
  • Repository includes full reproduction instructions

Activity

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

Metadata

Metadata

Assignees

Labels

area:corebugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions