Hook System for Openclaw

A powerful tool interception framework to inject custom logic before and after AI tool execution.

xhmqq616
v1.0.0
Apr 6, 2026
0
642
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install hook-system

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install hook-system using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Hook System?

The Hook System is a specialized framework designed to provide granular control over the lifecycle of AI tool calls. By integrating this skill, developers can inject custom scripts into the execution flow, allowing for real-time monitoring, input validation, and output modification. It serves as a middleware layer that enhances the reliability and security of Openclaw Skills by ensuring every tool interaction follows predefined logic.

This system is essential for developers who need to build guardrails around their AI agents. It allows for the interruption of potentially harmful commands before they run (PreToolUse) and the sanitization of results before they are returned to the model (PostToolUse), making it a cornerstone for production-grade agentic workflows.

Hook System Use Cases

  • Preventing path traversal attacks by validating file paths in tool arguments before execution.
  • Automatically redacting sensitive data such as API keys or PII from tool outputs to maintain privacy.
  • Generating detailed audit logs of every tool interaction for compliance and debugging purposes.
  • Implementing conditional tool execution where an action is only allowed if specific environment criteria are met.

How Hook System Works

  1. When a user message triggers a tool call, the system identifies the associated Openclaw Skills hooks.
  2. The HookRunner executes PreToolUse scripts, passing tool metadata via environment variables.
  3. Based on the script exit code (0 for allow, 2 for deny), the system either proceeds to the Tool Executor or blocks the call.
  4. If allowed, the tool runs and its raw output is captured.
  5. The PostToolUse scripts are then executed to process, log, or modify the tool result before the final response is generated.

Hook System Setup

To get started with the Hook System, ensure you have Node.js 18 or higher installed. You can initialize the runner within your local Openclaw Skills environment using the following structure:

# Navigate to your skill directory
cd hook-system

# Configure your hooks in a JSON format
# { "hooks": { "preToolUse": ["node ./hooks/validate.mjs"] } }

To programmatically invoke the runner in your JavaScript environment:

const { HookRunner } = require('./scripts/hook-runner.mjs');
const runner = new HookRunner({
  preToolUse: ['echo "Validating $HOOK_TOOL_NAME"'],
  postToolUse: ['node ./hooks/filter-secrets.mjs']
});

Hook System Data Schema & Taxonomy

The Hook System leverages standard environment variables to communicate context to your scripts. This allows for language-agnostic hook implementation using Openclaw Skills.

Environment Variable Description
HOOK_EVENT Specifies the hook type: PreToolUse or PostToolUse.
HOOK_TOOL_NAME The name of the tool being intercepted.
HOOK_TOOL_INPUT The raw JSON string of the tool arguments.
HOOK_TOOL_OUTPUT The result of the tool execution (available in PostToolUse).
HOOK_TOOL_IS_ERROR A flag (0 or 1) indicating if the tool execution failed.

Hook System Advanced Features

  • Granular Exit Code Logic: Distinguish between allowing execution, denying it, or continuing with a warning based on script return values.
  • Environment Injection: Automatically provides parsed and beautified JSON inputs to simplify script logic for developers.
  • Secret Scrubbing: Built-in patterns for filtering sensitive information from tool responses using PostToolUse hooks.
  • Extensible Middleware: Support for multiple sequential hooks, enabling complex multi-stage validation pipelines for any agentic tool.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*