Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By hughescrIn 1 marketplace
Denies Bash git commands that discard uncommitted work (checkout --, restore, reset --hard, clean -f)
Code that runs inside Claude Code on every session, as you, unsandboxed.
1 critical to review before installing
JavaScript or TypeScript that runs inside Claude Code as you, unsandboxed. Read from its source, it sees, changes or blocks tool calls.
Static checks of hooks, mods, MCP servers and commands. Not a security audit.
1 marketplace, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
An in-process tool.call mod that denies Bash git commands which silently discard uncommitted work. It
replaced a shell hook that cost about 34 ms of forks per Bash call; the mod costs under a microsecond.
Status: this mod is the enforcement. It is installed and enabled as git-guard@craigs-claude-plugins (user
scope), so it loads in every session, CLI and desktop app. The marketplace craigs-claude-plugins is a directory
source pointing at ~/.claude, and sessions load the plugin from its source folder, my-plugins/git-guard, not from
the plugin cache. A new session reads it from there; a running session re-reads it with /reload-plugins, or after a
restart. No claude plugin update is needed on this machine. A mod loads only while Claude Code's hooks-modules
feature flag is on: in a process where it is off, and under --bare, safe mode or an untrusted workspace, the guard
is absent. After an edit, verify with the live probe that the new behaviour is active. Operation, verification and
rollback: my-plugins/MODS-ACTIVATION.md.
Matched through git global options (git -C dir ..., git -c k=v ..., --git-dir, --work-tree, --namespace,
--exec-path, --super-prefix=, --config-env=, -p, --paginate, -P, --no-pager, --no-optional-locks,
--no-replace-objects, --literal-pathspecs, --glob-pathspecs, --noglob-pathspecs, --icase-pathspecs,
--bare):
| Command | Allowed exceptions |
|---|---|
git checkout ... -- <path> (a bare -- token after checkout, no |&; between) | git checkout main, -b, --track |
git restore | the pure --staged form (no --worktree or -W anywhere) |
git reset with --hard as a whole token anywhere in the command | --soft, --mixed, --hard-not-really |
git clean with a force flag (-f, -fd, -fdx, --force) | any dry run (-n, --dry-run, even with --force) |
Every deny reason ends with: "Undo your own edits by editing instead of discarding them; ask Craig for an
exception if this destructive command is genuinely needed." A command that is empty or not a string passes
through. tool.call fires for subagents as well, so there is no subagent filter.
hooks/guard.ts is pure string logic (no claude-code imports). The shell script's [[:space:]] and \b
are BSD grep and libc semantics, not Unicode properties, so the character classes are reproduced exactly:
[[:space:]] is JS \s minus U+FEFF (24 code points).\b after a keyword uses hooks/wordchars.ts, a generated table of the characters BSD grep treats as word
characters on this machine (706 ranges). tests/gen-git-guard-wordchars.ts regenerates it
(bun my-plugins/git-guard/tests/gen-git-guard-wordchars.ts from ~/.claude); rerun it only after
a macOS upgrade. The reference script is recovered from git history with the two commands in the "Regenerating
the word-character table" section of my-plugins/MODS-ACTIVATION.md.git ... <subcommand> prefix is scanned token by token in linear time. The shell's regexes backtracked
quadratically (git -C repeated 5,700 times, about 40 KB, took 5 s), which would have crossed the hook timeout
and failed open. Every 1 MB adversarial input now finishes in well under 100 ms.--staged anywhere in the command allows git restore; -S is not recognised, so git restore -S f is denied.-name) allows git clean.git -C reset ... (the value swallows reset), slips through.
--git-dir= with an empty value breaks the option chain.git -c clean.requireForce=false clean -d is allowed.eval, scripts that run git inside).git reset HEAD~1; echo --hard and git clean -d; rm -f x are denied.set -o pipefail with echo | grep -q could flakily miss a match on commands over about 64 KiB
(SIGPIPE). The mod is deterministic.claude plugin test my-plugins/git-guard runs tests/guard.test.ts (the golden corpus in tests/corpus.ts through
$.tool.call, deny-reason text, and 1 MB performance cases). Parity with the shell script was proven by running
the original script and the mod over the same corpus plus random fuzz.
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
npx claudepluginhub hughescr/claude-code-config --plugin git-guard