Skip to content

Case-insensitive filesystem guard (idea credit: @yurukusa, PR #8) #31

Description

@karanb192

PR #8 by @yurukusa proposed a genuinely good hook idea: on case-insensitive filesystems (APFS default, exFAT, NTFS), Content and content are the same path, and anthropics/claude-code#37875 documents real data loss from exactly this (rm -rf content destroying Content).

The submitted implementation couldn't ship as-is (verified against the PR script on an APFS volume):

  • Misses the motivating incident class: the parser is anchored to the start of the command string, so cd somewhere && rm -rf Content is allowed straight through (exit 0). Also missed: rm -i, multi-argument rm, globs.
  • Blocks harmless commands: mkdir -p Content is hard-blocked (exit 2) when a case-variant exists, even though mkdir -p there is a safe no-op.
  • No automated tests; not requirable (no module.exports guard), so it can't follow the repo's test pattern.

Requirements for a house-standard implementation

  • Tokenize compound commands (&&, ;, |) and check every rm/mv/destructive segment, not just a start-anchored match
  • Resolve targets against the hook-provided cwd (and any preceding cd in the same command)
  • Handle multi-arg rm, globs, quoted paths
  • Warn/deny only for destructive collisions; never block safe no-ops like mkdir -p
  • Per-directory case-insensitivity probe (volumes differ) with cleanup
  • House standards: JSDoc header + settings snippet, defensive stdin (garbage/empty → {} exit 0), require.main guard + pure-function exports, hermetic tests

Credit for the idea and the incident research goes to @yurukusa.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions