ConnectorsOpenClaw

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

ComponentRole
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.

runs
redirects LLM calls
asks before tools
forwards if allowed
OpenClaw
DefenseClaw pluginloads inside OpenClaw
Guardrail proxy :4000checks request and response
Inspect API :18970checks the tool call
Model provider

List view for small screens. Use the expand button to open the drawing.

  1. OpenClaw
    • runsDefenseClaw plugin
  2. DefenseClaw pluginloads inside OpenClaw
    • redirects LLM callsGuardrail proxy :4000
    • asks before toolsInspect API :18970
  3. Inspect API :18970checks the tool call
  4. Guardrail proxy :4000checks request and response
    • forwards if allowedModel provider
  5. Model provider
AgentConnectorGatewayExternal service
The plugin's two checkpoints on Linux and macOS. Both listeners belong to defenseclaw-gateway. The ports shown are the defaults. Native Windows has no guardrail proxy: the plugin's hooks use the inspect API alone.
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.

TransportRedirected through the proxy whenUnclassified request
globalThis.fetchThe 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.requestThe destination is a known provider or its path has a recognized LLM suffix.Passes through and emits egress passthrough telemetry.
http.request and http.getIts non-safe destination has a recognized LLM path, including supported known or local-provider paths.Passes through without guaranteed passthrough telemetry.
Undici global dispatcherIts non-safe destination is a known provider or has a recognized LLM path.Passes through without guaranteed passthrough telemetry.
Undici copy that OpenClaw shipsSame 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 /health returns 200. OpenClaw >=2026.6.8 needs 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-gateway restarts.
  • 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.

RouteMethodUsed for
/api/v1/inspect/* with X-DefenseClaw-Connector: openclawPOSTTool, prompt, request, response and tool-result checks
/statusGETHealth
/enforce/blocked, /enforce/allowedGETRead the block and allow lists
/audit/eventPOSTWrite an audit row
/policy/evaluatePOSTAsk for a policy decision
/scan/resultPOSTRecord a scan result
/v1/plugin/scan, /api/v1/scan/codePOSTThe /scan command
/api/v1/openclaw/runtimeGETMode, 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 NAME

Protocol 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

User
OpenClaw
Plugin
Gateway
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)
  1. 1OpenClaw to Plugin

    about to run a tool

  2. 2Plugin to Gateway

    POST /api/v1/inspect/tool

  3. 3Gateway to Pluginreply

    allow · alert · confirm · block

  4. 4Plugin to OpenClawreply

    run, block, or requireApproval

  5. 5OpenClaw to User

    asks for approval (confirm only)

  6. 6User to OpenClawreply

    approve or deny

  7. 7OpenClaw to Plugin

    reports the answer (logged)

OperatorAgentConnectorGateway
Before each tool runs, the plugin posts it to the inspect API (port 18970 by default). In action mode a block verdict stops the tool and a confirm verdict becomes OpenClaw's requireApproval, which denies on timeout. Allow and alert let the tool run. OpenClaw asks the user and applies the answer. The plugin only logs it.
Text version of this diagram

Participants

  • User (operator)
  • OpenClaw (agent)
  • Plugin (connector)
  • Gateway (gateway)

Messages, in order

  1. OpenClaw to Plugin: about to run a tool
  2. Plugin to Gateway: POST /api/v1/inspect/tool
  3. Gateway to Plugin (reply): allow · alert · confirm · block
  4. Plugin to OpenClaw (reply): run, block, or requireApproval
  5. OpenClaw to User: asks for approval (confirm only)
  6. User to OpenClaw (reply): approve or deny
  7. OpenClaw to Plugin: reports the answer (logged)

Verdict wait

The plugin waits for a verdict as long as the gateway says:

CaseWait
No human approvalThe hook judge budget (guardrail.judge.hook_timeout) plus 2 seconds
Human approval onThe approval timeout plus 5 seconds
Budget OpenClaw gives the hookThe 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 buffer or media value, 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 content or body field.

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-Id
  • X-DefenseClaw-Agent-Id, X-DefenseClaw-Agent-Name, X-DefenseClaw-Policy-Id
  • X-DefenseClaw-Agent-Instance-Id, X-DefenseClaw-Sidecar-Instance-Id
  • X-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.