Claw Guard is an OpenClaw security plugin that intercepts risky agent activity, records audits, and can optionally ask Claw_Guard_Server for a remote policy decision.
For the planned modularization path that supports more commands, more hook listeners, and more local scanners, see docs/modular-refactor.md.
- OpenClaw loads the plugin entry from
dist/index.js. - The plugin resolves config from
openclaw.plugin.jsonand runtime config. - The plugin initializes through
src/app/bootstrap.ts:- shared path and config-store services under
src/app/services/ - local guard engine
- audit writer and audit query service
- OpenClaw config/log access
- model adapter
- intel HTTP client
- exposure scanner
- config security scanner
- pause runtime and dashboard service
- auto-upgrade controller
- shared path and config-store services under
- The thin entry
src/index.tsdelegates to bootstrap, which registers hooks, commands, and dashboard routes. - Hook events are evaluated locally and may also be sent to the remote policy service.
- Decisions are written to structured audit logs and exposed in the dashboard.
Active hooks:
before_prompt_build: injects a skill-install security review instruction and the per-session local report pathbefore_tool_call: inspects command, file, URL, and generic tool-call eventsafter_tool_call: hashes installed skill artifacts when the download path is only known after completionmessage_received: inspects inbound user text, especially install operations
Pause behavior:
- When paused, all tool calls are blocked.
- When paused, normal incoming messages are blocked.
- Only the remaining chat control commands such as
/sec_openclaw_upgrade,/sec_help, and/sec_languageare allowed through. - Pause and resume operator actions stay available through the dashboard routes.
Local plugin modes:
ignore: observe only; policy results are recorded but not warned or blockedstandard: apply raw policy decisions as-isenforce: upgrade non-allow policy decisions into blocks
Remote transport decisions:
blockwarnallow
Local guard decisions:
blockwarnallow
Typical behavior:
- Local rules evaluate commands, paths, and URLs.
- The local guard now uses a two-tier command taxonomy:
- red-line operations default to
block, including destructive disk/system actions, remote script execution, code-injection chains, credential exfiltration, reverse shells, persistence mutation, auth tampering, and core permission tampering - yellow-line operations default to
warn, includingsudo, package installs that change the environment,docker run, firewall rule changes, known service start/stop/restart, localhost access, and broad sensitive-path access
- red-line operations default to
- Unknown or partially-modeled tools fall back to generic
tool_callevaluation instead of bypassing the guard. - Install operations can be intercepted from message text.
- Remote policy can upgrade or confirm the decision.
- The plugin keeps server compatibility by translating internal modes to the current server wire contract when it uploads
SecurityPolicyRequest. - Skill archives and installed skill folders can be matched by hash against server-side intel.
- Before skill installs, the plugin injects a system instruction that requires the agent to write a local JSON safety report.
- The core
Claw Guard skill-install policylines stay insrc/hooks/skill-report.ts, and extra generic operation-safety review text is loaded fromsrc/system-prompts/operation-safety/internal-safety-review.md. - The injected instruction now requires the agent to compute the skill hash first and write one JSON record per skill under
skill-reports/. - When Claw Guard observes a write into
skill-reports/*.json, it reads that record and uploads the hash verdict immediately. - If remote evaluation fails, fallback behavior depends on
intel.failClosed. - Guard detectors and remote policy still exchange stable reason codes such as
denylist:urlanddangerous:destructive_command, but all user-visible warning and block text is localized insrc/i18n/before delivery.
src/index.ts: thin plugin entry that delegates runtime wiringsrc/app/bootstrap.ts: composition root; creates runtime services and registers routes, commands, hooks, scanners, and controllerssrc/app/services/: bootstrap-owned runtime services for plugin state paths, config writes, audit queries, pause orchestration, dashboard status/actions, and hook signal bufferingsrc/features/registry.ts: feature registry that assembles command and dashboard contributionssrc/features/types.ts: shared feature contract and contribution registrationsrc/features/commands/index.ts: command registry that assembles per-command modules undersrc/features/commands/src/features/dashboard/index.ts: dashboard route registry that assembles per-route modules undersrc/features/dashboard/src/features/hooks/index.ts: hook registry that wires per-hook registration modules undersrc/features/hooks/src/hooks/before-prompt-build.ts: prompt injection for mandatory skill-install review reportingsrc/hooks/before-tool-call.ts:before_tool_callrisk evaluation and remote decision flowsrc/hooks/after-tool-call.ts: post-install skill hash lookup flow for download-style installssrc/hooks/skill-report.ts: local skill review report contract and upload payload buildersrc/system-prompts/operation-safety/internal-safety-review.md: shared internal safety-review prompt text appended to the install-review system contextsrc/hooks/message-received.ts:message_receivedpause gating and observation flowsrc/hooks/: shared hook helpers, tool metadata mapping, warning replies, and decision logssrc/guard/detectors.ts: detector registry that maps incoming events to risk subjectssrc/guard/policies.ts: policy registry that evaluates detected subjectssrc/guard/: local rule engine and per-kind evaluatorssrc/intel/: remote HTTP client and shared policy typessrc/dashboard/: gateway dashboard page and JSON endpointssrc/i18n/: localized guard notices and dashboard stringssrc/pause/: emergency pause, resume, snapshot, and child-process terminationsrc/commands/: upgrade, uninstall, auto-upgrade, and help commandssrc/config-security/: OpenClaw config security scansrc/exposure/: public exposure scansrc/audit/: JSONL audit outputsrc/runtime/: OpenClaw file and model adapters
- Audit log: JSONL file under the plugin state directory unless overridden
- Pause snapshot:
pause-snapshot.json - Auto-upgrade state:
auto-upgrade.json - Mutable plugin settings override:
mutable-config.json - Notification locale override:
notification-locale.json - Skill install review reports:
skill-reports/<skill-hash-hex>.json - Dashboard recent hook events: in-memory ring buffer
Routes:
GET /clawguardGET /clawguard/assets/:assetGET /clawguard/api/statusPOST /clawguard/api/action/:action
Implementation notes:
src/dashboard/http.tsnow serves a minimal HTML shell plus bootstrap JSON.- The interactive dashboard UI is a Preact app under
src/dashboard-app/. src/app/services/dashboard-service.tsowns dashboard status assembly and action-side state, while the feature routes stay declarative.npm run buildfirst bundles the dashboard intodashboard-assets/, then copies those assets intodist/dashboard-assets/so the compiled plugin remains loadable from built output.
Supported dashboard actions:
pauseresumesecurity-scansettings