/ 目录 / 演练场 / Claude Code Safety Net
● 社区 kenryu42 ⚡ 即开即用

Claude Code Safety Net

作者 kenryu42 · kenryu42/claude-code-safety-net

A hooks-driven safety net for Claude Code — interceptors catch rm -rf, git reset --hard, force pushes, and uncommitted destructive edits.

Installs as a Claude Code plugin with PreToolUse hooks. Each potentially destructive operation is intercepted and either confirmed or refused based on rules. Includes rules for git, file system, npm, and arbitrary bash.

为什么要用

核心特性

实时演示

实际使用效果

就绪

安装

选择你的客户端

~/Library/Application Support/Claude/claude_desktop_config.json  · Windows: %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "claude-code-safety-net": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/kenryu42/claude-code-safety-net",
        "~/.claude/skills/safety-net"
      ],
      "_inferred": true
    }
  }
}

打开 Claude Desktop → Settings → Developer → Edit Config。保存后重启应用。

~/.cursor/mcp.json · .cursor/mcp.json
{
  "mcpServers": {
    "claude-code-safety-net": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/kenryu42/claude-code-safety-net",
        "~/.claude/skills/safety-net"
      ],
      "_inferred": true
    }
  }
}

Cursor 使用与 Claude Desktop 相同的 mcpServers 格式。项目级配置优先于全局。

VS Code → Cline → MCP Servers → Edit
{
  "mcpServers": {
    "claude-code-safety-net": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/kenryu42/claude-code-safety-net",
        "~/.claude/skills/safety-net"
      ],
      "_inferred": true
    }
  }
}

点击 Cline 侧栏中的 MCP Servers 图标,然后选 "Edit Configuration"。

~/.codeium/windsurf/mcp_config.json
{
  "mcpServers": {
    "claude-code-safety-net": {
      "command": "git",
      "args": [
        "clone",
        "https://github.com/kenryu42/claude-code-safety-net",
        "~/.claude/skills/safety-net"
      ],
      "_inferred": true
    }
  }
}

格式与 Claude Desktop 相同。重启 Windsurf 生效。

~/.continue/config.json
{
  "mcpServers": [
    {
      "name": "claude-code-safety-net",
      "command": "git",
      "args": [
        "clone",
        "https://github.com/kenryu42/claude-code-safety-net",
        "~/.claude/skills/safety-net"
      ]
    }
  ]
}

Continue 使用服务器对象数组,而非映射。

~/.config/zed/settings.json
{
  "context_servers": {
    "claude-code-safety-net": {
      "command": {
        "path": "git",
        "args": [
          "clone",
          "https://github.com/kenryu42/claude-code-safety-net",
          "~/.claude/skills/safety-net"
        ]
      }
    }
  }
}

加入 context_servers。Zed 保存后热重载。

claude mcp add claude-code-safety-net -- git clone https://github.com/kenryu42/claude-code-safety-net ~/.claude/skills/safety-net

一行命令搞定。用 claude mcp list 验证,claude mcp remove 卸载。

使用场景

实战用法: Claude Code Safety Net

Install the safety net into Claude Code

👤 Claude Code users ⏱ ~15 min intermediate

何时使用: You've been bitten by an agent overwriting uncommitted changes.

步骤
  1. Clone
    git clone into ~/.claude/skills/safety-net✓ 已复制
    → Skill directory present
  2. Wire hooks
    Run the included setup; settings.json gets PreToolUse entries.✓ 已复制
    → Hooks active
  3. Test
    Ask Claude to git reset --hard; expect block.✓ 已复制
    → Block triggered

结果: Destructive ops require explicit override.

组合

与其他 MCP 搭配,撬动十倍杠杆

claude-code-safety-net + filesystem

Pairs naturally with any agent doing repo edits

Combine claude-code-safety-net with filesystem: Pairs naturally with any agent doing repo edits✓ 已复制

工具

此 MCP 暴露的能力

工具输入参数何时调用成本
hook-driven (see docs) No callable tools; activates via PreToolUse hooks 1 call

成本与限制

运行它的成本

API 配额
N/A
每次调用 Token 数
0
费用
Free
提示
Start in soft-warn mode; promote to hard-block after a week of clean runs

安全

权限、密钥、影响范围

最小权限: hooks-read hooks-write
凭据存储: None
数据出站: None

故障排查

常见错误与修复

Hooks not firing

Confirm settings.json was actually updated; restart Claude Code

False positives on benign git ops

Tune the per-project rules file

替代方案

Claude Code Safety Net 对比其他方案

替代方案何时用它替代权衡
pegasi-ai/reinsYou want broader agent guardrailsHeavier setup
Manual reviewSolo, low-stakes repoDoesn't scale

更多

资源

📖 阅读 GitHub 上的官方 README

🐙 查看未解决的 issue

🔍 浏览全部 400+ MCP 服务器和 Skills