Skip to content

Feature: Add tool:before / exec:before hook event for pre-execution interception #6613

Description

@aaroneden

Summary

Add a tool:before or exec:before hook event that fires before a tool executes, allowing hooks to intercept, modify, or block tool calls.

Use Case

I want to block specific dangerous commands (like gog gmail send, gog gmail delete) while allowing everything else to run freely. Currently:

  • The exec-approvals system only supports allowlist mode (no denylist)
  • The tool_result_persist hook fires after execution (too late to block)
  • There's no way to intercept commands before they run

Proposed Solution

Add a new hook event:

// Event structure
{
  type: 'tool',
  action: 'before',
  toolName: string,        // e.g., 'exec', 'read', 'write'
  toolArgs: object,        // tool arguments
  command?: string,        // for exec: the command being run
  sessionKey: string,
  timestamp: Date,
  // Hook can set this to block execution
  blocked?: boolean,
  blockReason?: string
}

Example Handler

const handler: HookHandler = async (event) => {
  if (event.type !== 'tool' || event.action !== 'before') return;
  
  if (event.toolName === 'exec' && event.command?.match(/gog gmail (send|delete)/)) {
    event.blocked = true;
    event.blockReason = 'Email send/delete requires manual approval';
  }
};

Alternatives Considered

  1. Wrapper scripts - Works but fragile, requires PATH manipulation
  2. Allowlist mode - Requires maintaining a huge allowlist of "safe" commands
  3. Agent guardrails - Soft guidance only, not enforced

Environment

  • OpenClaw 2026.1.30
  • macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions