[BUG] PreToolUse and PostToolUse hooks not triggering on WSL2 despite correct configuration

Status Fixed / completed
Maintainer reply ✓ Yes — dicksontsai
Activity 8 comments · opened Jul 9, 2025 · closed Jul 28, 2025
💡 Likely answer: A maintainer (dicksontsai, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [X] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other:
  • Claude CLI version: 1.0.44 (Claude Code)
  • Operating System: Linux 5.15.167.4-microsoft-standard-WSL2
  • Terminal: Windows Terminal with WSL2

Bug Description

PreToolUse and PostToolUse hooks are not being triggered during tool use, despite following the documentation and having what appears to be correct configuration. The hooks are properly configured in .claude/settings.local.json with appropriate matchers, but they never execute when tools are used.

Steps to Reproduce

  1. Configure hooks in .claude/settings.local.json with the following structure:
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|Task|Read|Write|Edit|MultiEdit|Grep|Glob|LS|WebFetch|TodoRead|TodoWrite|NotebookRead|NotebookEdit|WebSearch",
        "hooks": [
          {
            "type": "command",
            "command": "/home/ruslan/.local/bin/uv run .claude/hooks/pre_tool_use.py"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Bash|Task|Read|Write|Edit|MultiEdit|Grep|Glob|LS|WebFetch|TodoRead|TodoWrite|NotebookRead|NotebookEdit|WebSearch",
        "hooks": [
          {
            "type": "command",
            "command": "/home/ruslan/.local/bin/uv run .claude/hooks/post_tool_use.py"
          }
        ]
      }
    ]
  }
}
  1. Ensure hook scripts exist and are executable
  2. Start Claude Code session: claude
  3. Use any tool (e.g., execute a Bash command)
  4. Check hook logs - no new entries are created

Expected Behavior

  • PreToolUse hook should execute before each tool invocation
  • PostToolUse hook should execute after each tool invocation
  • Hook scripts should log tool usage to JSON files
  • Hook processes should be visible in process list during execution

Actual Behavior

  • Hook scripts are never executed
  • Log files remain unchanged (last modified timestamp doesn't update despite active tool use)
  • No hook processes appear in process list during tool execution
  • Hook configuration appears to be ignored completely

Additional Context

  • Initially tried with empty matchers ("matcher": "") based on examples, which didn't work
  • Updated to explicit tool names based on issue #3091, still doesn't work
  • Tested in multiple modes: debug mode, normal mode, isolated session - same result
  • Hook scripts execute successfully when run manually from command line
  • Notification hooks appear to work (TTS processes visible), but PreToolUse/PostToolUse do not
  • Settings precedence was verified by consolidating to single .claude/settings.local.json file
  • Similar to issue #3091 but configuration appears to match recommended format

View original on GitHub ↗

8 Comments

dicksontsai collaborator · 1 year ago

Do you see them detected when you run /hooks and navigate to PreToolUse or PostToolUse?

jackstine · 1 year ago
betancourtfit · 1 year ago

Confirming the same bug on macOS

I can confirm this exact same issue on macOS with the same symptoms:

Environment:

  • Claude CLI version: 1.0.44 (Claude Code)
  • Operating System: macOS
  • Terminal: zsh with conda environment

Symptoms (identical to the original report):

  • PreToolUse and PostToolUse hooks are NOT triggered despite correct configuration
  • Notification hooks DO work perfectly (TTS, logging, etc.)
  • Hook scripts execute successfully when run manually from command line
  • Configuration is correct (verified multiple times through /hooks command)
  • Scripts have proper permissions and are executable

Testing performed:

  • Tested in multiple projects (both new and existing)
  • Verified hook configuration through Claude's /hooks interface
  • Confirmed hooks are properly saved in .claude/settings.local.json
  • Manual execution of hook scripts works perfectly
  • Tried both simple bash scripts and Python scripts with uv run
  • Tested with both "*" and specific tool matchers

Key observation:
The fact that Notification hooks work but PreToolUse/PostToolUse don't suggests this is a specific bug in Claude Code 1.0.44's hook execution system for these particular hook types.

Workaround:
Currently using Notification hooks as a temporary solution since they function correctly.

This confirms the bug affects multiple platforms (WSL2/Linux and macOS), making it likely a core issue in Claude Code 1.0.44 rather than platform-specific.

doggy8088 · 1 year ago

I'm using 1.0.52 on WSL. The problem still exist.

{
  "hooks": {
    "Notification": [
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "if echo '$(.tool_input.file_path)' | grep -q '\\.js$'; then npx prettier --write '$(.tool_input.file_path)'; fi"
          }
        ]
      },
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "jq '.' >> ~/.claude/PostToolUse-logs.jsonl"
          }
        ]
      }
    ]
  }
}

The first example is copy from the doc here: https://docs.anthropic.com/en/docs/claude-code/hooks-guide#code-formatting-hook

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "if echo '$(.tool_input.file_path)' | grep -q '\\.js$'; then npx prettier --write '$(.tool_input.file_path)'; fi"
          }
        ]
      }
    ]
  }
}

The second one do works.

I give a second try.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "if echo '$(.tool_input.file_path)' | grep -q '\\.js$'; then npx prettier --write '$(.tool_input.file_path)'; fi"
          },
          {
            "type": "command",
            "command": "jq '.' >> ~/.claude/PostToolUse-logs.jsonl"
          }
        ]
      }
    ]
  }
}

The second command works too. The first one still not run.

My third trial.

{
  "permissions": {
    "allow": [
      "Bash(echo:*)",
      "Bash(grep:*)",
      "Bash(npx prettier:*)"
    ],
    "deny": []
  },
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "if echo '$(.tool_input.file_path)' | grep -q '\\.ts$'; then npx prettier --write '$(.tool_input.file_path)'; fi"
          },
          {
            "type": "command",
            "command": "jq '.' >> ~/.claude/PostToolUse-logs.jsonl"
          }
        ]
      }
    ]
  }
}

The first command still not run.

doggy8088 · 1 year ago

I finally made it. This is the correct PostToolUse setup.

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Edit|MultiEdit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "jq -r '.tool_input.file_path' | while read -r f; do case \"$f\" in *.js) npx prettier --write \"$f\";; esac; done"
          },
          {
            "type": "command",
            "command": "jq '.' >> ~/.claude/PostToolUse-logs.jsonl"
          }
        ]
      }
    ]
  }
}

The previous command I tried and copied form Claude Code doc is wrong. The behavior is the Claude Code piping the hook payload to the command. So that I have to read the pipe and complete the whole thing in one statement.

dicksontsai collaborator · 1 year ago

@ericharmeling Can you look at the doc example and see if it needs to be updated? $(.tool_input.file_path) syntax doesn't seem to work for everyone.

lyallh · 1 year ago

Same issue and fix as @doggy8088 here on v1.0.61 in WSL2. Thanks for the fix.

github-actions[bot] · 1 year ago

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.