Skip to content

[BUG] Claude Code Hooks System Issues #2814

@darko-mijic

Description

@darko-mijic

Summary

Multiple issues with the Claude Code hooks system preventing proper validation and blocking of unsafe operations.

Environment

  • Platform: macOS (Darwin 24.5.0)
  • Claude Code Version: 1.0.38 (Claude Code)
  • Working Directory: Git repository
  • Configuration File: .claude/settings.local.json

Issues Identified

1. Template Variable Interpolation Failure

Expected: Template variables like {{tool.name}}, {{timestamp}}, and {{tool.input.file_path}} should be replaced with actual values.

Actual: Template variables appear literally in executed commands.

Evidence:

# Debug log shows literal template variables instead of interpolated values
$ tail /tmp/claude-hook-debug.log
[DEBUG] Hook fired for tool: {{tool.name}} at {{timestamp}}
[DEBUG] Hook fired for tool: {{tool.name}} at {{timestamp}}

2. Hook Configuration Changes Not Respected

Expected: Changes to .claude/settings.local.json should take effect after Claude Code restart.

Actual: Configuration changes are ignored; old hook behavior persists even after restart.

Evidence:

  • Modified hook configuration multiple times
  • Restarted Claude Code after each change
  • Old debug hook continues executing despite being removed from config
  • New simple test hooks never execute

3. Hook Commands Not Blocking Operations

Expected: When a PreToolUse hook command exits with non-zero status, the tool operation should be blocked.

Actual: Tool operations proceed regardless of hook command exit status.

Evidence:

  • Created validation script that exits with code 1 on unsafe patterns
  • Hook wrapper correctly returns exit code 1 when validation fails
  • File operations still succeed despite validation failures

Configuration Tested

Final Hook Configuration

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write",
        "hooks": [
          {
            "type": "command", 
            "command": "echo 'Write hook fired' >> /tmp/claude-simple-test.log"
          }
        ]
      }
    ]
  }
}

Validation Script

  • Created working validation script that detects unsafe patterns
  • Returns proper exit codes (0 for safe, 1 for unsafe)
  • Tested independently - works correctly outside Claude Code

Steps to Reproduce

  1. Create .claude/settings.local.json with PreToolUse hooks
  2. Configure hooks with template variables and command that can fail
  3. Restart Claude Code
  4. Perform Write/Edit operations that should trigger hooks
  5. Observe that:
    • Template variables aren't interpolated
    • Hook commands execute but don't block operations
    • Configuration changes aren't respected

Expected Behavior

  1. Template variables should be replaced with actual values
  2. Hook configuration changes should take effect after restart
  3. PreToolUse hooks returning non-zero exit codes should block tool operations
  4. Hooks should provide effective validation/blocking capabilities

Workarounds Implemented

Since Claude Code hooks are not functional, we've implemented alternative safeguards:

  • ESLint rules with custom patterns detection
  • Pre-commit hooks for validation
  • Git safety rules to prevent bypassing quality gates

Request

Please investigate and fix the Claude Code hooks system to enable proper validation and blocking of unsafe operations as documented.

Metadata

Metadata

Assignees

Labels

area:corebugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOS

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions