git-guardrails
БесплатноЗапускает вложенные скриптыНе проверенInstall a hook that blocks destructive git commands before an AI agent runs them. Use when an agent force-pushed or ran reset --hard, when adding git safety…
от borghei★ 1 250 звёзд на GitHubОб этом скилле
Git Guardrails
An agent with shell access can run git reset --hard, git clean -fdx or
git push --force as casually as ls, usually while trying to make a failing
command pass. This skill installs a PreToolUse hook that reads every Bash
call before it runs, parses the git invocations inside it (chains, subshells,
bash -c, xargs, git -C), and blocks the destructive ones with exit code 2
and a reason the agent can act on. It ships the hook, an installer that merges
into .claude/settings.json without overwriting anything, plain git pre-push
and pre-rebase hooks for non-agent callers, and a corpus tester that proves
which commands are allowed and which are blocked.
When to use this skill
- After an incident: an agent discarded uncommitted work, deleted a branch, or force-pushed over a teammate's commits
- Before giving an agent autonomy: auto-accept mode, background agents, long unattended runs, or several agents in parallel worktrees
- Protecting shared branches: no direct pushes or rebases on
main,release/*,production - Auditing an existing guardrail: run its hook against the corpus to see what it actually catches
- Rolling guardrails out to a team: one committed project-scope hook plus a CI-runnable test
Not for server-side branch protection (configure that in your Git host) or for general command sandboxing; this guards git specifically.
Clarify First
The install scope and the protected-branch list decide what gets blocked, so settle them before installing. When one is missing or vague and would change the result, ask about it; when it wouldn't, use the default and say so.
- Scope: project scope (
<repo>/.claude/settings.json, committed, applies to every contributor's agent) or user scope (~/.claude/settings.json, every repo on this machine). The default is project scope, because team rules belong in version control. - Protected branches: the default list is
main, master, develop, trunk, production, prod, release/*. Repos withstable,stagingordeploy/*need a policy file, or pushes to those branches pass. - Force-with-lease on feature branches: allowed by default so an agent can update its own rebased PR. Teams that forbid any history rewrite after push should turn it off.
- Non-agent callers: if release scripts, IDEs or humans also need the push
rules, add the plain git hooks (
--git-hooks).
Ask about the two or three inputs that matter most for this request, not the whole list. If the user wants a result straight away, install at project scope with defaults and state your assumptions at the top.
Quick Start
# 1. See exactly what would change (writes nothing)
python3 engineering/git-guardrails/scripts/install_guardrails.py --project . --dry-run
# 2. Install hook + policy file + plain git hooks
python3 engineering/git-guardrails/scripts/install_guardrails.py --project . --policy --git-hooks
# 3. Prove it: run the corpus through the installed hook
python3 engineering/git-guardrails/scripts/guardrail_test.py --hook .claude/hooks/git_guardrails_hook.py
Restart the Claude Code session afterwards; settings are read at session start.
Tools Overview
| Tool | Purpose | Exit codes |
|---|---|---|
scripts/install_guardrails.py |
Copy the hook into .claude/hooks/, merge one PreToolUse entry into settings.json, optionally add policy and git hooks. --dry-run prints a unified diff |
0 installed or already installed, 1 a conflict was left untouched, 2 usage error or invalid settings (nothing written) |
scripts/guardrail_test.py |
Pipe each corpus command to a hook as a real PreToolUse payload; report allow/block and rule id per case. --command tests one command |
0 all cases matched, 1 any mismatch or reasonless block, 2 usage error |
assets/git_guardrails_hook.py |
The hook itself. Stdin JSON in; exit 0 allow or exit 2 + stderr reason. --check "<cmd>" for manual use |
0 allow, 2 block |
assets/pre-push, assets/pre-rebase |
Plain git hooks: force/non-fast-forward pushes, protected deletes, rebases of protected branches | 0 continue, 1 abort |
All tools take --format text|json (except the hooks, whose output format is
fixed by their callers).
Workflows
Workflow 1: Install at project scope [RECOMMENDED]
- Confirm the protected-branch list with the user. If it differs from the
defaults, the installer's
--policycopiesassets/sample_guardrail_policy.jsonto.claude/git-guardrails.json; edit that file. - Dry-run the installer and read the diff. Verify that the only change to
settings.jsonis one appendedPreToolUseentry. - Install for real. A pre-existing
settings.jsonis backed up tosettings.json.bak. - Run the tester against the installed copy. It must pass every case before you call the install done.
- Commit
.claude/settings.json, `.claude/hooks/git_guardrails
Установить git-guardrails в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл git-guardrails?
Install a hook that blocks destructive git commands before an AI agent runs them. Use when an agent force-pushed or ran reset --hard, when adding git safety hooks, or when protecting main from agent pushes.
Как установить скилл git-guardrails?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл git-guardrails запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic