[BUG] Report: Hooks Initialization Failure on First Startup with `--dangerously-skip-permissions` Mode
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When launching Claude Code for the first time using the --dangerously-skip-permissions mode, the correctly configured hooks system fails to operate. The configuration file is parsed successfully (verified using the /hooks command), but the hook events are not actually triggered or executed.
What Should Happen?
The hooks system should function correctly upon first startup, without requiring additional initialization steps.
Error Messages/Logs
Steps to Reproduce
Steps to Reproduce
Environment Setup
# 1. Create new project directory
mkdir test-hooks-bug
cd test-hooks-bug
# 2. Create .claude directory and settings.json configuration
mkdir .claude
settings.json configuration example:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Task",
"hooks": [
{
"type": "command",
"command": "python .claude/hooks/test-hook.py"
}
]
}
]
}
}
test-hook.py script example:
#!/usr/bin/env python3
import json
import sys
input_data = json.load(sys.stdin)
tool_name = input_data.get('tool_name', '')
if tool_name == "Task":
print("Hook successfully triggered!", file=sys.stderr)
sys.exit(2) # Prevent tool call
Reproduction Steps
- Launch for the first time using the
--dangerously-skip-permissionsmode:
``bash``
claude --dangerously-skip-permissions
- Attempt to trigger the hook:
- Execute any Task tool call
- Observe whether any hook response occurs
- Verify configuration status:
``bash``
/hooks
- Observe whether the configuration is displayed correctly
- Switch to debug mode for testing:
``bash``
# Exit current session
claude --debug
- Test the hook in debug mode:
- Execute the same Task tool call
- Observe if the hook responds normally
- Re-use
--dangerously-skip-permissionsmode:
``bash``
# Exit debug mode
claude --dangerously-skip-permissions
- Test if the hook now works correctly
Expected Behavior
- In Step 2, hooks should be correctly triggered and prevent the Task tool call.
- In Step 3, the
/hookscommand should display the configuration (this part works correctly). - The hooks system should function correctly upon first startup, without requiring additional initialization steps.
Actual Behavior
Step 2: Behavior on First Startup
- ❌ Hook is completely unresponsive.
- ❌ Task tool call is not intercepted.
- ❌ No errors or warning messages are displayed.
- ✅ The
/hookscommand correctly displays the configuration content.
Step 5: Behavior in Debug Mode
- ✅ Hook is triggered successfully.
- ✅ Task tool call is successfully prevented.
- ✅ Script output is correctly displayed in stderr.
Step 6: Behavior when Re-using --dangerously-skip-permissions Mode
- ✅ Hook now functions correctly.
- ✅ System behavior meets expectations.
Key Observations
- Configuration Parsing is Normal: The
/hookscommand correctly displays all configurations, indicating that JSON parsing and configuration reading work fine.
- Failure is Condition-Specific:
- Only occurs during the first launch in
--dangerously-skip-permissionsmode. - Debug mode and standard mode work correctly.
- Once initialized through another mode, subsequent use of the
--dangerously-skip-permissionsmode also works correctly.
- Configuration Visible but Execution Fails: This indicates a specific initialization issue where the configuration is loaded, but the hooks system is not correctly registered to the event listener.
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.0.27 (Claude Code)
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
Cursor
Additional Information
Workarounds (Temporary Solutions)
Workaround 1: Initial Startup Sequence
# Step 1: Initialize using debug mode first
claude --debug
# Confirm hooks trigger, then exit
# Step 2: Subsequent launches can be used normally
claude --dangerously-skip-permissions
Workaround 2: Pre-warming with Standard Mode
# Step 1: Start with standard mode first
claude
# Run /hooks to confirm configuration
/hooks
# Exit
# Step 2: Then use the dangerously-skip-permissions mode
claude --dangerously-skip-permissionsThis issue has 3 comments on GitHub. Read the full discussion on GitHub ↗