safety-guard
它能做什么
这个智能体就像你操作过程中的保镖。它能阻止危险命令被意外执行,还能把修改范围限制在项目的某个特定区域。
适用场景
- ✓在处理重要的(生产环境)系统时。
- ✓想让 AI 只在受限区域内独立工作时。
- ✓进行重要更新或数据变更期间。
技能链接
https://github.com/affaan-m/ECC/blob/main/skills/safety-guard/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“保护我的项目,阻止危险命令,并把修改限制在 'src/components/' 文件夹内。”
每周 5 个新技能,1 分钟读完。
工作原理
它的原理是检查 AI 即将执行的命令。如果某条命令被认为有危险(比如删除所有内容),或者 AI 试图修改允许范围之外的内容,它就会停下来,请你确认。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Safety Guard — Prevent Destructive Operations
When to Use
- When working on production systems
- When agents are running autonomously (full-auto mode)
- When you want to restrict edits to a specific directory
- During sensitive operations (migrations, deploys, data changes)
How It Works
Three modes of protection:
Mode 1: Careful Mode
Intercepts destructive commands before execution and warns:
Watched patterns:
- rm -rf (especially /, ~, or project root)
- git push --force
- git reset --hard
- git checkout . (discard all changes)
- DROP TABLE / DROP DATABASE
- docker system prune
- kubectl delete
- chmod 777
- sudo rm
- npm publish (accidental publishes)
- Any command with --no-verify
When detected: shows what the command does, asks for confirmation, suggests safer alternative.
Mode 2: Freeze Mode
Locks file edits to a specific directory tree:
/safety-guard freeze src/components/
Any Write/Edit outside src/components/ is blocked with an explanation. Useful when you want an agent to focus on one area without touching unrelated code.
Mode 3: Guard Mode (Careful + Freeze combined)
Both protections active. Maximum safety for autonomous agents.
/safety-guard guard --dir src/api/ --allow-read-all
Agents can read anything but only write to src/api/. Destructive commands are blocked everywhere.
Unlock
/safety-guard off
Implementation
Uses PreToolUse hooks to intercept Bash, Write, Edit, and MultiEdit tool calls. Checks the command/path against the active rules before allowing execution.
Integration
- Enable by default for
codex -a neversessions - Pair with observability risk scoring in ECC 2.0
- Logs all blocked actions to
~/.claude/safety-guard.log
常见问题
它会拦截哪些危险命令?
它会拦截诸如“删除所有内容”(rm -rf)、版本控制系统中的强制推送(git push --force),以及删除数据库表(DROP TABLE)之类的命令。
我怎样让它停止保护?
输入 '/safety-guard off' 即可关闭保护。
能不能让 AI 可以读取所有内容,但只能在一个地方写入?
可以,“守护模式”(Guard Mode)就支持这种设置。你可以指定一个 AI 可以写入的文件夹,它就无法修改项目的其他部分。
详情
作者的原始描述
Guard against destructive operations with three modes: Careful intercepts dangerous commands (rm -rf, git push --force, DROP TABLE) for confirmation, Freeze locks writes to one directory, and Guard combines both via PreToolUse hooks. Use when working on production systems, running agents autonomously, restricting edits to a directory, or during migrations, deploys, and data changes.
repo: affaan-m/ECC
热度
- GitHub 星标
- 280k
- 排名
- #397
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
accessibility
280k帮你的智能体创建人人都能使用的界面。确保网站和应用对残障人士友好,比如失明或行动不便的用户也能顺畅使用。
agent-architecture-audit
280k让你的智能体检查一切是否正常运行。它能找出并修复 AI 系统中的问题,确保系统按预期工作。
agent-eval
280k帮你的智能体比较不同的 AI 编程工具。它能衡量哪个工具在特定任务上更快、更便宜、更可靠。
agent-harness-construction
280k让你的智能体更好地理解如何完成任务。它会优化智能体使用的工具和指令,提高成功的几率。