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

[BUG] Notification Hook 10 second delay

Open bkaes opened this issue 1 year ago • 25 comments

Environment

  • Platform (select one):
    • [x] Anthropic API
    • [ ] AWS Bedrock
    • [ ] Google Vertex AI
    • [ ] Other:
  • Claude CLI version: 1.0.69
  • Operating System: Ubuntu 24.04.2
  • Terminal: Terminal App

Bug Description

~8-10 second delay for Notification Hook

Steps to Reproduce

  1. Setup a hook for notifications
  2. Request Claude Code to go into a different directory in order to send me to trigger the notification hook.

Expected Behavior

The notification hook to query and execute immediately

Actual Behavior

[DEBUG] Matched 0 unique hooks for query "LS" (0 before deduplication) [DEBUG] Found 0 hook commands to execute

10 Second Delay

[DEBUG] Getting matching hook commands for Notification with query: undefined [DEBUG] Found 1 hook matchers in settings [DEBUG] Matched 1 unique hooks for query "no match query" (1 before deduplication) [DEBUG] Notification [echo "$(date): Notification hook triggered, playing sound" >> ~/.claude/hook.log && paplay ~/.claude/sounds/correct-answer.wav &] completed with status 0

Additional Context

bkaes avatar Aug 05 '25 20:08 bkaes

+1 Having same issue

Environment

Platform:

  • [x] Anthropic API

  • Claude CLI version: 1.0.72

  • Operating System: Ubuntu 24.04.2

  • Terminal: Zsh

Makakusnik avatar Aug 11 '25 10:08 Makakusnik

I've been battling with this for a TTS based on the notification hook. Mine isn't quite 10 seconds but it's lengthy. I though it was my hook handlers and have put extensive logging in my code and my hook handler in Python take 50ms total. Not great but definitely not the 3-6 second delay the hook shows. I have logging of the notification as the first thing that happens and I see the file get written ad is immediately followed by my TTS announcement.

I'm certain it is not my code.

Anthropic API

Claude CLI version: 1.0.72

Operating System: macOS Sequoia 15.6

Terminal: Zsh

clafollett avatar Aug 14 '25 00:08 clafollett

same issue here

[DEBUG] Hooks: checkForNewResponses called
[DEBUG] Hooks: Found 0 total hooks in registry
[DEBUG] Hooks: checkForNewResponses returning 0 responses

then delay for 10~20s

I am on windows11, claude code 2.0.0,

CPU: AMD ryzen 9 9950X

sevelee avatar Sep 30 '25 03:09 sevelee

Seems I fixed this issue by https://stackoverflow.com/questions/28507014/cygwin-commands-from-cmd-are-slow-from-bash-are-fast. Problem is cygwinis very slow when frist time called on windows.

A section in Cygwin's FAQ addresses slow startup times. Cygwin recently changed to using Active Directory lookups for authentication, rather than using flat files. Changing the defaults in /etc/nsswitch.conf from

passwd: files db group: files db to

passwd: files group: files skips the AD lookup. My Cygwin commands are now speedy again.

sevelee avatar Sep 30 '25 18:09 sevelee

Has anyone got a fix on linux?

informal-stripes-condo avatar Oct 06 '25 15:10 informal-stripes-condo

I'm also getting this

will-lynas avatar Oct 06 '25 19:10 will-lynas

Bumping this

informal-stripes-condo avatar Oct 08 '25 12:10 informal-stripes-condo

This problem is still happening.

cool-RR avatar Oct 10 '25 13:10 cool-RR

im getting this bug too and its really disrupting my workflow at work!

conradtondryk avatar Oct 12 '25 09:10 conradtondryk

Bumping this again

informal-stripes-condo avatar Oct 22 '25 10:10 informal-stripes-condo

Bumping this

will-lynas avatar Nov 01 '25 23:11 will-lynas

I want to be notified as soon as possible when Claude needs my attention. These 10 second delays are annoying.

cool-RR avatar Nov 28 '25 16:11 cool-RR

@bcherny @ant-kurt @ashwin-ant Can you help with this? v2.0.37 included "Fixed how idleness is computed for notifications" but there's still a consistent ~10s delay in the notification pipeline.

Binary analysis (v2.0.55) shows a 6-second polling interval (setInterval with ewD=6000) in the notification check logic. The remaining ~4 seconds may be subprocess spawn overhead. On Windows/Cygwin, disabling AD lookups in nsswitch.conf reduces the delay, supporting this theory.

Relevant timing constants found in the bundled JS:

  • ewD=6000 (notification polling interval)
  • Tz=60000 (hook execution timeout)
  • asyncTimeout=15000 (async hook timeout)
  • messageIdleNotifThresholdMs=60000 (idle notification threshold)

Exposing the polling interval as a configurable environment variable would help.

cool-RR avatar Nov 28 '25 17:11 cool-RR

In the meanwhile I had Claude Code make a program that patches this bug on your local binary: https://gist.github.com/cool-RR/dab9b132fb607712a614d487dd554d29

For me it makes the notification hook have <1s delay. Use at your own risk.

cool-RR avatar Nov 28 '25 17:11 cool-RR

I can confirm this bug on Linux with Claude Code 2.0.65. Seems to be much longer than 10 seconds for me though. I'd expect the notification to be instant.

kid4git avatar Dec 11 '25 07:12 kid4git

Confirming this bug still exists on v2.0.76 (macOS)

sammcj avatar Dec 30 '25 22:12 sammcj

This bug still exists on v2.1.11 on Mac

adityabaradwaj avatar Jan 17 '26 05:01 adityabaradwaj

In the meanwhile I had Claude Code make a program that patches this bug on your local binary: gist.github.com/cool-RR/dab9b132fb607712a614d487dd554d29

For me it makes the notification hook have <1s delay. Use at your own risk.

thank you for this gist. I modified it to work with 2.1.x and included it in my MIT licensed tool, lemonaid: https://github.com/petergaultney/lemonaid/blob/main/src/lemonaid/claude/patcher.py

petergaultney avatar Jan 23 '26 02:01 petergaultney

Seems I fixed this issue by https://stackoverflow.com/questions/28507014/cygwin-commands-from-cmd-are-slow-from-bash-are-fast. Problem is cygwinis very slow when frist time called on windows.

A section in Cygwin's FAQ addresses slow startup times. Cygwin recently changed to using Active Directory lookups for authentication, rather than using flat files. Changing the defaults in /etc/nsswitch.conf from passwd: files db group: files db to passwd: files group: files skips the AD lookup. My Cygwin commands are now speedy again.

UP the issue.

This fix is not working if using Native Install. I tested and it is only works with npm install on windows 11.

sevelee avatar Feb 06 '26 15:02 sevelee

I'm seeing this bug on Mac v2.1.39 for Notification hooks as well. The Stop and SubagentStop fire immediately.

BradDuns avatar Feb 11 '26 05:02 BradDuns