[BUG] Hookify plugin fails with 'Invalid \escape' JSON error on Windows due to unescaped backslashes in file paths
Bug Description
The hookify plugin's PreToolUse hook fails on Windows with a JSON parse error when processing file paths containing backslashes.
Error message:
PreToolUse:Read says: Hookify error: Invalid \escape: line 1 column 372 (char 371)
Root Cause Analysis
When Claude Code invokes the PreToolUse:Read hook, it passes JSON data containing Windows file paths (e.g., C:\Users\username\file.txt). The issue is:
- Windows paths use backslashes (
\) as path separators - In JSON, backslashes must be escaped as
\ - Sequences like
\U(from\Users) or\kare interpreted as invalid escape sequences - Python's
json.loads()inpretooluse.py:40fails to parse the JSON
Location of the issue: The JSON data passed to the hook stdin contains unescaped Windows paths.
Steps to Reproduce
- Use Claude Code on Windows
- Enable the hookify plugin (
hookify@claude-plugins-official) - Have any hookify rules configured (e.g., in
.claude/hookify.*.local.md) - Trigger a
Readtool operation on any file - Observe the error:
Hookify error: Invalid \escape: line 1 column 372 (char 371)
Expected Behavior
The JSON data passed to hooks should have properly escaped backslashes in file paths:
- Wrong:
{"file_path": "C:\Users\koala\file.txt"} - Correct:
{"file_path": "C:\Users\koala\file.txt"}
Environment
| Field | Value |
|-------|-------|
| Claude Code Version | Latest |
| OS | Windows 11 (MSYS_NT-10.0-22631) |
| Platform | win32 |
| Shell | Git Bash / MSYS2 |
Related Issues
- #15481 - Windows paths with spaces issue
- #16152 - Hooks fail when user path contains spaces
- #13612 - hookify import error
Suggested Fix
Ensure that file paths in the JSON data passed to hooks are properly JSON-escaped before being sent to stdin. This likely needs to be fixed in Claude Code's hook invocation code, not in the hookify plugin itself.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗