-
Notifications
You must be signed in to change notification settings - Fork 503
Description
PreToolUse hooks are not invoked when Claude calls the Read tool with a file path that doesn't exist. The hook is only called when the file exists. This contradicts the official documentation which states that PreToolUse hooks execute "after Claude creates tool parameters and before processing the tool call".
This breaks legitimate use cases like path translation where hooks need to modify file paths before validation occurs.
Expected Behavior
According to the documentation, PreToolUse hooks should be called before the tool processes the call, allowing hooks to:
- Validate inputs
- Modify tool parameters using
updatedInput - Block execution with
permissionDecision: "deny"
The hook should be invoked regardless of whether the file exists.
Actual Behavior
When Claude calls Read with a non-existent file path:
- The SDK validates that the file doesn't exist
- The SDK returns "File does not exist" error
- The PreToolUse hook is never called
When Claude calls Read with an existing file path:
- The PreToolUse hook is called ✅
- The file is read successfully ✅
Reproduction
See the minimal reproduction script: reproduce_hook_bug.py
Run it:
pip install claude-agent-sdk
python reproduce_hook_bug.pyExpected output:
[HOOK CALLED] for TEST 1 (/workspace/test.txt)
[HOOK CALLED] for TEST 2 (/tmp/hook_test/test.txt)
Actual output:
[HOOK CALLED] for TEST 2 only (/tmp/hook_test/test.txt)
Environment
- Claude Code: 2.0.35 (latest)
- claude-agent-sdk: 0.1.6 (latest - tested on 0.1.4, 0.1.5, 0.1.6)
- Python: 3.11
- OS: Linux
Impact
This bug breaks:
- Path translation hooks - Cannot translate paths like
/workspace/*to actual locations before validation - Custom file resolution - Cannot implement custom file lookup logic
- Input sanitization - Cannot normalize/validate file paths before they're checked
- Audit logging - Cannot log all Read attempts, only successful ones
The updatedInput feature is essentially useless for file path modification because hooks don't fire early enough.
Workaround
None found. The only way to make hooks work is to ensure files exist at the exact paths Claude uses, which defeats the purpose of path translation hooks.
Related Issues
Similar to #7082 but different - that issue was about permission deny rules, this is about hooks not being called at all for non-existent paths.