/skills:stop-destructive-gitfrom skills
Installs a PreToolUse hook that parses Bash commands with a real shell lexer and blocks destructive git actions like force-push, hard reset, and forced checkout.
Ships in skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Install a Claude Code PreToolUse hook that parses Bash commands as shell tokens and exits 2 before destructive git actions run.
Ask whether to install for this project or every project before writing files:
.claude/hooks/stop-destructive-git.py and .claude/settings.json~/.claude/hooks/stop-destructive-git.py and ~/.claude/settings.jsonWrite an executable Python 3 script (#!/usr/bin/env python3, then chmod +x) that reads JSON from stdin and extracts tool_input.command. Exit 0 when the field is missing or empty.
Parse the command string instead of matching substrings:
shlex in POSIX punctuation mode, keeping newlines as separators) so quoted strings like commit messages stay single tokens.&&, ||, |, &, command separators, and newlines) outside quotes.KEY=VAL assignments, match git, and skip global git options before the subcommand (-C <dir>, -c <k=v>, --git-dir, --work-tree, --namespace, -p, --no-pager, --bare), consuming separate or = option values.push (all forms), reset --hard, clean with -f or --force (including combined flags like -fdx), branch -D (or --delete with force), and forced broad discards (checkout -f, checkout ., checkout -- ., restore ., restore --worktree .).BLOCKED: <reason> to stderr and exit 2. Otherwise exit 0.Create or update the settings file for the chosen scope. Merge a Bash matcher entry into hooks.PreToolUse without removing other settings or existing hooks:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/stop-destructive-git.py"
}
]
}
]
}
}
For every-project scope, point command to ~/.claude/hooks/stop-destructive-git.py.
Pipe simulated hook JSON into the installed script without executing any git command (swap the path if installed for every project):
printf '%s\n' '{"tool_input":{"command":"git -C . push"}}' | .claude/hooks/stop-destructive-git.py
Check every case below and confirm the settings JSON parses cleanly with prior hooks intact:
Piped tool_input.command | Expected exit |
|---|---|
git -C . push, git push -f origin main, git status && git push | 2 (blocked) |
git reset --hard HEAD~1, git clean -fdx, git checkout -- ., git branch -D tmp | 2 (blocked) |
git commit -m "why git push failed", git status, git log | 0 (allowed) |
Report the exact script path, the exact settings file updated, whether the hook applies to this project or every project, and the piped test results. Note where the editable rule list lives in the script, and state that this hook only guards commands run through Claude Code's Bash tool, not other tools or manual terminal commands.
Based on mattpocock/skills (MIT), rewritten by Copybook.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
git-safety, pre-tool-hook, branch-protection, force-push-guard
npx claudepluginhub heyvhuang/copybook-skills --plugin skills24 skills in this plugin
/add-pre-commit-checksUse when asked to add pre-commit hooks, set up Husky or lint-staged, stop bad commits, or run Prettier and type checks on commit. Sets up a pre-commit hook that formats staged files, type-checks with the project config, and runs related tests, proven by blocked and fast commits. Not for picking a test set for a change (run-affected-tests)./build-throwaway-prototypeUse when asked to prototype, spike, try an idea out quickly, sanity-check a state model or logic, or mock up what a UI should look like. Builds a throwaway prototype that answers one named design question from one command or one HTML file while leaving production code untouched. Not for building a finished production page (design-web-page)./check-current-docsUse when asked to use the latest docs, check if an API is still current, check which version the project is on, follow modern HTML or CSS best practices, or avoid outdated patterns; also when adding or changing code that calls a library pinned in the project, such as validation with a schema library. Reads the project lockfile and manifest, checks the official docs or browser guidance for the exact pinned versions, implements the current pattern without deprecated calls, and cites each choice with its URL, version, and date read. Not for moving existing code off an old API (migrate-off-deprecated-api)./check-live-deployUse when asked if a merge is live, if the deploy worked, or to check production after shipping and merging. Verifies that the canonical public URL serves the merged commit past any cache and that the change itself works live, reporting live, not live or unknown with evidence. Not for checking code before a merge (verify-work-done)./check-skill-before-installUse when asked to find a skill for a task, if there is a skill that helps, how to do something with an agent, which plugin to use, or to install a skill. Finds two or three candidate skills, reads each one for scripts, network calls, file writes, licence, and name clashes, and recommends one pick with a proposed install command. Not for getting a second opinion on a plan or trade-off (get-second-opinion)./find-root-causeUse when something is broken: a bug, a failing test, a build error, "it doesn't work", or a fix that didn't hold. Reproduces the failure, traces it to the line where it starts, proves one cause with one change, fixes every copy, and stops with a report after two failed fixes. Not for checking finished work before saying done (verify-work-done).Other plugins' skills for the same job