PreToolUse/PostToolUse hooks fail mid-session with 'No such file or directory' despite files existing

Resolved 💬 3 comments Opened Dec 6, 2025 by mishkinf Closed Dec 9, 2025

Bug Description

PreToolUse, PostToolUse, and UserPromptSubmit hooks randomly start failing mid-session with "No such file or directory" errors, even though the hook script files exist and have correct permissions. Once the failure starts, it doesn't recover for the remainder of the session.

Environment

  • Claude Code Version: Latest (as of Dec 6, 2025)
  • Platform: macOS Darwin 25.1.0
  • Hook execution method: uv run .claude/hooks/script.py

Symptoms

  1. ✅ Hooks work correctly at session start
  2. ❌ After some time (often during complex multi-agent workflows), hooks start failing
  3. ❌ Once failures begin, they persist - no recovery without session restart
  4. ❌ Error message is misleading - claims file doesn't exist when it does

Error Messages

PreToolUse:Task hook error: [uv run .claude/hooks/pre_tool_use.py]: error: Failed to spawn: `.claude/hooks/pre_tool_use.py`
  Caused by: No such file or directory (os error 2)
UserPromptSubmit operation blocked by hook:
  [uv run .claude/hooks/user_prompt_submit.py --log-only --store-last-prompt --name-agent]: error: Failed to spawn: `.claude/hooks/user_prompt_submit.py`
    Caused by: No such file or directory (os error 2)

Verification That Files Exist

$ ls -la .claude/hooks/*.py
-rwxr-xr-x  1 user  staff  12222 Dec  5 23:15 .claude/hooks/notification.py
-rwxr-xr-x  1 user  staff   1234 Dec  5 23:15 .claude/hooks/post_tool_use.py
-rwxr-xr-x  1 user  staff   3941 Dec  5 23:15 .claude/hooks/pre_compact.py
-rwxr-xr-x  1 user  staff   5145 Dec  5 23:15 .claude/hooks/pre_tool_use.py
-rwxr-xr-x  1 user  staff   6629 Dec  5 23:15 .claude/hooks/session_start.py
-rwxr-xr-x  1 user  staff   7612 Dec  5 23:15 .claude/hooks/stop.py
-rwxr-xr-x  1 user  staff   5122 Dec  5 23:15 .claude/hooks/subagent_stop.py
-rw-r--r--  1 user  staff   6424 Dec  5 23:15 .claude/hooks/user_prompt_submit.py

$ pwd
/Users/user/workspace/project  # Correct working directory

$ which uv
/Users/user/.local/bin/uv  # uv is available

Observations

  • File descriptors: Session had ~15,774 open file descriptors when errors started (under limit but unusually high)
  • Trigger pattern: Often occurs during sessions with many Task subagent spawns (parallel E2B workers, explorers, etc.)
  • Bash tool still works: Direct Bash commands execute, but hook spawning fails

Difference from #6305

Issue #6305 reports hooks never triggering at all. This issue is different:

  • Hooks DO trigger initially
  • Hooks STOP working mid-session
  • Error claims file doesn't exist when it does
  • Suggests a resource exhaustion or state corruption issue in the spawn mechanism

Steps to Reproduce

  1. Start a Claude Code session with PreToolUse hooks configured
  2. Run a complex workflow with many subagents (Task tool with parallel workers)
  3. Continue working for an extended period
  4. Eventually, hook spawning starts failing with "No such file or directory"
  5. All subsequent hook invocations fail until session restart

Expected Behavior

Hooks should continue working throughout the session, or fail with an accurate error message if there's a resource issue.

Workaround

Restart the Claude Code session (/exit and reopen). Hooks work again after restart.

Suggested Investigation Areas

  1. Process spawn resource tracking/cleanup
  2. Working directory state during hook execution
  3. File descriptor management during long sessions
  4. The specific mechanism used to spawn uv run processes

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗