🛡️ OpenClaw Guardian
The Safety Brake for OpenClaw - Session-aware protection for risky operations
Overview
Claw-Gatekeeper is a comprehensive security control layer for OpenClaw that intercepts potentially dangerous operations and manages them according to their risk level:
| Risk Level | Score | Behavior | Session Approval |
|---|
| 🔴 CRITICAL | 80-100 | Always requires confirmation | ❌ Not available |
| 🟠 HIGH |
60-79 | Requires confirmation, can approve for session | ✅ Available |
| 🟡
MEDIUM | 30-59 | Suggests confirmation, can approve for session | ✅ Available |
| 🟢
LOW | 0-29 | Auto-allowed without confirmation | N/A |
Key Features
- - 🛑 Smart Interception - Automatically catches risky operations
- 📅 Session-Level Approval - Approve MEDIUM/HIGH once, auto-approve similar operations for the session
- 🔒 CRITICAL Protection - Must confirm each CRITICAL operation individually
- 📝 Audit Trail - All MEDIUM+ operations logged to INLINECODE0
- ⚙️ Persistent Operation - Designed to be loaded as a resident skill
Risk Level Behaviors
🔴 CRITICAL (80-100) - Always Confirm
Examples:
- -
rm -rf / or system directory deletion - Disk formatting (
mkfs, format) - System configuration changes
- Access to
/etc/shadow, root SSH keys
Behavior:
- - ❌ Must confirm EACH time individually
- ❌ No session-level approval available
- ❌ No auto-approval
- ✅ Complete audit logging
CODEBLOCK0
🟠 HIGH (60-79) - Confirm or Session Approve
Examples:
- - Deleting directories with many files
- Executing shell commands
- Installing skills from external sources
- Network requests to external domains
Behavior:
- - ✅ Requires confirmation (first time)
- ✅ Can approve for entire session
- ✅ Session expires after 30min inactivity
- ✅ Complete audit logging
CODEBLOCK1
🟡 MEDIUM (30-59) - Suggest Confirm or Session Approve
Examples:
- - Creating new files
- Batch file operations (5-20 files)
- Reading sensitive directories
- Modifying configuration files
Behavior:
- - ✅ Suggests confirmation
- ✅ Can approve for entire session
- ✅ Auto-allowed in loose mode
- ✅ Complete audit logging
🟢 LOW (0-29) - Auto-Allow
Examples:
- - Reading files
- Listing directories
- Whitelisted operations
- Safe read-only commands
Behavior:
- - ✅ Auto-allowed without confirmation
- ✅ No interruption to workflow
- ✅ Still logged if enabled
Installation
Prerequisites
Claw-Guardian is designed to be a persistent/resident skill in OpenClaw. It should be loaded at the start of every session.
Method 1: OpenClaw CLI (Recommended)
CODEBLOCK2
Method 2: Manual Installation
CODEBLOCK3
Method 3: Configuration File
Add to ~/.openclaw/config.json:
CODEBLOCK4
Quick Start
1. Initialize Configuration
CODEBLOCK5
2. Set Operation Mode
CODEBLOCK6
3. Verify Installation
CODEBLOCK7
4. Check Session Status
CODEBLOCK8
Session Management
How Session Approval Works
CODEBLOCK9
Session Expiration
- - Default timeout: 30 minutes of inactivity
- Activity: Any operation or confirmation resets the timer
- Persistence: Session state saved between OpenClaw interactions
Managing Session Approvals
CODEBLOCK10
Configuration
Operation Modes
Standard Mode (Recommended)
python3 scripts/policy_config.py mode standard
- - CRITICAL: Always confirm (no session)
- HIGH: Confirm or session approve
- MEDIUM: Suggest confirm or session approve
- LOW: Auto-allow
Strict Mode
python3 scripts/policy_config.py mode strict
- - All non-whitelisted operations require confirmation
- Session approval still available for MEDIUM/HIGH
- CRITICAL always per-confirmation
Loose Mode
python3 scripts/policy_config.py mode loose
- - Only CRITICAL requires confirmation
- MEDIUM/HIGH auto-allowed after first session approval
- LOW always auto-allowed
Emergency Mode
python3 scripts/policy_config.py mode emergency
- - Completely disables autonomous operations
- Everything requires confirmation
- Session approvals suspended
Managing Whitelists and Blacklists
CODEBLOCK15
Audit Logging
Operate_Audit.log
All MEDIUM and above operations are logged to ~/.claw-guardian/sessions/Operate_Audit.log:
CODEBLOCK16
Viewing Logs
CODEBLOCK17
Log Format
CODEBLOCK18
Usage Examples
Example 1: File Cleanup with Session Approval
CODEBLOCK19
Example 2: Skill Development Workflow
CODEBLOCK20
Example 3: CRITICAL Operation Always Confirms
CODEBLOCK21
Script Reference
Session Management
CODEBLOCK22
Session Manager Direct
CODEBLOCK23
Risk Assessment
CODEBLOCK24
Best Practices
For Personal Use
- 1. Use session approval for development work
- Approve temp file deletions for session
- Approve git operations for session
- Approve skill testing for session
- 2. Never session-approve CRITICAL risks
- Always review each CRITICAL operation
- CRITICAL = potential data loss or system damage
- 3. Review Operate_Audit.log weekly
CODEBLOCK25
For Team/Enterprise
- 1. Standard mode for most users
- Strict mode for production systems
- Regular audit log reviews
- Document session approval policies
Troubleshooting
Session Not Persisting
Problem: Session approvals lost between interactions
Solution: Ensure skill is loaded as persistent:
CODEBLOCK26
Too Many CRITICAL Prompts
Problem: Every CRITICAL operation requires confirmation
This is by design. CRITICAL risks must always be confirmed individually. Consider:
- - Whitelisting safe operations
- Reviewing why operations are marked CRITICAL
- Using less destructive alternatives
Session Timeout Too Short
Problem: Session expires during work
Solution: Adjust timeout (requires config edit):
CODEBLOCK27
Project Status
This is a temporary security measure.
Claw-Guardian addresses current security gaps in OpenClaw. Once OpenClaw implements comprehensive built-in safety controls, this project may be deprecated.
Claw-Guardian - Making OpenClaw Safer, One Session at a Time 🛡️
🛡️ OpenClaw 守护者
OpenClaw 的安全制动器 - 针对高风险操作的会话感知保护
概述
Claw-Gatekeeper 是 OpenClaw 的全面安全控制层,可拦截潜在危险操作并根据风险等级进行管理:
| 风险等级 | 分数 | 行为 | 会话审批 |
|---|
| 🔴 严重 | 80-100 | 始终需要确认 | ❌ 不可用 |
| 🟠 高 |
60-79 | 需要确认,可批准会话 | ✅ 可用 |
| 🟡
中 | 30-59 | 建议确认,可批准会话 | ✅ 可用 |
| 🟢
低 | 0-29 | 自动允许,无需确认 | 不适用 |
主要特性
- - 🛑 智能拦截 - 自动捕获风险操作
- 📅 会话级审批 - 对中/高风险操作一次性批准,会话内自动批准类似操作
- 🔒 严重保护 - 每次严重操作必须单独确认
- 📝 审计追踪 - 所有中风险及以上操作记录到 Operate_Audit.log
- ⚙️ 持久运行 - 设计为常驻技能加载
风险等级行为
🔴 严重 (80-100) - 始终确认
示例:
- - rm -rf / 或系统目录删除
- 磁盘格式化(mkfs、format)
- 系统配置更改
- 访问 /etc/shadow、root SSH 密钥
行为:
- - ❌ 每次必须单独确认
- ❌ 不可用会话级审批
- ❌ 无自动批准
- ✅ 完整审计日志记录
[OpenClaw] rm -rf ~/Projects/important
[Claw-Guardian] 🔴 严重风险
⚠️ 即将递归删除包含 1,247 个文件的目录
选项:
[y] ✅ 本次允许(下次仍会询问)
[Y] ✅✅ 始终允许(加入白名单)
[n] ❌ 本次拒绝
[N] ❌❌ 始终拒绝(加入黑名单)
注意:严重风险不可用会话审批
🟠 高 (60-79) - 确认或会话审批
示例:
- - 删除包含大量文件的目录
- 执行 shell 命令
- 从外部来源安装技能
- 对外部域名的网络请求
行为:
- - ✅ 需要确认(首次)
- ✅ 可批准整个会话
- ✅ 会话在 30 分钟无活动后过期
- ✅ 完整审计日志记录
[OpenClaw] 从 GitHub 安装技能
[Claw-Guardian] 🟠 高风险
⚠️ 正在从 GitHub 安装 data-processor
选项:
[y] ✅ 仅本次允许
[s] ✅📅 允许本次会话 ⭐ 推荐
[Y] ✅✅ 始终允许(白名单)
[n] ❌ 本次拒绝
[N] ❌❌ 始终拒绝(黑名单)
用户选择:[s]
✅ 操作已批准本次会话
📌 类似高风险操作将自动批准
⏱️ 会话在 30 分钟无活动后过期
🟡 中 (30-59) - 建议确认或会话审批
示例:
- - 创建新文件
- 批量文件操作(5-20 个文件)
- 读取敏感目录
- 修改配置文件
行为:
- - ✅ 建议确认
- ✅ 可批准整个会话
- ✅ 宽松模式下自动允许
- ✅ 完整审计日志记录
🟢 低 (0-29) - 自动允许
示例:
行为:
- - ✅ 自动允许,无需确认
- ✅ 不中断工作流程
- ✅ 启用后仍会记录日志
安装
前提条件
Claw-Guardian 设计为 OpenClaw 的持久/常驻技能。应在每次会话开始时加载。
方法 1:OpenClaw CLI(推荐)
bash
安装技能
openclaw skill install claw-gatekeeper
添加到持久技能(每次会话自动加载)
openclaw skill persist claw-guardian
方法 2:手动安装
bash
复制技能包
cp claw-guardian.skill ~/.openclaw/skills/
添加到自动加载
openclaw skill load claw-guardian --persist
方法 3:配置文件
添加到 ~/.openclaw/config.json:
json
{
persistent_skills: [
claw-guardian
]
}
快速入门
1. 初始化配置
bash
使用默认设置初始化
python3 ~/.claw-gatekeeper/scripts/policy_config.py show
2. 设置操作模式
bash
标准模式(推荐)
python3 scripts/policy_config.py mode standard
或严格模式以获得最大安全性
python3 scripts/policy_config.py mode strict
3. 验证安装
bash
测试风险评估
python3 scripts/risk_engine.py file delete ~/test-file.txt
4. 检查会话状态
bash
查看当前会话信息
python3 scripts/guardian_ui.py session
查看 Operate_Audit.log
python3 scripts/session_manager.py check --lines 50
会话管理
会话审批工作原理
首次操作(中/高风险):
[OpenClaw] 删除 ~/temp/old-files/
[Guardian] 🟡 中风险 - 需要确认
选项:[y] 一次,[s] 会话,[Y] 始终,[n] 拒绝
用户:[s] 允许本次会话
✅ 操作已批准
📌 会话审批已授予
类似操作(同一会话):
[OpenClaw] 删除 ~/temp/more-files/
[Guardian] 🟡 中风险 - 会话已批准
自动允许(与之前审批类似)
✅ 自动批准(无提示)
会话过期
- - 默认超时: 30 分钟无活动
- 活动: 任何操作或确认都会重置计时器
- 持久性: 会话状态在 OpenClaw 交互之间保存
管理会话审批
bash
查看当前会话
python3 scripts/guardian_ui.py session
查看活动审批
python3 scripts/session_manager.py list
撤销特定审批
python3 scripts/session_manager.py revoke --type file --risk HIGH
清除整个会话
python3 scripts/session_manager.py clear
配置
操作模式
标准模式(推荐)
bash
python3 scripts/policy_config.py mode standard
- - 严重:始终确认(无会话)
- 高:确认或会话审批
- 中:建议确认或会话审批
- 低:自动允许
严格模式
bash
python3 scripts/policy_config.py mode strict
- - 所有非白名单操作都需要确认
- 中/高风险仍可用会话审批
- 严重始终每次确认
宽松模式
bash
python3 scripts/policy_config.py mode loose
- - 仅严重需要确认
- 中/高风险在首次会话审批后自动允许
- 低风险始终自动允许
紧急模式
bash
python3 scripts/policy_config.py mode emergency
- - 完全禁用自主操作
- 所有操作都需要确认
- 暂停会话审批
管理白名单和黑名单
bash
添加可信路径
python3 scripts/policy_config.py add whitelist paths ~/Projects
添加可信命令
python3 scripts/policy_config.py add whitelist commands git status
添加可信技能
python3 scripts/policy_config.py add whitelist skills docx
阻止敏感路径
python3 scripts/policy_config.py add blacklist paths ~/.ssh
审计日志
Operate_Audit.log
所有中风险及以上操作记录到 ~/.claw-guardian/sessions/Operate_Audit.log:
[2026-03-12 14:30:25.123] [🟠 高] [技能] allow_session: 从 github 安装 data-processor@1.0.0
[2026-03-12 14:31:10.456] [中] [文件] allow_session: 删除 ~/temp/cache(会话已批准)
[2026-03-12 14:32:05.789