Skip to content

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

Description

@Julian-Genuario

Summary

The vendored PreToolUse hooks match paths with POSIX-only regexes, so on Windows the .env protection and the database module's migration protection never fire. Claude Code on Windows hands the hook tool_input.file_path with backslashes, the regex does not match, the hook exits 0 and the write goes through.

Where

  • packages/cli/templates/claude/hooks/protect-files.mjs:29: /(^|\/)\.env(\.[\w.]+)?$/.test(filePath)
  • packages/cli/modules/database/hooks/protect-migrations.fragment.mjs:27: /(^|\/)(supabase\/|db\/|prisma\/)?migrations\/[^/]+\.(sql|js|ts|rb|py)$/
  • same pattern in .github/facility/doctor/resolve.mjs SENSITIVE_PATHS if that ever runs on a Windows runner.

Repro (Windows 11, Node 24, facility main)

printf '{"tool_name":"Write","tool_input":{"file_path":"/repo/.env"}}'      | node protect-files.mjs ; echo $?   # 2  (blocked)
printf '{"tool_name":"Write","tool_input":{"file_path":"C:\repo\.env"}}' | node protect-files.mjs ; echo $?   # 0  (allowed)

Same with C:\repo\supabase\migrations\0001_init.sql → allowed; the forward-slash form → blocked.

Why it matters

The hooks are the local half of the "protect files / protect branch" story that init prints and STANDARD.md relies on; on Windows they are installed, listed as ✓ by doctor, and inert. Nothing tells the user. Runners in CI are Linux so this only bites developers running the agents locally, but that is exactly where .env files with real secrets live.

Suggested fix

Normalise once at the top of each hook: const filePath = String(raw).replace(/\/g, "/"), and add a hook test with a backslash path. Related in spirit to #173 (Windows paths in guards), different files.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions