Guardrail

Tool-call state

Catch a chain like reading a secret and then sending it by remembering a session's successful tool calls. See which connectors support it. Preview.

Preview. This feature can change in a later release. It does not change policy defaults, and it does not turn an observe-only connector into one that blocks.

Some attacks take several calls: read a secret, then send it; download a file, then run it. DefenseClaw remembers the tool calls of a session that really succeeded, so the 26 ordered chains (list) can be checked across calls and turns. A single-call rule, including every custom CEL rule, does not need this.

How a chain step is recorded

Agent
Connector hook
Gateway
State store
about to run a tool
pre-tool event + call ID
check earlier successful steps
if not blocked: save a pending step
allow · alert · confirm · block
the agent's allow, ask or deny
the tool runs if allowed
tool finished
post-tool result, same call ID
success: keep the step; else discard
  1. 1Agent to Connector hook

    about to run a tool

  2. 2Connector hook to Gateway

    pre-tool event + call ID

  3. 3Gateway to State store

    check earlier successful steps

  4. 4Gateway to State store

    if not blocked: save a pending step

  5. 5Gateway to Connector hookreply

    allow · alert · confirm · block

  6. 6Connector hook to Agentreply

    the agent's allow, ask or deny

  7. 7Note · Agent

    the tool runs if allowed

  8. 8Agent to Connector hook

    tool finished

  9. 9Connector hook to Gateway

    post-tool result, same call ID

  10. 10Gateway to State store

    success: keep the step; else discard

AgentConnectorGatewayData store
A pending step becomes history only after the post-tool event for the same call ID reports success. A failed, cancelled, unknown or expired call is discarded. The store is the gateway's SQLite database; it keeps hashes and step flags, not command text.
Text version of this diagram

Participants

  • Agent (agent)
  • Connector hook (connector)
  • Gateway (gateway)
  • State store (data store)

Messages, in order

  1. Agent to Connector hook: about to run a tool
  2. Connector hook to Gateway: pre-tool event + call ID
  3. Gateway to State store: check earlier successful steps
  4. Gateway to State store: if not blocked: save a pending step
  5. Gateway to Connector hook (reply): allow · alert · confirm · block
  6. Connector hook to Agent (reply): the agent's allow, ask or deny
  7. Note on Agent: the tool runs if allowed
  8. Agent to Connector hook: tool finished
  9. Connector hook to Gateway: post-tool result, same call ID
  10. Gateway to State store: success: keep the step; else discard
  1. The pre-tool hook describes what the agent is about to do. DefenseClaw checks it against earlier successful steps and may block it.
  2. If the call is not blocked, DefenseClaw saves a pending step.
  3. When the post-tool event for the same call reports success, the step becomes history. A failure, cancel, unknown result or timeout discards it.
  • A pending step never completes a chain. A blocked call is never recorded as successful.
  • Only authenticated connector hook events advance the state. Inspect, proxy and telemetry traffic never do.
  • History survives gateway restarts, within each chain's time and call-count window.
  • The call that completes a chain names it in its audit row (chain_match_ids and related chain_match_* fields). These fields never change a verdict.

Which connectors support it

LevelMeaning
paired-outcomesA call becomes history only when a matching, trusted result reports success.
detection-onlyCalls and results are inspected, but results do not advance state.
direct-onlyOnly the current pre-tool call is judged; nothing is remembered.
ConnectorPre-tool eventsResult evidenceState level
Claude CodePreToolUse; PermissionRequest is direct-onlyPostToolUse, PostToolUseFailure, PermissionDeniedpaired-outcomes
CodexPreToolUse; PermissionRequest is direct-onlyPostToolUse; only apply_patch and MCP results countpaired-outcomes for apply_patch and MCP only
Hermespre_tool_callpost_tool_call; only extra.status=ok succeedspaired-outcomes
Cursorgeneric preToolUsegeneric postToolUse and postToolUseFailurepaired-outcomes for generic events
OpenCodetool.execute.beforetool.execute.after; bash also needs exit 0paired-outcomes
Amptool.calltool.result; status=done succeedspaired-outcomes
DevinPreToolUsePostToolUse, but no per-tool call IDdetection-only
GitHub Copilot CLIpreToolUse, permissionRequestpostToolUse, but no per-tool call IDdetection-only
AntigravityPreToolUsePostToolUse, keyed by step, not a call IDdetection-only
KiropreToolUse / PostToolUse per CLI versionAudited as result contentPre-tool decisions only

Agents reached through the ACP guard are outside this feature. State is used only for an agent version DefenseClaw knows; a version mismatch turns state off for that session.

Session and turn ends

  • End of a turn (Codex, Claude Code or Cursor Stop, OpenCode session.idle, Amp agent.end, Hermes on_session_end (which Hermes sends at the end of every turn, not only when the session ends)) discards unfinished calls but keeps successful history, so a chain can span turns. A late result cannot promote a call left pending.
  • End, deletion or reset of a session discards pending calls and closes that session's chain window.
  • A subagent stop does not clear the session's pending calls.

What it covers

  • Shell commands (POSIX shell, PowerShell, cmd.exe), direct file reads, writes, edits, moves and deletes, reviewed built-in tools, MCP tools, and skill calls that the connector reports as tool events.
  • Mail, calendar and other SaaS actions only as their generic or MCP tool call. DefenseClaw does not guess that a custom tool sends mail.
  • apply_patch envelopes, with relative paths, as file writes and deletes. Patch contents are not kept.

Limits

  • Scripts run later. When a blockable shell call runs a local script, DefenseClaw can read that script (an absolute, regular file of at most 64 KiB with a known shell dialect) and judge its contents. This is best effort: another process could change the file after the check.
  • No file watcher. DefenseClaw does not rescan every file change on the host.
  • Churn. Under extreme session churn, the store of session cutoffs can fill; older boundaries are summarized, which can reduce chain detection but never creates a block.