Skip to content

fix(cli): normalize Windows backslash paths in protect-files hook - #242

Open
ale-aguirre wants to merge 2 commits into
theam:mainfrom
ale-aguirre:fix/227-windows-path-hooks
Open

fix(cli): normalize Windows backslash paths in protect-files hook#242
ale-aguirre wants to merge 2 commits into
theam:mainfrom
ale-aguirre:fix/227-windows-path-hooks

Conversation

@ale-aguirre

Copy link
Copy Markdown

What changes

protect-files.mjs (and the database module's migration guard, which gets
spliced into the same file) now normalizes tool_input.file_path before
matching 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_path with backslashes. The guards are
POSIX-only regexes, so on Windows the .env protection and the migration
protection never fire. The hook exits 0 and the write goes through, and
doctor still reports the hook as installed and correct.

Fixes #227.

Left .github/facility/doctor/resolve.mjs alone. Its SENSITIVE_PATHS check
only ever sees paths from the GitHub API or git diff, both always
forward-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 verify passes locally — couldn't run it, this checkout has no
    node_modules installed and I didn't want to pull a full monorepo
    install just to touch one file. Said so instead of guessing.
  • Behaviour verified beyond the test suite: ran protect-files.mjs
    directly with node on Windows 11, before and after the fix, feeding
    it the same JSON Claude Code sends on stdin. POSIX .env path blocked
    both times, Windows .env path went from exit 0 to exit 2, and
    .env.example stays allowed on both path styles.
  • Added a test in packages/cli/test/init.test.mjs that spawns the
    installed hook with a Windows-style path, for both the base .env
    guard and the database module's migration guard.
  • Documentation updated, or no user-facing change — no doc describes
    this hook's internals, nothing to update.

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 adrian-lorenzo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this!

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.

PreToolUse hooks are POSIX-path-only: .env and migration protection silently do nothing on Windows

2 participants