[BUG] Report: Hooks Initialization Failure on First Startup with `--dangerously-skip-permissions` Mode

Resolved 💬 3 comments Opened Oct 26, 2025 by yxcl6666 Closed Jan 11, 2026

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

  1. Launch for the first time using the --dangerously-skip-permissions mode:

``bash
claude --dangerously-skip-permissions
``

  1. Attempt to trigger the hook:
  • Execute any Task tool call
  • Observe whether any hook response occurs
  1. Verify configuration status:

``bash
/hooks
``

  • Observe whether the configuration is displayed correctly
  1. Switch to debug mode for testing:

``bash
# Exit current session
claude --debug
``

  1. Test the hook in debug mode:
  • Execute the same Task tool call
  • Observe if the hook responds normally
  1. Re-use --dangerously-skip-permissions mode:

``bash
# Exit debug mode
claude --dangerously-skip-permissions
``

  1. 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 /hooks command 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 /hooks command 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

  1. Configuration Parsing is Normal: The /hooks command correctly displays all configurations, indicating that JSON parsing and configuration reading work fine.
  1. Failure is Condition-Specific:
  • Only occurs during the first launch in --dangerously-skip-permissions mode.
  • Debug mode and standard mode work correctly.
  • Once initialized through another mode, subsequent use of the --dangerously-skip-permissions mode also works correctly.
  1. 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-permissions

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗