Token导航 LogoToken导航TokenDH.com
开发执行命令github未标认证来源可访问许可证需确认审计异常

git-safety-guardgit 安全卫士

Agent Skill

git-safety-guard 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

552

周安装

23

GitHub Stars

3

下载量

184
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-safety-guard(git 安全卫士)
来源仓库:https://github.com/terraphim/terraphim-skills
仓库路径:skills/git-safety-guard
安装命令:
npx skills add https://github.com/terraphim/terraphim-skills --skill git-safety-guard
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/terraphim/terraphim-skills --skill git-safety-guard

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在需要围绕仓库状态、代码变更或协作事项进行整理时使用。
  • 可结合来源仓库和原始 README 核验具体用法和功能细节。
  • 安装通过 npx skills add 命令从指定 GitHub 仓库获取,适用于 Codex、Claude、Cursor、Gemini CLI。
  • 建议确认权限范围、维护状态及是否触发联网、命令执行或文件读写。

SKILL.md

Git Safety Guard

Use this skill when setting up or configuring protection against destructive git/filesystem commands in Claude Code.

Overview

Git Safety Guard intercepts Bash commands before execution and blocks dangerous operations that could permanently destroy uncommitted work or important files. The guard uses regex pattern matching with an allowlist to distinguish between safe and dangerous variants of commands.

Key Features:

  • terraphim-agent guard - CLI command for pattern checking
  • PreToolUse hook - Intercept Claude Code tool calls before execution
  • Allowlist support - Safe patterns override dangerous patterns
  • Fail-open semantics - If guard fails, commands pass through

Architecture

Claude Code PreToolUse
      |
      v
git_safety_guard.sh (shell wrapper)
      |
      v
terraphim-agent guard --json "$COMMAND"
      |
      v
Pattern Matching (Regex)
      |
      +---> SAFE_PATTERNS (allowlist) -> Allow
      |
      +---> DESTRUCTIVE_PATTERNS -> Block with reason
      |
      +---> No match -> Allow

Commands Blocked

Command PatternReason
git checkout -- <files>Discards uncommitted changes permanently
git restore <files>Discards uncommitted changes (except --staged)
git reset --hardDestroys all uncommitted changes
git reset --mergeCan lose uncommitted changes
git clean -fRemoves untracked files permanently
git push --forceDestroys remote history
git push -fSame as --force
git branch -DForce-deletes branch without merge check
rm -rf (non-temp paths)Recursive file deletion
git stash dropPermanently deletes stashed changes
git stash clearDeletes ALL stashed changes
git commit --no-verifyBypasses pre-commit and commit-msg hooks
git commit -nSame as --no-verify
git push --no-verifyBypasses pre-push hooks

Commands Explicitly Allowed

Command PatternWhy Safe
git checkout -b <branch>Creates new branch, doesn't modify files
git checkout --orphanCreates orphan branch
git restore --stagedOnly unstages files, doesn't discard changes
git clean -n / --dry-runPreview only, no actual deletion
git push --force-with-leaseSafer force push with remote check
rm -rf /tmp/...Temp directories are designed for ephemeral data
rm -rf /var/tmp/...System temp directory
rm -rf $TMPDIR/...User's temp directory

For Humans

Quick Start

# Install terraphim-agent from GitHub releases (latest version)
# macOS ARM64 (Apple Silicon)
gh release download --repo terraphim/terraphim-ai \
  --pattern "terraphim-agent-aarch64-apple-darwin" --dir /tmp
chmod +x /tmp/terraphim-agent-aarch64-apple-darwin
mv /tmp/terraphim-agent-aarch64-apple-darwin ~/.cargo/bin/terraphim-agent

# macOS x86_64 (Intel)
# gh release download --repo terraphim/terraphim-ai \
#   --pattern "terraphim-agent-x86_64-apple-darwin" --dir /tmp

# Linux x86_64
# gh release download --repo terraphim/terraphim-ai \
#   --pattern "terraphim-agent-x86_64-unknown-linux-gnu" --dir /tmp

# Note: crates.io version (cargo install terraphim_agent) is outdated (v1.0.0)
# and missing the guard command. Use GitHub releases for latest features.

# Test guard command
echo "git checkout -- file.txt" | terraphim-agent guard --json
# Output: {"decision":"block","reason":"git checkout -- discards...","command":"..."}

echo "git checkout -b new-branch" | terraphim-agent guard --json
# Output: {"decision":"allow","command":"git checkout -b new-branch"}

Installation

Project-local installation:

# Copy hook script
cp .claude/hooks/git_safety_guard.sh /your/project/.claude/hooks/

# Add to .claude/settings.local.json
{
  "hooks": {
    "PreToolUse": [{
      "matcher": "Bash",
      "hooks": [{
        "type": "command",
        "command": ".claude/hooks/git_safety_guard.sh"
      }]
    }]
  }
}

Global installation (~/.claude/):

# Run install script with --global flag
./scripts/install-terraphim-hooks.sh --global

CLI Usage

# Check a command (JSON output)
echo "git reset --hard" | terraphim-agent guard --json

# Check a command (human output - exits with code 1 if blocked)
echo "rm -rf /home/user" | terraphim-agent guard

# Fail-open mode (always exit 0)
echo "git checkout -- ." | terraphim-agent guard --fail-open

For AI Agents

Detecting Guard Availability

# Check if terraphim-agent is available
if command -v terraphim-agent >/dev/null 2>&1; then
    echo "Guard available"
elif [ -x "./target/release/terraphim-agent" ]; then
    AGENT="./target/release/terraphim-agent"
fi

Using Guard in Hooks

PreToolUse Hook Pattern:

#!/bin/bash
# Read JSON input
INPUT=$(cat)
TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name')
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command')

# Only process Bash commands
[ "$TOOL_NAME" != "Bash" ] && exit 0

# Check command
RESULT=$(terraphim-agent guard --json <<< "$COMMAND")

# If blocked, output deny decision
if echo "$RESULT" | jq -e '.decision == "block"' >/dev/null; then
    REASON=$(echo "$RESULT" | jq -r '.reason')
    cat <<EOF
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "BLOCKED: $REASON"
  }
}
EOF
fi

exit 0

Guard Response Format

Blocked command:

{
  "decision": "block",
  "reason": "git checkout -- discards uncommitted changes permanently. Use 'git stash' first.",
  "command": "git checkout -- file.txt",
  "pattern": "git\\s+checkout\\s+--\\s+"
}

Allowed command:

{
  "decision": "allow",
  "command": "git checkout -b new-branch"
}

Error Handling

The guard uses fail-open semantics:

  • If terraphim-agent is not found: pass through unchanged
  • If pattern matching fails: allow command
  • Errors logged to stderr only in verbose mode

Enable verbose mode:

export TERRAPHIM_VERBOSE=1

What Happens When Blocked

When Claude tries to run a blocked command, it receives feedback like:

BLOCKED by git_safety_guard

Reason: git checkout -- discards uncommitted changes permanently. Use 'git stash' first.

Command: git checkout -- file.txt

If this operation is truly needed, ask the user for explicit permission and have them run the command manually.

The command never executes. Claude sees this feedback and should ask the user for help.

Testing

# Manual test - should be blocked
echo "git checkout -- test.txt" | terraphim-agent guard --json

# Manual test - should be allowed
echo "git checkout -b feature" | terraphim-agent guard --json

# Run unit tests
cargo test -p terraphim_agent guard_patterns

# Test hook script
echo '{"tool_name":"Bash","tool_input":{"command":"git reset --hard"}}' | \
  .claude/hooks/git_safety_guard.sh

Troubleshooting

IssueSolution
Hook not triggeringCheck .claude/settings.local.json configuration
Command not blockedVerify pattern matches with terraphim-agent guard --json
Agent not foundBuild with cargo build -p terraphim_agent --release
Permission deniedRun chmod +x.claude/hooks/git_safety_guard.sh
jq not foundInstall jq: brew install jq or apt install jq

The Incident That Prompted This

On December 17, 2025, an AI agent ran git checkout -- on multiple files containing hours of uncommitted work from another agent. This destroyed the work instantly and silently. The files were recovered from a dangling Git object via git fsck --lost-found, but it was a close call.

Instructions alone don't prevent accidents. Mechanical enforcement does.

Related Skills

  • terraphim-hooks - Knowledge graph-based text replacement
  • implementation - For building custom guards
  • testing - For validating guard behavior
  • devops - For CI/CD integration with hooks

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

35.09%
按下载量换算65

Claude

29.14%
按下载量换算54

Cursor

16.86%
按下载量换算31

Gemini CLI

9.49%
按下载量换算17

安全审计

Gen Agent Trust Hub

未通过

Socket

通过

Snyk

通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/terraphim/terraphim-skills --skill git-safety-guard 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills