Skip to content

fix: make hooks work on Windows by loading scripts long-path-safe#21

Merged
viragtripathi merged 3 commits into
mainfrom
fix/windows-hook-maxpath
Jun 30, 2026
Merged

fix: make hooks work on Windows by loading scripts long-path-safe#21
viragtripathi merged 3 commits into
mainfrom
fix/windows-hook-maxpath

Conversation

@viragtripathi

@viragtripathi viragtripathi commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

What

Fixes #20. Fixes #23. Both report the same symptom (a hook error block on every Write/Edit/MultiEdit) from two different causes:

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 0 so 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 .py scripts 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:

All pass locally.

Notes

  • VS Code ignores hook matchers, and the Write|Edit|MultiEdit matcher cannot filter by file type before process start, so the script's extension filter only helps after startup. The ; exit 0 guard is what prevents the block when startup itself fails.
  • Also updates CONTRIBUTING with the long-path-safe hook pattern and a Windows note in the README, and drops the hardcoded backend/agent counts from the descriptions.

…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.
@viragtripathi viragtripathi merged commit 81f29eb into main Jun 30, 2026
1 check passed
@viragtripathi viragtripathi deleted the fix/windows-hook-maxpath branch June 30, 2026 21:03
@viragtripathi viragtripathi mentioned this pull request Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostToolUse hook PostToolUse hook fails on Windows: ${CLAUDE_PLUGIN_ROOT} path exceeds MAX_PATH

1 participant