fix: make hooks work on Windows by loading scripts long-path-safe#21
Merged
Conversation
…dows
The PreToolUse and PostToolUse hooks passed the full ${CLAUDE_PLUGIN_ROOT}
script path to python3. On Windows that path lives in a deeply nested plugin
cache and can go past the 260 character MAX_PATH limit, so python could not
open the script and errored on every matched edit or SQL call.
The hooks now run a small inline bootstrap that loads the script with runpy
and, on Windows, prefixes the path with the \\?\ long-path escape that gets
around MAX_PATH. The bootstrap has no long path to open itself, the existing
scripts stay the single source of truth, and the trailing "; exit 0" keeps a
failed bootstrap from interrupting editing.
Fixes #20
Update the CONTRIBUTING hook guidance to show the long-path-safe bootstrap so new hooks do not bring the Windows MAX_PATH problem back. Add a Windows note to the README that explains hooks need python3 on PATH and that long-path support is not required. Also remove the fixed backend and agent counts from the plugin description, marketplace entry, and README intro so they do not go stale as the plugin grows.
Covers issue #20 (resolved path exceeds Windows MAX_PATH) and issue #23 (${CLAUDE_PLUGIN_ROOT} not substituted by the host): in both cases the interpreter cannot open the script, and the hook must exit 0 with no user-visible block so editing is never interrupted. Also asserts the positive deny/warn/lint cases. Runs in CI on changes to hooks or scripts.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #20. Fixes #23. Both report the same symptom (a hook error block on every Write/Edit/MultiEdit) from two different causes:
${CLAUDE_PLUGIN_ROOT}is substituted, but on Windows the resolved plugin-cache path exceeds the 260-character MAX_PATH limit, so Python cannot open the hook script.${CLAUDE_PLUGIN_ROOT}is not substituted at all; the literal token is passed to Python, which then cannot open the path.Fix
The hooks now run a small inline bootstrap that loads the script with
runpy, prefixing the path with the\\?\long-path escape on Windows (fixes the MAX_PATH case), and a trailing; exit 0so that whenever the interpreter cannot open the script the hook still exits 0 and surfaces no block. That makes the editor experience clean in both the MAX_PATH case and the unsubstituted-token case. The existing.pyscripts stay as the single source of truth.When the token is unsubstituted (the #23 runtime), the lint cannot run (that substitution is the host's responsibility, not something the plugin can force), but it now degrades silently instead of erroring on every edit, which is the actual UX complaint in both issues.
Tests
Adds
scripts/test-hooks.sh(run in CI via.github/workflows/test-hooks.yml) asserting:permissionDecision: deny)All pass locally.
Notes
Write|Edit|MultiEditmatcher cannot filter by file type before process start, so the script's extension filter only helps after startup. The; exit 0guard is what prevents the block when startup itself fails.