PreToolUse hooks not executing at all in Claude Code
PreToolUse hooks not executing at all in Claude Code
Environment
- Claude Code Version: 1.0.53 (npm-local)
- Operating System: macOS Darwin 24.5.0
- Node.js Version: v22.17.0
Bug Description
PreToolUse hooks are not executing at all, despite following various configuration formats suggested by error messages. Additionally, claude doctor reports configuration errors regardless of the format used.
Reproduction Steps
- Create
/Users/cesar/.claude/settings.jsonwith the following configuration:
{
"hooks": {
"preToolUse": [
{
"matcher": {},
"hooks": [
{
"type": "command",
"command": "~/.claude/wing-coding/check-log-time.sh"
}
]
}
]
}
}
- Create a test script at
~/.claude/wing-coding/check-log-time.sh:
#!/bin/bash
echo "Hook executed at $(date)" >> /tmp/claude-hook-test.log
- Make the script executable:
chmod +x ~/.claude/wing-coding/check-log-time.sh
- Run
claude doctorand observe the error:
Invalid Settings
/Users/cesar/.claude/settings.json
└ hooks
└ preToolUse: Expected array, but received object
- Use any Claude tool (e.g.,
ls,grep,read)
- Check if the hook executed:
cat /tmp/claude-hook-test.log
# File does not exist - hook never executed
Expected Behavior
- The hook script should execute before each tool use
claude doctorshould accept valid hook configurations- A log entry should be created in
/tmp/claude-hook-test.log
Actual Behavior
- Hook never executes under any configuration
claude doctorrejects all configuration formats tried- No log file is created, indicating the hook is never called
Additional Context
- This appears related to issue #3514 which reported similar problems in v1.0.51
- The bug persists in v1.0.53, indicating it hasn't been fixed
- Tried multiple configuration formats based on error message suggestions:
- With
hookswrapper object - With capitalized
PreToolUsekey - With and without matchers
- The hook script works correctly when executed manually
Impact
This prevents users from implementing critical workflow automation and monitoring features via hooks, which is essential for production use cases.
Full File Contents
Current settings.json
{
"PreToolUse": [
{
"matcher": {},
"hooks": [
{
"type": "command",
"command": "~/.claude/wing-coding/check-log-time.sh"
}
]
}
]
}
Hook script (check-log-time.sh)
#!/bin/bash
echo "Hook executed at $(date)" >> /tmp/claude-hook-test.log
Claude doctor output
Claude CLI Diagnostic
Currently running: npm-local (1.0.53)
Path: /Users/cesar/.nvm/versions/node/v22.17.0/bin/node
Invoked: /Users/cesar/.claude/local/node_modules/.bin/claude
Config install method: local
Auto-updates enabled: true
Invalid Settings
/Users/cesar/.claude/settings.json
└ hooks
└ preToolUse: Expected array, but received object
Hooks use a new format with matchers. Example: {"PostToolUse": [{"matcher": {"tools": ["BashTool"]}, "hooks": [{"type":
"command", "command": "echo Done"}]}]}
Learn more: https://docs.anthropic.com/en/docs/claude-code/hooks
---
This issue report was generated collaboratively using Wing Coding methodology - a human-AI pair programming approach where César (human pilot) directs Claude (AI wingman) in real-time development sessions. Wing Coding combines human architectural vision with AI implementation capabilities to achieve 3-5x development velocity. Learn more: Wing Coding on LinkedIn
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗