Blocks destructive commands and confines file edits to chosen directories for agents working on production or autonomously.
- What it does
- The skill defines three protection modes for agent sessions: a cautious mode that intercepts destructive commands such as force pushes, hard resets, recursive deletes, database drops and cluster deletions, showing what the command does, asking for confirmation and suggesting safer alternatives; a freeze mode that locks writes and edits to a specified directory tree; and a guard mode combining both. It also provides an off command to disable protection. It is implemented through a PreToolUse hook that inspects Bash, Write, Edit and MultiEdit calls against the active rules, and blocked operations are logged to a file.
- When to use it
- Use it when an agent operates on production systems, runs in fully autonomous mode, should be restricted to editing only certain directories, or is performing sensitive operations such as migrations, deployments or data changes.
- Requirements
- Requires an agent environment that supports PreToolUse hooks for Bash, Write, Edit and MultiEdit tool calls. No scripts are shipped; the skill is instructions only. It writes a log file under the user's home directory.
安全防护 — 防止破坏性操作
使用场景
- 在生产系统上工作时
- 代理以全自动模式运行时
- 希望将编辑限制在特定目录时
- 敏感操作期间(迁移、部署、数据变更)
工作原理
三种保护模式:
模式 1:谨慎模式
在执行破坏性命令前进行拦截并发出警告:
检测到时:显示命令功能、请求确认、建议更安全的替代方案。
模式 2:冻结模式
将文件编辑锁定到特定目录树:
任何在 src/components/ 之外的写入/编辑操作都会被阻止并附带说明。适用于希望代理专注于某个区域而不触及无关代码的场景。
模式 3:守护模式(谨慎+冻结组合)
双重保护同时生效。为自主代理提供最高安全性。
代理可读取任何内容,但仅能写入 src/api/。破坏性命令在所有位置均被阻止。
解锁
实现方式
通过 PreToolUse 钩子拦截 Bash、Write、Edit 和 MultiEdit 工具调用。在执行前根据活动规则检查命令/路径。
集成方案
- 默认在
codex -a never 会话中启用
- 配合 ECC 2.0 的可观测性风险评分
- 所有被阻止的操作记录至
~/.claude/safety-guard.log