Claude Code · HooksPreToolUse
case-insensitive-guard
Evita borrar carpetas por confusión de mayúsculas en macOS y Windows.
por Karan Bansal
PreToolUse
Licencia: MITVer original
Instalación
/plugin marketplace add karanb192/claude-code-hooks
/plugin install case-insensitive-guard@claude-code-hooksContenido
# case-insensitive-guard
> Stops `rm -rf content` silently destroying `Content` on case-insensitive filesystems (APFS default, exFAT, NTFS).
On a case-insensitive volume, `Content` and `content` are the same path, so a miscased delete lands on the real directory anyway (see [anthropics/claude-code#37875](https://github.com/anthropics/claude-code/issues/37875)). A `PreToolUse` hook on `Bash` resolves the real target of destructive commands (`rm`, `rmdir`, `mv`, `mkdir`, `touch`, `find -delete` and `find -exec rm/unlink`) and denies the ones that would hit a differently-cased entry of what was typed. Directory context is modeled properly: `cd`/`pushd`/`popd` chains, `&&`/`||`/`;`/`|`/`&` connectors gated by exit status, subshell scoping, heredoc stripping, quotes and escapes, and wrapper prefixes (`sudo`, `nohup`, `exec`, `env`, ...). No probe files: case-insensitivity is proven by the collision itself (the typed name is absent from `readdir()` yet the path still exists).
Idea credit: [@yurukusa](https://github.com/karanb192/claude-code-hooks/pull/8).
## Install
```
/plugin marketplace add karanb192/claude-code-hooks # once per machine
/plugin install case-insensitive-guard@claude-code-hooks
```
Restart Claude Code, done. (Or from a shell: `claude plugin install case-insensitive-guard@claude-code-hooks`.)
## Codex CLI
```sh
codex plugin marketplace add karanb192/claude-code-hooks
codex plugin add case-insensitive-guard@claude-code-hooks
```
Open `/hooks` in Codex and approve this plugin. Re-approve after every update; Codex skips unapproved or changed hooks. Do not install it alongside [guard-pack](../guard-pack#codex-cli), which includes this guard.
This entry point checks `Bash` and native `apply_patch` calls. Patch files are checked individually; unreadable patches are blocked. Shell patches must use a plain command with a quoted heredoc. Literal searches and commit messages mentioning `apply_patch` pass. See [the shared adapter's limits](../guard-pack#codex-cli), including shell sessions and dynamically constructed commands.
Export configuration variables before launching Codex. An ask-mode match becomes a block because Codex hooks cannot ask. Logs stay in `~/.claude/hooks-logs/` with `host: "codex"`, including on Codex-only machines.
## What it does
| Event | Runs | What happens |
|-------|------|--------------|
| PreToolUse (`Bash`) | sync (it must answer before the command runs) | Parses the command, resolves every destructive target against the real filesystem, and returns `permissionDecision: "deny"` (or `"ask"`, see below) with both names in the reason when a case-variant would be hit. Safe commands pass through untouched. |
What it deliberately does NOT flag: glob targets (shell glob matching is case-sensitive), `$VAR`/`$( )`/backtick targets (not statically resolvable, conservatively allowed), exact-case deletes (intentional), a case-only rename like `mv readme.md README.md` (the canonical fix), `mv -t DIR` (moves INTO a directory), plain `rm` of a case-variant directory (`rm` refuses directories, nothing is destroyed), and heredoc bodies (document text, not commands). On a case-sensitive volume it never fires: the miscased command fails harmlessly on its own.
## Configuration
All optional, set via environment variables:
| Variable | Default | Purpose |
|----------|---------|---------|
| `HOOK_SAFETY_LEVEL` | `high` | Safety level: `critical`, `high`, or `strict`. Invalid values fall back to `high`. Prefer this over editing the script (plugin updates overwrite installed files). |
| `HOOK_ASK_CRITICAL` | unset (deny) | Literal string `true`: `critical`-level hits prompt for approval instead of denying. |
| `HOOK_ASK_HIGH` | unset (deny) | Literal string `true`: `high`-level hits prompt instead of denying. |
| `HOOK_ASK_STRICT` | unset (deny) | Literal string `true`: `strict`-level hits prompt instead of denying. |
Safety levels are cumulative:
| Level | Blocks |
|-------|--------|
| `critical` | Recursive `rm -r/-rf` (and `find -delete`) onto a case-variant |
| `high` | + non-recursive deletes that really remove something: `rm` of a case-variant FILE, `rm -d`/`rmdir` of a case-variant dir, `mv` overwriting a case-variant FILE |
| `strict` | + `mkdir`/`touch` onto an existing case-variant (usually a no-op, but often a sign the agent has the wrong name in mind) |
Set them inline in your hook command, or export them in your shell profile:
```json
{
"type": "command",
"command": "HOOK_SAFETY_LEVEL=strict HOOK_ASK_STRICT=true node \"${CLAUDE_PLUGIN_ROOT}/case-insensitive-guard.js\""
}
```
## Data & privacy
Blocked/asked commands are logged to `~/.claude/hooks-logs/<date>.jsonl` (command, typed vs actual name, session id). It makes no network calls (the script only uses `fs`, `path`, and `os`), so everything stays on your local machine.
## Uninstall
```
/plugin uninstall case-insensitive-guard@claude-code-hooks
```
Part of [claude-code-hooks](https://github.com/karanb192/claude-code-hooks): production-ready Claude Code hooks, each installable on its own as a plugin.
Más en Hooks
Formatear al editar
Ejecuta Prettier sobre cada archivo que Claude edita o crea.
Bloquear archivos .env
Impide que Claude lea o edite archivos de secretos.
Aviso al terminar
Notificación de escritorio en macOS cuando Claude termina.
Chequeo de tipos al editar
Corre tsc después de editar archivos TypeScript y muestra los errores.
Contexto al iniciar
Carga la rama y los últimos commits al abrir una sesión.
Registro de comandos
Guarda cada comando de shell en un log para auditoría.