claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] User Interrupt Hook

Open arhgap11b opened this issue 3 months ago • 3 comments

Preflight Checklist

  • [x] I have searched existing requests and this feature hasn't been requested yet
  • [x] This is a single feature request (not multiple features)

Problem Statement

Summary

Add a new hook event that fires when the user manually interrupts Claude Code's response (e.g., by clicking Stop or pressing Ctrl+C).

Problem

Currently, Claude Code provides a Stop hook that fires when the agent finishes responding normally. However, according to the documentation:

"Does not run if the stoppage occurred due to a user interrupt."

This creates a gap: there is no way to detect when the user manually interrupts the agent. This prevents implementing features that need to differentiate between:

  • Normal completion (agent finished its work)
  • User interrupt (user manually stopped the agent)

Proposed Solution

Add a new hook event: UserInterrupt (or AgentInterrupted, Stop:Interrupted, etc.)

This hook should fire when:

  • User clicks the Stop button during agent response
  • User presses keyboard interrupt (Ctrl+C or equivalent)
  • User manually cancels agent operation through any UI mechanism

Example Configuration

{
  "hooks": {
    "Stop": [{
      "hooks": [{
        "type": "command",
        "command": "my-script.py --event normal_completion"
      }]
    }],
    "UserInterrupt": [{
      "hooks": [{
        "type": "command",
        "command": "my-script.py --event user_interrupted"
      }]
    }]
  }
}

Alternative Solutions

No response

Priority

Medium - Would be very helpful

Feature Category

CLI commands and flags

Use Case Example

We're implementing an audio notification system that plays background noise while Claude works and plays a completion sound when finished. We need to:

  • Play a "work complete" sound when the agent finishes normally (Stop hook)
  • Play a different "interrupted" sound when the user manually stops the agent
  • Currently impossible because there's no hook for user interrupts

Additional Context

Benefits

  1. Feature parity: Completes the lifecycle coverage (start → working → end/interrupt)
  2. Better UX: Enables context-aware notifications and state management
  3. Debugging: Helps track user interaction patterns and interruption frequency
  4. Resource cleanup: Allows proper cleanup of resources when operations are interrupted vs. completed

Workarounds (and why they don't work)

  1. Timeout-based detection: Unreliable, creates false positives for long-running tasks
  2. Heartbeat with PreToolUse: Fires on every tool call, creates noise and complexity
  3. Process monitoring: External to Claude Code, fragile and platform-specific

Related Documentation

arhgap11b avatar Oct 14 '25 09:10 arhgap11b

Would be great if we could have hook on context limit (when auto-compact turned off)!

arhgap11b avatar Oct 14 '25 11:10 arhgap11b

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 08 '25 10:12 github-actions[bot]

Would be nice to see this fixed for edge-triggered status / notification purposes

mpercy avatar Dec 24 '25 09:12 mpercy

I need that too!

CharlonTank avatar Dec 29 '25 05:12 CharlonTank

Consider me another vote for this.

I'm working on a utility that watches Claude activity and is effectively 'stuck' if it can't detect manual interuption.

jeffc-dev avatar Jan 14 '26 07:01 jeffc-dev

I could use the Interrupted hook too 🙏

bernarduh avatar Jan 21 '26 11:01 bernarduh

Very keen for this feature it is leaving my Claude code wrapper in very strange states.

maxisme avatar Jan 24 '26 09:01 maxisme

I need this one too ;)

alvarolb avatar Jan 24 '26 14:01 alvarolb

Pretty please 🙏 Thanks!

johnrobinsn avatar Jan 24 '26 19:01 johnrobinsn