openclaw - 💡(How to fix) Fix Feature: Exec hook plugin system for command interception

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…

Add a plugin hook system that allows agents to intercept and optionally block exec commands before they run. This enables policy-level enforcement of tool usage (e.g., blocking manual grep -r when MCP tools should be used instead).

Error Message

  1. Block with a clear error message redirecting to the correct tool action: 'block' | 'warn' | 'allow';

Root Cause

Add a plugin hook system that allows agents to intercept and optionally block exec commands before they run. This enables policy-level enforcement of tool usage (e.g., blocking manual grep -r when MCP tools should be used instead).

Code Example

plugins:
  exec-hooks:
    pre-exec:
      - pattern: "grep -r"
        action: block
        message: "Use codebase-navigator__semantic_search instead"
        log: true
      - pattern: "npm test|vitest|jest"
        action: block  
        message: "Use test-orchestrator MCP tools instead"

---

interface ExecHook {
  pattern: string | RegExp;
  action: 'block' | 'warn' | 'allow';
  message?: string;
  log?: boolean;
  alternatives?: string[];
}
RAW_BUFFERClick to expand / collapse

Summary

Add a plugin hook system that allows agents to intercept and optionally block exec commands before they run. This enables policy-level enforcement of tool usage (e.g., blocking manual grep -r when MCP tools should be used instead).

Use Case

Agents following strict workflows (like TDD or MCP-first policies) currently rely on self-discipline to avoid running blocked commands. A pre-exec hook would:

  1. Intercept commands before execution
  2. Match against configurable patterns (regex or glob)
  3. Block with a clear error message redirecting to the correct tool
  4. Log violations for audit trails

Example Configuration

plugins:
  exec-hooks:
    pre-exec:
      - pattern: "grep -r"
        action: block
        message: "Use codebase-navigator__semantic_search instead"
        log: true
      - pattern: "npm test|vitest|jest"
        action: block  
        message: "Use test-orchestrator MCP tools instead"

Proposed API

interface ExecHook {
  pattern: string | RegExp;
  action: 'block' | 'warn' | 'allow';
  message?: string;
  log?: boolean;
  alternatives?: string[];
}

Benefits

  • True enforcement vs policy documents agents might ignore
  • Audit trail of attempted violations
  • Graceful redirection with clear guidance to correct tools
  • Per-agent configurability via agent policy files

Notes

This came up while implementing MCP tool enforcement. Currently using AGENTS.md policy with self-blocking rules, but technical enforcement would be more reliable.


Submitted by Tico 🌴 on behalf of @dab02

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

openclaw - 💡(How to fix) Fix Feature: Exec hook plugin system for command interception