openclaw - 💡(How to fix) Fix [Feature]: tool:before hook — per-tool-call interception for user feedback & visual audit trail [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#60766Fetched 2026-04-08 02:47:28
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
1
Participants
Timeline (top)
labeled ×1

Add a tool:before hook event so hooks can intercept individual tool executions before they run, enabling screenshot/screen-recording confirmation workflows without relying on model self-discipline.

Error Message

// { allow: false, reason: string } → block, return error to agent

Root Cause

Add a tool:before hook event so hooks can intercept individual tool executions before they run, enabling screenshot/screen-recording confirmation workflows without relying on model self-discipline.

Fix Action

Fix / Workaround

The only available workaround is hoping the AI model "remembers" to do this on its own — which is unreliable, depends on model honesty, and fails consistently in practice. Users have a legitimate right to know what an AI agent is doing on their machine before it happens.

RAW_BUFFERClick to expand / collapse

Summary

Add a tool:before hook event so hooks can intercept individual tool executions before they run, enabling screenshot/screen-recording confirmation workflows without relying on model self-discipline.

Problem to solve

Currently OpenClaw hooks only support: agent:bootstrap (once per session) and message:preprocessed (once per message). There is no event that fires before each individual tool execution.

This makes it impossible to implement visual feedback workflows where:

  • Privacy-sensitive operations (file deletion, screenshot, clipboard access) require screenshot confirmation before proceeding
  • Multi-step operations are screen-recorded so users can see exactly what was done
  • Single-step operations are screenshot before and after to prove correctness

The only available workaround is hoping the AI model "remembers" to do this on its own — which is unreliable, depends on model honesty, and fails consistently in practice. Users have a legitimate right to know what an AI agent is doing on their machine before it happens.

Proposed solution

Add a new hook event tool:before that fires before each tool execution, allowing hooks to intercept, inspect, and conditionally block tool calls.

Proposed handler signature:

const handler = async (event: { type: "tool", action: "before" | "after", toolName: string, // e.g. "exec", "browser", "message" toolCallId: string, params: Record<string, any>, session: Session }) => { // Return options: // { allow: true } → proceed with execution // { allow: false, reason: string } → block, return error to agent // { screenshot: true } → pause, screenshot, resume on user confirm };

The hook receives full tool parameters so it can make context-aware decisions (e.g. only pause on delete operations, not on read operations).

Alternative: extend message:preprocessed to include tool planning metadata so hooks can inject conditional reminders based on which tools will be called.

Alternatives considered

  1. Rely on model self-discipline: The agent "remembers" to screenshot/confirm before sensitive operations. This is unreliable and fails consistently in practice — the model does not consistently follow its own guidelines.

  2. Bootstrap reminder only: agent:bootstrap fires once per session; the reminder is forgotten after a few turns. Cannot enforce ongoing behavior.

  3. message:preprocessed: Fires per message, not per tool call. Cannot distinguish which tools will be called within a message, so hooks cannot make targeted interception decisions.

  4. Per-tool configuration: Add a config flag like tools.exec.requireScreenshot: ["delete", "rm", "trash"]. This is more rigid, requires user config for each tool, and cannot handle conditional logic (e.g. "only screenshot if path contains user data").

Impact

Affected users: All OpenClaw users who want visual transparency into what the AI is doing on their machine.

Severity: High for users who prioritize safety and transparency. The current architecture makes it impossible to build trustworthy visual audit trails without this event.

Frequency: Any tool execution that could affect the user's system (exec, file operations, clipboard, screenshots, messages).

Consequences: Without this, users must blindly trust that the AI will "remember" to screenshot/confirm — which it consistently fails to do in practice. This erodes trust and prevents deployment of OpenClaw in security-sensitive environments. With this event, users can build wake-up-rec style workflows that give genuine visual accountability.

Evidence/examples

No response

Additional information

No response

extent analysis

TL;DR

Implement a tool:before hook event to enable hooks to intercept individual tool executions before they run, allowing for screenshot/screen-recording confirmation workflows.

Guidance

  • Add a new hook event tool:before that fires before each tool execution, passing in relevant parameters such as toolName, toolCallId, and params.
  • Define a handler signature for the tool:before event that allows hooks to inspect and conditionally block tool calls, with return options to proceed with execution, block with an error, or pause for user confirmation.
  • Consider extending the message:preprocessed event to include tool planning metadata as an alternative solution.
  • Evaluate the impact of implementing the tool:before event on existing users and workflows, particularly those who prioritize safety and transparency.

Example

const handler = async (event: {
  type: "tool",
  action: "before" | "after",
  toolName: string,
  toolCallId: string,
  params: Record<string, any>,
  session: Session
}) => {
  if (event.toolName === "exec" && event.params.command === "delete") {
    return { screenshot: true }; // pause and screenshot before deletion
  }
  return { allow: true }; // proceed with execution
};

Notes

The implementation of the tool:before event requires careful consideration of the potential impact on existing users and workflows, as well as the trade-offs between security, transparency, and usability.

Recommendation

Apply the workaround by implementing the tool:before hook event, as it provides a more flexible and reliable solution for enabling visual feedback workflows and screenshot/screen-recording confirmation.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING