fix(cli): normalize Windows backslash paths in protect-files hook - #242
Open
ale-aguirre wants to merge 2 commits into
Open
fix(cli): normalize Windows backslash paths in protect-files hook#242ale-aguirre wants to merge 2 commits into
ale-aguirre wants to merge 2 commits into
Conversation
Claude Code on Windows sends tool_input.file_path with backslashes. The .env guard and the database module's migration guard spliced into the same file both match with POSIX-only regexes, so on Windows both silently allow what they are meant to block, and doctor still reports the hook as correct. Normalize the path once, right after it is read, so every guard in this file (including module fragments spliced in later) gets a forward-slash path regardless of OS. Left .github/facility/doctor/resolve.mjs untouched: its SENSITIVE_PATHS check only ever sees paths from the GitHub API / git diff, which are always forward-slash, and its workflow is pinned to ubuntu-latest, so it has no reachable Windows-backslash input. Fixes theam#227
adrian-lorenzo
approved these changes
Sep 1, 2026
adrian-lorenzo
left a comment
Member
There was a problem hiding this comment.
Thanks for fixing this!
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 changes
protect-files.mjs(and the database module's migration guard, which getsspliced into the same file) now normalizes
tool_input.file_pathbeforematching it against the regex guards. Backslashes become forward slashes, so
a Windows path matches the same way a POSIX one already did.
Why
Claude Code on Windows sends
file_pathwith backslashes. The guards arePOSIX-only regexes, so on Windows the
.envprotection and the migrationprotection never fire. The hook exits 0 and the write goes through, and
doctorstill reports the hook as installed and correct.Fixes #227.
Left
.github/facility/doctor/resolve.mjsalone. ItsSENSITIVE_PATHScheckonly ever sees paths from the GitHub API or
git diff, both alwaysforward-slash regardless of OS, and its workflow is pinned to
ubuntu-latest, so there's no Windows-backslash path that ever reaches it.Verification
pnpm verifypasses locally — couldn't run it, this checkout has nonode_modulesinstalled and I didn't want to pull a full monorepoinstall just to touch one file. Said so instead of guessing.
protect-files.mjsdirectly with
nodeon Windows 11, before and after the fix, feedingit the same JSON Claude Code sends on stdin. POSIX
.envpath blockedboth times, Windows
.envpath went from exit 0 to exit 2, and.env.examplestays allowed on both path styles.packages/cli/test/init.test.mjsthat spawns theinstalled hook with a Windows-style path, for both the base
.envguard and the database module's migration guard.
this hook's internals, nothing to update.