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
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
Text version of this diagram
Participants
- Agent (agent)
- Connector hook (connector)
- Gateway (gateway)
- State store (data store)
Messages, in order
- Agent to Connector hook: about to run a tool
- Connector hook to Gateway: pre-tool event + call ID
- Gateway to State store: check earlier successful steps
- Gateway to State store: if not blocked: save a pending step
- Gateway to Connector hook (reply): allow · alert · confirm · block
- Connector hook to Agent (reply): the agent's allow, ask or deny
- Note on Agent: the tool runs if allowed
- Agent to Connector hook: tool finished
- Connector hook to Gateway: post-tool result, same call ID
- Gateway to State store: success: keep the step; else discard
- The pre-tool hook describes what the agent is about to do. DefenseClaw checks it against earlier successful steps and may block it.
- If the call is not blocked, DefenseClaw saves a pending step.
- 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_idsand relatedchain_match_*fields). These fields never change a verdict.
Which connectors support it
| Level | Meaning |
|---|---|
paired-outcomes | A call becomes history only when a matching, trusted result reports success. |
detection-only | Calls and results are inspected, but results do not advance state. |
direct-only | Only the current pre-tool call is judged; nothing is remembered. |
| Connector | Pre-tool events | Result evidence | State level |
|---|---|---|---|
| Claude Code | PreToolUse; PermissionRequest is direct-only | PostToolUse, PostToolUseFailure, PermissionDenied | paired-outcomes |
| Codex | PreToolUse; PermissionRequest is direct-only | PostToolUse; only apply_patch and MCP results count | paired-outcomes for apply_patch and MCP only |
| Hermes | pre_tool_call | post_tool_call; only extra.status=ok succeeds | paired-outcomes |
| Cursor | generic preToolUse | generic postToolUse and postToolUseFailure | paired-outcomes for generic events |
| OpenCode | tool.execute.before | tool.execute.after; bash also needs exit 0 | paired-outcomes |
| Amp | tool.call | tool.result; status=done succeeds | paired-outcomes |
| Devin | PreToolUse | PostToolUse, but no per-tool call ID | detection-only |
| GitHub Copilot CLI | preToolUse, permissionRequest | postToolUse, but no per-tool call ID | detection-only |
| Antigravity | PreToolUse | PostToolUse, keyed by step, not a call ID | detection-only |
| Kiro | preToolUse / PostToolUse per CLI version | Audited as result content | Pre-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, OpenCodesession.idle, Ampagent.end, Hermeson_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_patchenvelopes, 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.
Fix setup problems
Fix DefenseClaw guardrail setup problems such as hooks that do not load, stale scripts, a gateway that is down or a rejected rule pack, each with a check.
Model routing
Send each model call to the model that fits it, limit which models a group may use, cap spend and see what each call cost. Find which page covers what.