Como usar
- Copie o comando e verifique o pacote antes de instalar no seu ambiente de agente.
- Consulte no original as ferramentas, credenciais e ambientes necessários.
- Descreva os dados de entrada e a entrega esperada; confira a saída com as fontes.
npx skills add https://github.com/victorzhuk/skills --skill z-git-guardrailsAntes de começar
- A instalação não inclui assinatura de modelo, franquia API ou acesso aos seus arquivos.
- Estrelas e instalações indicam atividade, não um teste independente de qualidade ou segurança.
Renderizado do repositório de origem, preservando títulos, exemplos, código, tabelas, links e imagens.
Git guardrails
Install a best-effort PreToolUse filter for literal Git invocations in Bash tool calls. It requires Bash, Python 3, and Git. Keep block-dangerous-git.sh beside check-git.py.
The filter parses direct commands and command separators. It understands Git's -C, --git-dir, and --work-tree options. It does not interpret aliases, shell functions, wrapper programs, scripts, substitutions, or the full shell grammar. Use host permission controls for those forms. Passing this filter never grants authorization.
What gets blocked
- Literal
git push, including global options beforepush git reset --hardgit cleanwith force, including combined short flagsgit checkoutwith a path separator,., or force; worktreegit restore- Forced branch deletion unless ancestry can be checked for an isolated literal command
What stays allowed
Worktree-based flows delete branches and worktrees as routine cleanup, so the hook deliberately lets through:
- Literal
git worktreecommands pass this filter. Destructive cleanup still needs the host's checks and existing user authorization. - An isolated
git branch -Dpasses when every named branch tip is an ancestor ofHEADin the command's effective repository. This snapshot check does not protect against concurrent ref changes or preserve the branch name for the user. git branch -d— git itself refuses unmerged branches on lowercase-d.
Steps
- Resolve scope. Use the requested project or user installation. Ask only if that choice remains unspecified.
- Copy both scripts to the chosen
hooks/directory and make the.shentry point executable. Verify Python 3 and Git are available. - Wire the hook into the chosen settings file — merge into any existing
hooks.PreToolUsearray, don't overwrite:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/block-dangerous-git.sh"
}
]
}
]
}
}For the global install, point command at the script's path under the user-level Claude config directory instead.
- Preserve policy. Apply only requested customizations. Add cases to the guard tests for any changed command policy.
- Verify with piped test input:
echo '{"tool_input":{"command":"git push origin master"}}' | <path-to-script> # exit 2, BLOCKED on stderr
echo '{"tool_input":{"command":"git worktree remove ../wt"}}' | <path-to-script> # exit 0Do not
- Overwrite an existing
hooks.PreToolUsearray — merge into it. - Add
git worktreeto the blocklist — that breaks worktree-based apply flows. - Rely on the hook as a security boundary or as proof that a shell program is safe. It filters a literal subset of Bash tool input, not arbitrary programs or the user's terminal.
Verify
- Blocked command test exits
2withBLOCKED:on stderr; allowed commands exit0. git branch -Dof a merged branch passes; of an unmerged branch is blocked.- The hook script is executable and referenced from settings by the correct path.
- Run
python3 -m unittest discover -s scripts -p 'test_*.py'from this skill directory; prefix withgtimeout 60son hosts without GNU coreutils. The tests submit command text; they do not run destructive Git operations.

