case-insensitive-guard — плагин для Claude Code: защита файлов
Плагин case-insensitive-guard для Claude Code перехватывает опасные файловые команды и блокирует удаление не того пути из-за регистра букв. Срабатывает на командах Bash вроде rm -rf.
MIT ★ 586 обновлён 2026-10-26
/plugin marketplace add karanb192/claude-code-hooks
/plugin install case-insensitive-guard@claude-code-hooksЧто делает case-insensitive-guard
Плагин проверяет команды Bash перед запуском и сопоставляет их цели с реальными путями в файловой системе. Если команда из-за регистра попадёт в файл или каталог с другим написанием имени, хук запретит её или запросит подтверждение. Он разбирает цепочки cd и pushd, подстановки оболочки и кавычки.
Уровень защиты задаёт переменная HOOK_SAFETY_LEVEL: critical, high или strict. Для каждого уровня можно включить запрос подтверждения через HOOK_ASK_CRITICAL, HOOK_ASK_HIGH или HOOK_ASK_STRICT. На файловой системе с учётом регистра хук не срабатывает; цели с $VAR и подстановками команд он пропускает. Команды, заблокированные или отправленные на подтверждение, записываются в ~/.claude/hooks-logs/<date>.jsonl; сетевых запросов плагин не делает.
Какие задачи решает
- не дать
rm -rf contentудалить каталогContent - перехватить удаление файла с несовпадающим регистром
- запретить
mvперезаписывать файл с другим написанием имени - настроить блокировку команд по уровню риска
Примеры запросов агенту
- Удали каталог
contentрекурсивно. - Перемести
readme.mdвREADME.md. - Создай файл
config.json.
Как установить case-insensitive-guard
Через маркетплейс плагинов
/plugin marketplace add karanb192/claude-code-hooks/plugin install case-insensitive-guard@claude-code-hooksПо шагам, с командами для каждой платформы: Плагины Claude Code: маркетплейсы, установка и как собрать свой
Вопросы о case-insensitive-guard
Как установить case-insensitive-guard в Claude Code?
Выполни /plugin marketplace add karanb192/claude-code-hooks, затем /plugin install case-insensitive-guard@claude-code-hooks и перезапусти Claude Code.
Что делает case-insensitive-guard?
Хук проверяет цели опасных команд Bash и блокирует те, что из-за регистра букв затронут другой файл или каталог на файловой системе без учёта регистра.
Какие уровни защиты есть у case-insensitive-guard?
critical блокирует рекурсивное удаление, high добавляет некоторые обычные удаления и перезапись файлов через mv, а strict также охватывает mkdir и touch. Для каждого уровня можно включить запрос подтверждения.
Исходный текст
case-insensitive-guard · MIT
# 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`.)
## 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.
© Karan Bansal · MIT · karanb192/claude-code-hooks