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

[BUG] pre_tool_use and post_tool_use hooks not firing

Open pm0code opened this issue 6 days ago • 1 comments

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?

Claude Code Bug Report: pre_tool_use and post_tool_use Hooks Not Firing

Date: 2025-12-26 Claude Code Version: 2.0.76 Platform: Windows 11 x64


Summary

Hookify hooks configured with event: pre_tool_use and event: post_tool_use are not triggering in Claude Code sessions, despite being properly configured with enabled: true and valid matchers.


Expected Behavior

When a hook is configured with:

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

Expected: Claude should be blocked from using any matching tools (Grep, Glob, Read, Write, Edit, Bash, WebSearch, WebFetch, Task) until the hook conditions are satisfied.


Actual Behavior

Actual: Claude freely uses all matching tools without any blocking, warnings, or acknowledgment that the hook exists.


Evidence

Hook Configuration (Verified)

File: D:\[...]\.claude\hookify.mandatory-thinking-before-action.local.md

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

## BLOCKED - MANDATORY THINKING BEFORE ANY ACTION

**Protocol v10.0.0 - ZERO TOLERANCE FOR REACTIVE BEHAVIOR**

### YOU CANNOT USE THIS TOOL UNTIL YOU HAVE:

**1. ARTICULATED THE PROBLEM** (in your response text)
**2. SHOWN YOUR THINKING** (in your response text)
**3. PROPOSED A PLAN** (in your response text)
**4. ASKED FOR APPROVAL** (for non-trivial tasks)

Tool Usage That Should Have Been Blocked

In the same session where the hook is enabled, Claude successfully executed:

  1. Glob - .claude/hookify*.md (line 82216)
  2. Read - Multiple reads of hookify config files (lines 82718-107795)
  3. Bash - Multiple bash commands (lines 100766, 101838, etc.)
  4. TodoWrite - Task list updates (line 82216)

None of these tool calls were blocked, warned, or acknowledged by the hook system.

Hook System IS Working for Other Event Types

Working hooks:

  • event: file hooks ✅ (detect file pattern changes)
  • event: bash hooks ✅ (detect command patterns)
  • event: stop hooks ✅ (completion validation)
  • event: UserPromptSubmit ✅ (shows "hook success" messages)

NOT Working hooks:

  • event: pre_tool_use ❌ (no blocking, no warnings)
  • event: post_tool_use ❌ (no verification prompts)

System Messages Confirming Other Hooks Work

<system-reminder>
UserPromptSubmit hook success: Success
</system-reminder>
<system-reminder>
UserPromptSubmit:Callback hook success: Success
</system-reminder>

These messages appear consistently, proving the hookify system IS active, but only for certain event types.


Reproduction Steps

  1. Create a hookify hook file in .claude/ directory:
---
name: test-pre-tool-use-hook
enabled: true
event: pre_tool_use
action: block
matcher: Read|Glob
---

## TEST HOOK - YOU SHOULD BE BLOCKED

This hook should prevent Read and Glob tool usage.
  1. Start a Claude Code session in that directory

  2. Ask Claude to read a file or search for files

  3. Expected: Claude is blocked and cannot use Read/Glob until hook conditions satisfied

  4. Actual: Claude freely uses Read and Glob without acknowledgment of the hook


Impact

Critical for APEX-v2 Project

This bug breaks Protocol v10.0.0 enforcement in the APEX-v2 trading system project, which relies on pre_tool_use hooks to:

  1. Prevent reactive coding - Force ANALYSIS→THINKING→PLAN→APPROVAL workflow before tool usage
  2. Enforce holistic thinking - Block tools until full system impact is considered
  3. Prevent costly mistakes - Require approval before code changes in financial systems

Examples of Broken Workflows

Hook: mandatory-thinking-before-action.local.md Purpose: Block ALL tool usage until Claude articulates problem, shows thinking, and gets approval Status: ❌ Not working - Claude uses tools immediately without planning

Hook: post-action-verification.local.md Purpose: After Write/Edit/Bash, verify changes had intended effect Status: ❌ Not working - No verification prompts appear


Workaround

Currently using manual compliance: Developer reminds Claude to follow the workflow before tool usage. This is error-prone and defeats the purpose of automated enforcement.


Diagnostic Information

Hook Files Present

$ ls .claude/hookify*.md
hookify.[...]-aiml-models-registry.local.md
hookify.[...]-completion-validation.local.md
hookify.[...]-database-operations.local.md
hookify.[...]-financial-precision.local.md
hookify.[...]-gpu-operations.local.md
hookify.[...]-protocol-violations.local.md
hookify.[...]-service-hardening.local.md
hookify.[...]-winui3-builds.local.md
hookify.financial-precision-check.local.md
hookify.mandatory-thinking-before-action.local.md  # <-- THIS ONE
hookify.post-action-verification.local.md          # <-- THIS ONE
hookify.require-agent-planning.local.md
hookify.require-analysis-before-code.local.md
hookify.ui-chain-verification.local.md

Enabled Hooks Count

$ grep -l "enabled: true" .claude/hookify*.md | wc -l
10

Pre-Tool-Use Hooks (Should Be Working)

$ grep -l "event: pre_tool_use" .claude/hookify*.md
hookify.mandatory-thinking-before-action.local.md  # enabled: true
hookify.require-agent-planning.local.md            # enabled: false (deprecated)
hookify.require-analysis-before-code.local.md      # enabled: false (deprecated)

Only 1 active pre_tool_use hook, and it's not firing.


Questions for Claude Code Team

  1. Is pre_tool_use event implemented in the current Claude Code version?
  2. Is there a different event name that should be used for pre-tool blocking?
  3. Are there any known limitations or requirements for pre_tool_use hooks?
  4. What is the roadmap for full hookify event support?

Suggested Fix

If pre_tool_use is not yet implemented:

  1. Document which events ARE supported in hookify documentation
  2. Add pre_tool_use and post_tool_use support to match documentation examples
  3. Ensure action: block actually prevents tool execution (not just warnings)

Additional Context

This is blocking a critical quality enforcement mechanism for a financial trading system development project. The project has 14 hookify hooks configured to enforce:

  • Decimal precision for money (no float/double)
  • Database operation safety (architect consultation required)
  • GPU operation governance
  • AI/ML model registry compliance
  • Protocol v10.0.0 zero-tolerance policies

Without working pre_tool_use hooks, these enforcement mechanisms are non-functional.

What Should Happen?

Claude Code Bug Report: pre_tool_use and post_tool_use Hooks Not Firing

Date: 2025-12-26 Claude Code Version: 2.0.76 Platform: Windows 11 x64


Summary

Hookify hooks configured with event: pre_tool_use and event: post_tool_use are not triggering in Claude Code sessions, despite being properly configured with enabled: true and valid matchers.


Expected Behavior

When a hook is configured with:

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

Expected: Claude should be blocked from using any matching tools (Grep, Glob, Read, Write, Edit, Bash, WebSearch, WebFetch, Task) until the hook conditions are satisfied.


Actual Behavior

Actual: Claude freely uses all matching tools without any blocking, warnings, or acknowledgment that the hook exists.


Evidence

Hook Configuration (Verified)

File: D:\[...]\.claude\hookify.mandatory-thinking-before-action.local.md

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

## BLOCKED - MANDATORY THINKING BEFORE ANY ACTION

**Protocol v10.0.0 - ZERO TOLERANCE FOR REACTIVE BEHAVIOR**

### YOU CANNOT USE THIS TOOL UNTIL YOU HAVE:

**1. ARTICULATED THE PROBLEM** (in your response text)
**2. SHOWN YOUR THINKING** (in your response text)
**3. PROPOSED A PLAN** (in your response text)
**4. ASKED FOR APPROVAL** (for non-trivial tasks)

Tool Usage That Should Have Been Blocked

In the same session where the hook is enabled, Claude successfully executed:

  1. Glob - .claude/hookify*.md (line 82216)
  2. Read - Multiple reads of hookify config files (lines 82718-107795)
  3. Bash - Multiple bash commands (lines 100766, 101838, etc.)
  4. TodoWrite - Task list updates (line 82216)

None of these tool calls were blocked, warned, or acknowledged by the hook system.

Hook System IS Working for Other Event Types

Working hooks:

  • event: file hooks ✅ (detect file pattern changes)
  • event: bash hooks ✅ (detect command patterns)
  • event: stop hooks ✅ (completion validation)
  • event: UserPromptSubmit ✅ (shows "hook success" messages)

NOT Working hooks:

  • event: pre_tool_use ❌ (no blocking, no warnings)
  • event: post_tool_use ❌ (no verification prompts)

System Messages Confirming Other Hooks Work

<system-reminder>
UserPromptSubmit hook success: Success
</system-reminder>
<system-reminder>
UserPromptSubmit:Callback hook success: Success
</system-reminder>

These messages appear consistently, proving the hookify system IS active, but only for certain event types.


Reproduction Steps

  1. Create a hookify hook file in .claude/ directory:
---
name: test-pre-tool-use-hook
enabled: true
event: pre_tool_use
action: block
matcher: Read|Glob
---

## TEST HOOK - YOU SHOULD BE BLOCKED

This hook should prevent Read and Glob tool usage.
  1. Start a Claude Code session in that directory

  2. Ask Claude to read a file or search for files

  3. Expected: Claude is blocked and cannot use Read/Glob until hook conditions satisfied

  4. Actual: Claude freely uses Read and Glob without acknowledgment of the hook


Impact

Critical for APEX-v2 Project

This bug breaks Protocol v10.0.0 enforcement in the APEX-v2 trading system project, which relies on pre_tool_use hooks to:

  1. Prevent reactive coding - Force ANALYSIS→THINKING→PLAN→APPROVAL workflow before tool usage
  2. Enforce holistic thinking - Block tools until full system impact is considered
  3. Prevent costly mistakes - Require approval before code changes in financial systems

Examples of Broken Workflows

Hook: mandatory-thinking-before-action.local.md Purpose: Block ALL tool usage until Claude articulates problem, shows thinking, and gets approval Status: ❌ Not working - Claude uses tools immediately without planning

Hook: post-action-verification.local.md Purpose: After Write/Edit/Bash, verify changes had intended effect Status: ❌ Not working - No verification prompts appear


Workaround

Currently using manual compliance: Developer reminds Claude to follow the workflow before tool usage. This is error-prone and defeats the purpose of automated enforcement.


Diagnostic Information

Hook Files Present

$ ls .claude/hookify*.md
hookify.[...]-aiml-models-registry.local.md
hookify.[...]-completion-validation.local.md
hookify.[...]-database-operations.local.md
hookify.[...]-financial-precision.local.md
hookify.[...]-gpu-operations.local.md
hookify.[...]-protocol-violations.local.md
hookify.[...]-service-hardening.local.md
hookify.[...]-winui3-builds.local.md
hookify.financial-precision-check.local.md
hookify.mandatory-thinking-before-action.local.md  # <-- THIS ONE
hookify.post-action-verification.local.md          # <-- THIS ONE
hookify.require-agent-planning.local.md
hookify.require-analysis-before-code.local.md
hookify.ui-chain-verification.local.md

Enabled Hooks Count

$ grep -l "enabled: true" .claude/hookify*.md | wc -l
10

Pre-Tool-Use Hooks (Should Be Working)

$ grep -l "event: pre_tool_use" .claude/hookify*.md
hookify.mandatory-thinking-before-action.local.md  # enabled: true
hookify.require-agent-planning.local.md            # enabled: false (deprecated)
hookify.require-analysis-before-code.local.md      # enabled: false (deprecated)

Only 1 active pre_tool_use hook, and it's not firing.


Questions for Claude Code Team

  1. Is pre_tool_use event implemented in the current Claude Code version?
  2. Is there a different event name that should be used for pre-tool blocking?
  3. Are there any known limitations or requirements for pre_tool_use hooks?
  4. What is the roadmap for full hookify event support?

Suggested Fix

If pre_tool_use is not yet implemented:

  1. Document which events ARE supported in hookify documentation
  2. Add pre_tool_use and post_tool_use support to match documentation examples
  3. Ensure action: block actually prevents tool execution (not just warnings)

Additional Context

This is blocking a critical quality enforcement mechanism for a financial trading system development project. The project has 14 hookify hooks configured to enforce:

  • Decimal precision for money (no float/double)
  • Database operation safety (architect consultation required)
  • GPU operation governance
  • AI/ML model registry compliance
  • Protocol v10.0.0 zero-tolerance policies

Without working pre_tool_use hooks, these enforcement mechanisms are non-functional.

Error Messages/Logs


Steps to Reproduce

Claude Code Bug Report: pre_tool_use and post_tool_use Hooks Not Firing

Date: 2025-12-26 Claude Code Version: 2.0.76 Platform: Windows 11 x64


Summary

Hookify hooks configured with event: pre_tool_use and event: post_tool_use are not triggering in Claude Code sessions, despite being properly configured with enabled: true and valid matchers.


Expected Behavior

When a hook is configured with:

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

Expected: Claude should be blocked from using any matching tools (Grep, Glob, Read, Write, Edit, Bash, WebSearch, WebFetch, Task) until the hook conditions are satisfied.


Actual Behavior

Actual: Claude freely uses all matching tools without any blocking, warnings, or acknowledgment that the hook exists.


Evidence

Hook Configuration (Verified)

File: D:\[...]\.claude\hookify.mandatory-thinking-before-action.local.md

---
name: mandatory-thinking-before-action
enabled: true
event: pre_tool_use
action: block
matcher: Grep|Glob|Read|Write|Edit|Bash|WebSearch|WebFetch|Task
---

## BLOCKED - MANDATORY THINKING BEFORE ANY ACTION

**Protocol v10.0.0 - ZERO TOLERANCE FOR REACTIVE BEHAVIOR**

### YOU CANNOT USE THIS TOOL UNTIL YOU HAVE:

**1. ARTICULATED THE PROBLEM** (in your response text)
**2. SHOWN YOUR THINKING** (in your response text)
**3. PROPOSED A PLAN** (in your response text)
**4. ASKED FOR APPROVAL** (for non-trivial tasks)

Tool Usage That Should Have Been Blocked

In the same session where the hook is enabled, Claude successfully executed:

  1. Glob - .claude/hookify*.md (line 82216)
  2. Read - Multiple reads of hookify config files (lines 82718-107795)
  3. Bash - Multiple bash commands (lines 100766, 101838, etc.)
  4. TodoWrite - Task list updates (line 82216)

None of these tool calls were blocked, warned, or acknowledged by the hook system.

Hook System IS Working for Other Event Types

Working hooks:

  • event: file hooks ✅ (detect file pattern changes)
  • event: bash hooks ✅ (detect command patterns)
  • event: stop hooks ✅ (completion validation)
  • event: UserPromptSubmit ✅ (shows "hook success" messages)

NOT Working hooks:

  • event: pre_tool_use ❌ (no blocking, no warnings)
  • event: post_tool_use ❌ (no verification prompts)

System Messages Confirming Other Hooks Work

<system-reminder>
UserPromptSubmit hook success: Success
</system-reminder>
<system-reminder>
UserPromptSubmit:Callback hook success: Success
</system-reminder>

These messages appear consistently, proving the hookify system IS active, but only for certain event types.


Reproduction Steps

  1. Create a hookify hook file in .claude/ directory:
---
name: test-pre-tool-use-hook
enabled: true
event: pre_tool_use
action: block
matcher: Read|Glob
---

## TEST HOOK - YOU SHOULD BE BLOCKED

This hook should prevent Read and Glob tool usage.
  1. Start a Claude Code session in that directory

  2. Ask Claude to read a file or search for files

  3. Expected: Claude is blocked and cannot use Read/Glob until hook conditions satisfied

  4. Actual: Claude freely uses Read and Glob without acknowledgment of the hook


Impact

Critical for APEX-v2 Project

This bug breaks Protocol v10.0.0 enforcement in the APEX-v2 trading system project, which relies on pre_tool_use hooks to:

  1. Prevent reactive coding - Force ANALYSIS→THINKING→PLAN→APPROVAL workflow before tool usage
  2. Enforce holistic thinking - Block tools until full system impact is considered
  3. Prevent costly mistakes - Require approval before code changes in financial systems

Examples of Broken Workflows

Hook: mandatory-thinking-before-action.local.md Purpose: Block ALL tool usage until Claude articulates problem, shows thinking, and gets approval Status: ❌ Not working - Claude uses tools immediately without planning

Hook: post-action-verification.local.md Purpose: After Write/Edit/Bash, verify changes had intended effect Status: ❌ Not working - No verification prompts appear


Workaround

Currently using manual compliance: Developer reminds Claude to follow the workflow before tool usage. This is error-prone and defeats the purpose of automated enforcement.


Diagnostic Information

Hook Files Present

$ ls .claude/hookify*.md
hookify.[...]-aiml-models-registry.local.md
hookify.[...]-completion-validation.local.md
hookify.[...]-database-operations.local.md
hookify.[...]-financial-precision.local.md
hookify.[...]-gpu-operations.local.md
hookify.[...]-protocol-violations.local.md
hookify.[...]-service-hardening.local.md
hookify.[...]-winui3-builds.local.md
hookify.financial-precision-check.local.md
hookify.mandatory-thinking-before-action.local.md  # <-- THIS ONE
hookify.post-action-verification.local.md          # <-- THIS ONE
hookify.require-agent-planning.local.md
hookify.require-analysis-before-code.local.md
hookify.ui-chain-verification.local.md

Enabled Hooks Count

$ grep -l "enabled: true" .claude/hookify*.md | wc -l
10

Pre-Tool-Use Hooks (Should Be Working)

$ grep -l "event: pre_tool_use" .claude/hookify*.md
hookify.mandatory-thinking-before-action.local.md  # enabled: true
hookify.require-agent-planning.local.md            # enabled: false (deprecated)
hookify.require-analysis-before-code.local.md      # enabled: false (deprecated)

Only 1 active pre_tool_use hook, and it's not firing.


Questions for Claude Code Team

  1. Is pre_tool_use event implemented in the current Claude Code version?
  2. Is there a different event name that should be used for pre-tool blocking?
  3. Are there any known limitations or requirements for pre_tool_use hooks?
  4. What is the roadmap for full hookify event support?

Suggested Fix

If pre_tool_use is not yet implemented:

  1. Document which events ARE supported in hookify documentation
  2. Add pre_tool_use and post_tool_use support to match documentation examples
  3. Ensure action: block actually prevents tool execution (not just warnings)

Additional Context

This is blocking a critical quality enforcement mechanism for a financial trading system development project. The project has 14 hookify hooks configured to enforce:

  • Decimal precision for money (no float/double)
  • Database operation safety (architect consultation required)
  • GPU operation governance
  • AI/ML model registry compliance
  • Protocol v10.0.0 zero-tolerance policies

Without working pre_tool_use hooks, these enforcement mechanisms are non-functional.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.0.76

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

pm0code avatar Dec 26 '25 17:12 pm0code