PostToolUse hooks not triggering for Edit operations on .cs files
PostToolUse hooks not triggering for Edit operations on .cs files
Summary
PostToolUse hooks configured in .claude/settings.json are not executing after Edit, MultiEdit, or Write operations on C# files, despite having a properly configured matcher pattern and verbose mode enabled.
Environment
- Claude Code Version: 1.0.70
- Operating System: macOS 15.6 (24G84)
- Kernel: Darwin 24.6.0
- User Setup:
claude --dangerously-skip-permissions(aliased) - System Integrity Protection: Disabled
Configuration
.claude/settings.json
{
"enableAllProjectMcpServers": true,
"verbose": true,
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|MultiEdit|Write:.*\\.cs$",
"name": "Format and Build C# Files",
"description": "Formats the code and builds the project after editing C# files.",
"type": "command",
"command": "dotnet format -v normal && dotnet build --no-restore",
"timeout": 180
}
]
}
}
Problem Description
The hook should trigger after any Edit, MultiEdit, or Write operation on files matching the pattern .*\\.cs$, but it completely fails to execute.
Reproduction Steps
- Setup: Create
.claude/settings.jsonwith the configuration above - Create test file: Create any
.csfile (tested both at project root and within src/ directories) - Edit operation: Use the
Edittool to modify the .cs file - Expected behavior: Hook should execute
dotnet format -v normal && dotnet build --no-restore - Actual behavior: No hook execution occurs, no output or error messages
Tested Files
/Users/wangkanai/Sources/sathai/test-hook-csharp.cs(project root)/Users/wangkanai/Sources/sathai/src/Web/Controllers/HomeController.cs(within project structure)
Edit Operations Performed
# Test 1: Root level file
Edit tool on test-hook-csharp.cs
Result: Hook did not trigger
# Test 2: Project structure file
Edit tool on src/Web/Controllers/HomeController.cs
Result: Hook did not trigger
Configuration Analysis
- Matcher Pattern:
Edit|MultiEdit|Write:.*\\.cs$- Should match any .cs file after Edit/MultiEdit/Write operations - Verbose Mode: Enabled (
"verbose": true) - Should show hook execution details - Timeout: 180 seconds - Sufficient for dotnet operations
- Command:
dotnet format -v normal && dotnet build --no-restore- Valid dotnet commands
Expected Behavior
With verbose mode enabled, we should see:
- Hook matching confirmation when editing .cs files
- Command execution output from
dotnet format -v normal - Command execution output from
dotnet build --no-restore - Success/failure status of hook execution
Actual Behavior
- No output indicating hook matching
- No command execution
- No errors or warnings about hook failures
- Silent failure with no indication of why hooks aren't triggering
Debugging Attempts
- Pattern Verification: The regex
.*\\.cs$should match all .cs files - File Path Testing: Tested files at different directory levels
- Tool Verification: Confirmed Edit tool successfully modifies files
- Configuration Syntax: JSON syntax is valid and follows documented format
Potential Issues
- Pattern Matching: The matcher pattern may not be working as expected
- Tool Name Recognition: The
Edit|MultiEdit|Write:prefix may not be matching correctly - File Path Resolution: Hook system may not be resolving file paths properly
- Working Directory: Commands may need specific working directory context
- Hook Execution Environment: There may be an issue with the hook execution environment
Additional Context
This is part of a comprehensive hook validation system for a .NET 9.0 project with multiple file types (C#, CSHTML, Razor, SCSS, PowerShell, JSON). The C# hook configuration follows the same pattern as documented examples but fails to execute.
Request
Please investigate why PostToolUse hooks are not triggering for Edit operations on .cs files despite apparently correct configuration. Verbose mode should provide debugging output but currently shows nothing related to hook execution attempts.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗