cc-safe-setup 提供 910 个安全 hooks,一键安装后可阻止 Claude Code 的破坏性操作(如 rm -rf、force-push、git reset --hard),并在工具边界暴露静默失败,适用于生产环境和团队协作。
适合的任务:
生产环境代码开发(需要严格安全控制)
团队协作(防止 Agent 意外修改共享代码)
需要阻止危险命令的场景(如删除文件、强制推送、重置代码)
需要监控 Token 使用和预算管理的场景
需要凭证保护的场景(防止 .env 文件被修改)
不适合的任务:
快速原型开发(安全限制可能降低速度)
个人实验项目(不需要严格安全控制)
适用的模型版本:Claude Opus 4.7
适用的客户端、Agent 或 API:Claude Code CLI
推荐的推理档位和参数:high 或 xhigh(根据任务复杂度)
方式一:npx 一键安装(推荐)
npx github:yurukusa/cc-safe-setup方式二:作为 Claude Code 插件安装
/plugin marketplace add yurukusa/cc-safe-setup
/plugin install safety-essentials@cc-safe-setup注意:不要使用 npx cc-safe-setup(npm 版本),因为 npm 版本停留在 29.8.0,而当前仓库版本是 30.0.4,存在 3 个破坏性命令未被阻止。
| Plugin | What it blocks |
|---|---|
safety-essentials | rm -rf, force-push, git reset --hard, writes to .env, package publish |
git-protection | force-push, direct pushes to main/master, hard reset, interactive rebase, git clean -fd |
credential-guard | writes and edits to .env and service-account files, API keys in shell commands |
token-guard | reads over 100KB, a per-session read budget, subagent fan-out, a token budget that asks for /compact |
cc-safe-setup 安装以下类型的 hooks:
PreToolUse:在工具执行前阻止危险操作
PostToolUse:在工具执行后检查并暴露静默失败
SessionStart:会话开始时初始化
Stop:会话停止时清理
SubagentStop:子 Agent 停止时清理
命令是交互式的:
显示每个 hook 的功能
让你选择要安装哪些 hooks
安装到 ~/.claude/settings.json(全局)或项目本地的 .claude/settings.json
所有安装都需要你的确认
你可以编写自己的 hooks:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "jq -e 'select(.tool_input.command | test(\"rm -rf\")) | error(\"rm -rf blocked\")' > /dev/null 2>&1"
}
]
}
]
}
}cc-safe-setup 提供审计功能:
--doctor:检查已安装的 hooks 状态
--audit:生成安全审计报告
滚动部署到团队:
将 .claude/settings.json 提交到版本控制
团队成员克隆仓库后自动继承安全配置
使用 --doctor 验证所有成员的配置一致性
已安装的 hooks 不会自动更新:
你需要手动运行更新命令
定期检查仓库的 CHANGELOG.md
npm 版本落后:
npm 版本(29.8.0)阻止的命令少于当前仓库(30.0.4)
建议使用 npx github:yurukusa/cc-safe-setup 而不是 npx cc-safe-setup
安装 cc-safe-setup:
npx github:yurukusa/cc-safe-setup选择要安装的 hooks:
根据项目需求选择 safety-essentials、git-protection、credential-guard、token-guard
验证安装:
# 检查 hooks 是否生效
cat ~/.claude/settings.json测试安全保护:
尝试运行 rm -rf,确认被阻止
尝试强制推送,确认被阻止
尝试修改 .env,确认被阻止
定期更新:
检查仓库更新
运行更新命令
团队部署:
将 .claude/settings.json 提交到版本控制
团队成员克隆后自动继承配置
仓库包含 910 个 hooks
npm 版本 29.8.0 于 2026-04-20 发布
当前仓库版本 30.0.4
npm 版本让 3 个破坏性命令通过,而当前版本阻止这些命令
提供 4 个核心插件:safety-essentials、git-protection、credential-guard、token-guard
支持多种 hook 类型:PreToolUse、PostToolUse、SessionStart、Stop、SubagentStop
提供审计工具:--doctor、--audit
MIT 许可证
需要 Claude Code CLI 环境
hooks 不会自动更新,需要手动维护
npm 版本落后于仓库版本,建议使用 GitHub 版本
某些 hooks 可能影响开发速度(如阻止 rm -rf)
团队部署需要版本控制支持
README 强调:"One command to add safety hooks to Claude Code. It installs a set of PreToolUse, PostToolUse, SessionStart, Stop, and SubagentStop hooks that stop destructive or irreversible operations before they run, and that surface silent failures."
"Why not npx cc-safe-setup? The npm release is stuck at 29.8.0 (2026-04-20) while this repository is at 30.0.4, and the gap is not cosmetic — 29.8.0 lets three destructive commands through that the current code blocks."
Claude Opus 4.7