OpenClaw integration
Learn how the DefenseClaw plugin works inside OpenClaw: components, transport coverage, plugin credential, verdict waits, correlation headers, approvals.
This page is the reference for the OpenClaw connector: how the plugin is built and what it sends. Setup, files and limits are on the connector page.
Components
| Component | Role |
|---|---|
Plugin (extensions/defenseclaw/, TypeScript) | Loads inside OpenClaw. Hooks OpenClaw's fetch interceptor and the before_tool_call lifecycle. On OpenClaw 2026.8.35 and later it also uses the native hooks before_agent_run, after_tool_call and llm_output (Hook modes). |
defenseclaw-gateway (Go) | Receives plugin requests, evaluates policy, returns verdicts and writes the audit row. |
defenseclaw CLI (Python) | Runs setup and exposes the TUI for audit, alerts, logs and inventory. |
OpenClaw is the only connector that ships a first-party plugin in this repository. The plugin owns the OpenClaw-side wiring; the gateway and CLI own everything else.
List view for small screens. Use the expand button to open the drawing.
- OpenClaw
- runsDefenseClaw plugin
- DefenseClaw pluginloads inside OpenClaw
- redirects LLM callsGuardrail proxy :4000
- asks before toolsInspect API :18970
- Inspect API :18970checks the tool call
- Guardrail proxy :4000checks request and response
- forwards if allowedModel provider
- Model provider
Text version of this diagram
- OpenClaw (agent)
- runs to DefenseClaw plugin
- DefenseClaw plugin: loads inside OpenClaw (connector)
- redirects LLM calls to Guardrail proxy :4000
- asks before tools to Inspect API :18970
- Inspect API :18970: checks the tool call (gateway). Checks each tool call, and each prompt when the prompt gate is on. In native hook mode it also scans tool results and finished replies, which it cannot block.
- Guardrail proxy :4000: checks request and response (gateway)
- forwards if allowed to Model provider
- Model provider (external service)
Transport coverage
The plugin patches globalThis.fetch, Node https.request, http.request and http.get, the global Undici dispatcher, and the Undici copy OpenClaw ships. Only recognized model traffic is redirected through the guardrail proxy. Other requests pass through unchecked.
| Transport | Redirected through the proxy when | Unclassified request |
|---|---|---|
globalThis.fetch | The destination is a known provider, or the method, path and readable body form a recognized LLM request shape. | Passes through and emits egress passthrough telemetry. |
https.request | The destination is a known provider or its path has a recognized LLM suffix. | Passes through and emits egress passthrough telemetry. |
http.request and http.get | Its non-safe destination has a recognized LLM path, including supported known or local-provider paths. | Passes through without guaranteed passthrough telemetry. |
| Undici global dispatcher | Its non-safe destination is a known provider or has a recognized LLM path. | Passes through without guaranteed passthrough telemetry. |
| Undici copy that OpenClaw ships | Same rule as the global dispatcher. OpenClaw sends model requests through an SSRF-guarded fetch that gives Undici a dispatcher of its own, which skips every layer above. | Passes through without guaranteed passthrough telemetry. |
- Raw sockets, custom transports and libraries that bypass every patched entry point are outside the boundary. An egress event proves the plugin observed a transport branch, not that the request was proxied and inspected.
- The plugin patches the main thread of the OpenClaw process. A model call made from a Node worker thread is not redirected and not inspected.
defenseclaw doctor checks interception in its OpenClaw interception row:
- It fails when the plugin's sentinel self-test, which never leaves the host, cannot prove a rewrite onto the guardrail proxy, even if
/healthreturns 200. OpenClaw>=2026.6.8needs the Undici dispatcher layers for this. - The gateway pairs each model call OpenClaw completes with a proxy hop of its own. Doctor fails the row when the latest call took no hop, and warns when an earlier one did not but the calls after it did. Counts restart when
defenseclaw-gatewayrestarts. - If turns succeed while doctor says traffic is not intercepted, restart OpenClaw so the plugin reloads, then rerun doctor.
Plugin credential
The plugin uses one credential: the connector-scoped token in ~/.defenseclaw/hooks/.hook-openclaw.token, which setup creates. In the separate-user layout it reads the copy at plugin_token_file. It does not read the gateway token from config.yaml, .env or OPENCLAW_GATEWAY_TOKEN.
The credential works on loopback only, for the routes in this table and for the listener proofs. Every other route needs the DefenseClaw gateway token.
| Route | Method | Used for |
|---|---|---|
/api/v1/inspect/* with X-DefenseClaw-Connector: openclaw | POST | Tool, prompt, request, response and tool-result checks |
/status | GET | Health |
/enforce/blocked, /enforce/allowed | GET | Read the block and allow lists |
/audit/event | POST | Write an audit row |
/policy/evaluate | POST | Ask for a policy decision |
/scan/result | POST | Record a scan result |
/v1/plugin/scan, /api/v1/scan/code | POST | The /scan command |
/api/v1/openclaw/runtime | GET | Mode, human approval, approval timeout, verdict wait, prompt gate |
A leaked plugin credential can read the lists, write audit and scan rows and ask for scans and decisions. It cannot block, allow or unblock anything, switch connectors, change config or stop the gateway.
So the /block and /allow commands in OpenClaw chat do not change a list. They print the command to run in a terminal, because anyone who can message the agent can send a chat command, while a terminal command needs the account that owns DefenseClaw:
defenseclaw skill block NAME
defenseclaw mcp allow NAME
defenseclaw plugin unblock NAMEProtocol compatibility
The gateway client speaks the OpenClaw WebSocket handshake across protocol v3 to v4. On connect it sends minProtocol: 3 and maxProtocol: 4. OpenClaw returns the negotiated hello-ok protocol plus its supported methods and events. The v3 challenge-response device flow is kept for older endpoints.
End-to-end flow
A model call
The plugin's fetch interceptor sends each recognized LLM request to the guardrail proxy (port 4000 by default) and keeps the original address in the X-DC-Target-URL header. The proxy checks the request before it forwards it and the response before it returns it.
A tool call
about to run a tool
POST /api/v1/inspect/tool
allow · alert · confirm · block
run, block, or requireApproval
asks for approval (confirm only)
approve or deny
reports the answer (logged)
Text version of this diagram
Participants
- User (operator)
- OpenClaw (agent)
- Plugin (connector)
- Gateway (gateway)
Messages, in order
- OpenClaw to Plugin: about to run a tool
- Plugin to Gateway: POST /api/v1/inspect/tool
- Gateway to Plugin (reply): allow · alert · confirm · block
- Plugin to OpenClaw (reply): run, block, or requireApproval
- OpenClaw to User: asks for approval (confirm only)
- User to OpenClaw (reply): approve or deny
- OpenClaw to Plugin: reports the answer (logged)
Verdict wait
The plugin waits for a verdict as long as the gateway says:
| Case | Wait |
|---|---|
| No human approval | The hook judge budget (guardrail.judge.hook_timeout) plus 2 seconds |
| Human approval on | The approval timeout plus 5 seconds |
| Budget OpenClaw gives the hook | The approval timeout plus 15 seconds, at least 30 and at most 600 seconds. The plugin stops waiting 3 seconds before it ends. |
Large message calls
The plugin sends a message tool call to the gateway whole, up to the gateway's 1 MiB request limit. Over the limit, it never cuts the message text:
- Each attachment (a long base64
bufferormediavalue, or a base64 data URL whose;base64,ends within its first 256 bytes) is replaced by a descriptor: its size, media type, SHA-256 hash and the text the gateway would read in its bytes. A key in a file sent as an attachment still reaches the rules. - Attachments past 32 MiB of base64 in one call are not read. Each gets a descriptor that says so.
- A call with descriptors is judged at least at the unknown tier of its policy: an alert in the default and permissive policies, a block in the strict policy. A finding in the text still blocks.
- A call whose text alone is over the limit is blocked in every policy, before any check is sent. So is a call with an unread attachment and a
contentorbodyfield.
The gateway reads an attachment only for the text of its decoded bytes. Text in a raw base64-alphabet buffer value, in the parameters of a plain ASCII data URL header, or in an attachment nested more than 8 levels deep is not read. The nested case is judged at the unknown tier.
Correlation headers
There is no X-DefenseClaw-Correlation-Id header. Depending on available context, plugin requests use these headers; optional ones are omitted when OpenClaw supplies no context:
X-DefenseClaw-Run-Id,X-DefenseClaw-Session-Id,X-DefenseClaw-Trace-IdX-DefenseClaw-Agent-Id,X-DefenseClaw-Agent-Name,X-DefenseClaw-Policy-IdX-DefenseClaw-Agent-Instance-Id,X-DefenseClaw-Sidecar-Instance-IdX-DefenseClaw-Client, which identifies the HTTP client
The fetch interceptor mints a fresh trace ID for each intercepted LLM call and reuses the most recent tool context for run and session attribution. The sidecar can echo sticky agent and sidecar instance IDs so later requests converge on the same identities.
Approvals
For a confirm verdict in action mode the plugin returns OpenClaw's requireApproval object with timeoutBehavior: "deny". OpenClaw applies the decision; the plugin's onResolution callback only logs it and sends no separate "resolve approval" request to the gateway. Other native-ask connectors use their own host UI. See Human approval for the per-connector matrix.
OpenClaw advanced setup
Set up OpenClaw beyond the default: shared machines, admin-installed plugin, separate OS accounts, gateway token, device pairing and Bedrock VPC endpoints.
ZeptoClaw
Guard ZeptoClaw by pointing its providers at the DefenseClaw guardrail proxy, which checks every request and response.