Hooks not executing despite following documentation
Status Fixed / completed
Maintainer reply ✓ Yes — dicksontsai
Workaround ✓ Mentioned in thread ↓
Activity 11 comments · opened Jul 2, 2025 · closed Jan 15, 2026
💡 Likely answer: A maintainer (dicksontsai, collaborator)
responded on this thread — see the highlighted reply below.
Hook Functionality Verification Report
Environment
- Claude Code Version: 0.10.14 (from ps output)
- OS: Ubuntu 24.04.2 LTS
- Date: 2025-07-02
Test Methodology
1. Hook Setup
Created executable hook scripts in ~/.claude/hooks/:
pre-tool(chmod +x)post-tool(chmod +x)pre-edit(chmod +x)
Each hook logs to /tmp/claude_hooks_*.log when executed.
2. Configuration
Added hook configuration to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/pre-tool"
}
]
}
],
"PostToolUse": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/post-tool"
}
]
}
]
}
}
3. Tests Performed
- Multiple Bash commands executed
- File creation using Write tool
- File editing using Edit tool
- Checked for log files after each operation
4. Results
- No log files created in
/tmp/claude_hooks_*.log - Manual execution of hooks works correctly
- Hooks do not appear to execute automatically during tool use
Observations
- Claude Code process running with flags:
--dangerously-skip-permissions --mcp-config "/home/graham/.claude/claude_code/.mcp.json" --continue - No hook-related processes detected during tool execution
- Settings file is valid JSON and readable
Questions
- Are there additional configuration steps required to enable hooks?
- Is there a specific flag needed when launching Claude Code?
- Are hooks only available in certain versions or editions?
Reproduction Steps
- Create hook script:
echo '#!/bin/bash\necho "Hook executed" > /tmp/hook_test.log' > ~/.claude/hooks/pre-tool && chmod +x ~/.claude/hooks/pre-tool - Configure in
~/.claude/settings.jsonas shown above - Execute any Bash command through Claude Code
- Check for
/tmp/hook_test.log- file is not created
Would appreciate clarification on whether hooks are currently functional and if there are additional setup requirements.
11 Comments
Update: Tested suggested fixes - hooks still not executing
Thank you for the configuration feedback. I've implemented all suggested changes:
Changes Made:
~/.claude/hooks/pre-toolto absolute paths/home/graham/.claude/hooks/pre-toolpython3 -m json.toolvalidation.claude/settings.jsonin the project directory-rwxrwxr-x)Additional Testing:
/hookscommand as suggested - command not foundCurrent Configuration:
Result:
Despite implementing all suggested fixes, hooks still do not execute. No logs are created, no processes spawn, and the
/hookscommand mentioned in the documentation does not exist in my Claude Code installation.Could this be a version-specific issue? The
/hooksslash command doesn't appear to be available in version 0.10.14.Workaround Solution
Since Claude Code hooks are not executing, here's a workaround that ensures deterministic hook execution:
Simple Python-based approach:
Instead of relying on Claude Code's hook system, modify your application to run hooks before launching subprocesses:
This approach:
The key insight from perplexity: Don't overcomplicate with wrapper scripts. Just run hooks in Python and pass the modified environment to subprocess via the
envparameter.### Temporary Workaround
Instead of relying on Claude Code to run hooks, I intercept
commands before they're executed and run the hooks
programmatically:
```python
# In websocket_handler.py or wherever you launch Claude
if "claude" in command.lower():
# Run pre-execution hooks directly
hooks_dir = Path.home() / ".claude" / "hooks"
for hook in ["pre-tool", "setup_environment.py"]:
hook_path = hooks_dir / hook
if hook_path.exists():
subprocess.run([sys.executable, str(hook_path)],
check=True)
# Setup environment for subprocess
env = os.environ.copy()
venv_path = Path(".venv")
if venv_path.exists():
env["VIRTUAL_ENV"] = str(venv_path)
env["PATH"] = f"{venv_path}/bin:" + env["PATH"]
# Execute with modified environment
result = subprocess.run(command, env=env, shell=True)
Test Results
From my testing, this approach seems to work with:
All three test cases showed:
dependency checks)
output validation)
Why I Think This Works
This approach seems to bypass the Claude Code hook system
entirely by:
environment
The hooks execute deterministically because they run before the
subprocess starts, not relying on the AI's voluntary compliance.
This workaround is keeping me unblocked for now, but it's
definitely not ideal. I hope for a proper working solution using claude code hooks.
Note: I could simply be doing this wrong, and would love to be corrected.
Adding determinism (pre and post) is crucial to an agent that simply forgets or refuses to follow instructions.
You can use
claude --debugto look at whether Claude is picking up your hooks. You should see output like the following if there's a match.Another thing you can try is to add a hook manually with
/hooksand see if the same user-level settings file gets edited.Thanks. I gave it shot... https://github.com/grahama1970/claude-code-hooks-test. As of yet, I can't get hooks to work reliably.
I 'think' it has something to do with me using --dangerously-skip-permissions. Not using the parameter would be a deal breaker for me.
On a positive note, this alternative is nearly complete: https://github.com/grahama1970/cc_executor, which might solve my immediate issues with hooks, and other challenges.
Maybe, on your end, you have a proof of concept example that tests a moderately complex example over 10x times to prove that Anthropic hooks are deterministic (work 100% of the time) and NOT agent optional? That would be lovely and helpful to many here with similar issues, I presume.
Onward and upwards
To utilize hooks, you must use a version of Claude Code that includes hook support. Hooks were first introduced in version 1.0.38 released on July 1, 2025 (https://github.com/anthropics/claude-code/commit/390f11039c4986f2172aae21c6380d2b5a8b251e), with the current latest version as of July 15, 2025 being 1.0.51. To update, install Claude Code using the command:
npm install -g @anthropic-ai/claude-code.FWIW I cloned your github repo and got the following output with
--dangerously-skip-permissions. I did remove thelogurulines.I wonder if there's something related to your shell setup.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
~Hooks don’t work for me at all on macOS Tahoe
26.1, claude code2.0.69installed with the bash script.Tried uninstall/reinstalling claude code and still didn’t fix.~
Turns out they just don’t work from the home directory.
this is done on the latest version of claude.code Claude Code v2.1.4
▝▜█████▛▘ Sonnet 4.5 · Claude Max
update # Bug Report: Claude Code Hooks Not Triggering Automatically
Date: 2026-01-11
Claude Code Version: CLI
Environment: Ubuntu 22.04
Severity: Medium - Feature Not Working
Issue Description
Hooks configured in
.claude/settings.jsondo not trigger automatically despite correct and validated configuration.Configuration Tested
.claude/settings.jsonHook Script (Works Manually)
Tests Performed
✅ Manual Test (Works)
❌ Automatic Test (Does NOT Work)
/mnt/erp-core/erp-api/test-hook.pywith hardcoded errorsEditon this file via Claude CodeWritea new.pyfilefinal-check.shnot executedEnvironment Verified
/mnt/erp-core(correct).claude/settings.jsonpresent and validchmod +x)jqinstalled for JSON parsingEdit|Write,*)Alternative Configurations Tested
| Configuration | Result |
|---------------|--------|
| Matcher:
Edit:*.py\|Write:*.py| ❌ Doesn't work || Matcher:
Edit\|Write| ❌ Doesn't work || Relative path:
.claude/hooks/...| ❌ Doesn't work || Absolute path:
/mnt/erp-core/.claude/hooks/...| ❌ Doesn't work |Expected Behavior
When
EditorWriteis performed on a.py,.js, or.jsxfile:tool_input.file_pathActual Behavior
Current Workaround
Added to
CLAUDE.md:Claude must manually execute the hook via
Bashafter each modification.Impact
Questions
PostToolUseandStophooks supported in Claude Code CLI?Request
Logs/Traces
No hook execution traces in:
/tmp/claude*(temporary files)CLAUDECODE=1present---
Reproducible: 100%
Contact: Via GitHub Issues https://github.com/anthropics/claude-code/issues
@drouleau-gtvr you should use
CLAUDE_PROJECT_DIRand not depend on relative paths https://code.claude.com/docs/en/hooks#project-specific-hook-scripts.This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.