Claude Code Hook Events Fired Twice When Running from Home Directory
Claude Code Hook Events Fired Twice When Running from Home Directory
Bug Description
Claude Code fires duplicate Stop hook events when executed from the user's home directory (/Users/username), but works correctly when executed from other directories. This causes duplicate notifications, sounds, and any other hook-based integrations to trigger twice.
Environment
- Platform: macOS (Darwin 24.6.0)
- Claude Code Version: Latest (as of 2025-07-14)
- Shell: bash/zsh
- Home Directory:
/Users/username
Steps to Reproduce
- Configure Claude Code hooks in
~/.claude/settings.json:
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "/path/to/your/hook-script.sh"
}
]
}
]
}
}
- Open terminal in home directory (
/Users/username) - Run
claude - Send any message (e.g., "hello")
- Exit the session
- Observe hook execution
- Compare with other directory:
cd /Users/username/Desktop/test- Run
claude - Send any message
- Exit the session
- Observe hook execution
Expected Behavior
Hook events should fire exactly once per event regardless of the working directory from which Claude Code is executed.
Actual Behavior
- From home directory (
/Users/username): Hook events fire twice - From other directories: Hook events fire once (correct behavior)
Evidence
Log Analysis
Hook script logs clearly show duplicate event processing when running from home directory:
From /Users/username (DUPLICATE EVENTS):
[2025-07-13 20:08:00] [INFO] === Claude Hook v18.0 started ===
[2025-07-13 20:08:00] [INFO] === Claude Hook v18.0 started ===
[2025-07-13 20:08:00] [INFO] Processing event: Stop
[2025-07-13 20:08:00] [INFO] Processing event: Stop
From /Users/username/Desktop/test (CORRECT BEHAVIOR):
[2025-07-13 20:04:50] [INFO] === Claude Hook v18.0 started ===
[2025-07-13 20:04:50] [INFO] Processing event: Stop
Notification Behavior
- Home directory: 2 identical notifications displayed
- Other directories: 1 notification displayed (expected)
Root Cause Analysis
Based on extensive debugging, Claude Code appears to launch two separate hook processes simultaneously when executed from the user's home directory, but only one process when executed from other directories.
This suggests a potential issue in Claude Code's hook registration or execution logic that specifically affects the home directory context, possibly related to:
- Configuration loading hierarchy - Different behavior when Claude Code runs from the same directory as the global configuration
- Process spawning logic - Potential race condition or double-execution in home directory context
- Session management - Different session handling when working directory matches configuration directory
Impact
- User Experience: Annoying duplicate notifications
- Automation: Scripts/integrations receive duplicate events
- Resource Usage: Unnecessary duplicate process execution
- Reliability: Inconsistent behavior between directories
Workaround
We implemented client-side deduplication using file locking in the hook script:
# Add deduplication logic with file locking to handle concurrent processes
acquire_lock() {
local timeout=10
local count=0
while [[ $count -lt $timeout ]]; do
if (set -C; echo $$ > "$LOCK_FILE") 2>/dev/null; then
return 0 # Lock acquired
fi
sleep 0.1
count=$((count + 1))
done
return 1 # Failed to acquire lock
}
is_duplicate_event() {
local event_type="$1"
local session_id="$2"
local current_epoch=$(date '+%s')
if ! acquire_lock; then
return 1 # Allow event if we can't get lock
fi
# Check recent events and record if not duplicate
# ... deduplication logic ...
release_lock
return $is_duplicate
}
Suggested Fix
The issue should be addressed in Claude Code's core hook execution logic to ensure:
- Single Process Execution: Only one hook process should be spawned per event
- Consistent Behavior: Same execution pattern regardless of working directory
- Session Management: Proper session tracking that doesn't create duplicates based on directory context
Additional Notes
- This bug is reproducible and consistent
- Only affects the home directory - all other directories work correctly
- Affects all hook events (Stop, Notification, etc.) when run from home directory
- No configuration differences between directories - same global
~/.claude/settings.jsonused
Priority
Medium-High - While workaround exists, this affects user experience and could impact automation reliability for users running Claude Code from their home directory.
---
Reporter: [Your GitHub username]
Date: 2025-07-14
Claude Code Session: Multiple reproductions confirmed
6 Comments
I'm very confident, that this is related to: https://github.com/anthropics/claude-code/issues/3477
This issue is not related to #3477. I have a repro and will fix the issue soon.
_Aside: I recommend not to run Claude Code from the home directory, since you will give Claude Code broad access to execute files in your system (files within your home directory), which can be dangerous._
@dicksontsai - I'm getting duplicate hooks in my project directory as well. This is recent behavior (last day or two maybe) I'm happy to make a new issue if you'd prefer.
@BuckAMayzing can you file a new issue? This issue is specifically about using Claude Code in the home directory. There was a regression that duplicated hooks configuration that we fixed in v1.0.53 (#3477 ), but we don't automatically clean up the duplicates.
-----
The fix for this issue went out with v1.0.53.
Ah! This was the root cause of my issue as well. I deleted the duplicate config and problem solved. I'm not going to tag you again because there's no reason to create the noise.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.