openclaw - 💡(How to fix) Fix [Feature]: [Feature Request] Skill Hook: 工具执行前自动调用 Skill 审查 [1 comments, 2 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#77954Fetched 2026-05-06 06:18:53
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
2
Timeline (top)
closed ×1commented ×1labeled ×1unsubscribed ×1

Error Message

throw new Error(Blocked by ${skill.name}: ${result.reason}) throw new Error(Blocked by ${skill.name}: ${result.reason})

Code Example

// 伪代码:工具执行流程

async function executeTool(tool, input) {

  // 1. 执行前 Hook

  for (const skill of getSkillsForHook('tool:before-execute')) {

   const result = await skill.check(tool, input)

   if (result.blocked) {

   throw new Error(`Blocked by ${skill.name}: ${result.reason}`)

   }

  }

  

  // 2. 执行工具

  return await tool.execute(input)

  

  // 3. 执行后 Hook

  for (const skill of getSkillsForHook('tool:after-execute')) {

   await skill.onComplete(tool, result)

  }

}

### Problem to solve

## 需求标题
**Skill Hook: 工具执行前自动调用 Skill 审查**

## 背景

基于 Claude Code 源码深度分析,我为 OpenClaw 创建了以下安全/优化技能:

1. **bash-security** - 23Bash 安全规则检查器
2. **context-compression** - 5级上下文压缩体系
3. **memory-三层架构** -//冷记忆分层
4. **prompt-cache-optimization** - Prompt 缓存优化
5. **tool-orchestration** - 工具并发安全控制

这些技能目前只能**手动调用**,无法在 OpenClaw 执行工具(如 `exec`)时**自动触发**
## 需求描述

### 当前问题

OpenClaw`exec` 工具是核心内置工具,执行命令时:
1. 无安全检查流程
2. 无压缩触发机制
3. 无工具结果清理

用户需要手动调用技能进行检查,不能实现"命令发出前自动安全审查"
### 期望功能

在工具执行前增加 Skill Hook 机制:
RAW_BUFFERClick to expand / collapse

Summary

需求标题

Skill Hook: 工具执行前自动调用 Skill 审查

背景

基于 Claude Code 源码深度分析,我为 OpenClaw 创建了以下安全/优化技能:

  1. bash-security - 23条 Bash 安全规则检查器
  2. context-compression - 5级上下文压缩体系
  3. memory-三层架构 - 热/温/冷记忆分层
  4. prompt-cache-optimization - Prompt 缓存优化
  5. tool-orchestration - 工具并发安全控制

这些技能目前只能手动调用,无法在 OpenClaw 执行工具(如 exec)时自动触发

需求描述

当前问题

OpenClaw 的 exec 工具是核心内置工具,执行命令时:

  1. 无安全检查流程
  2. 无压缩触发机制
  3. 无工具结果清理

用户需要手动调用技能进行检查,不能实现"命令发出前自动安全审查"。

期望功能

在工具执行前增加 Skill Hook 机制:


// 伪代码:工具执行流程

async function executeTool(tool, input) {

  // 1. 执行前 Hook

  for (const skill of getSkillsForHook('tool:before-execute')) {

   const result = await skill.check(tool, input)

   if (result.blocked) {

   throw new Error(`Blocked by ${skill.name}: ${result.reason}`)

   }

  }

  

  // 2. 执行工具

  return await tool.execute(input)

  

  // 3. 执行后 Hook

  for (const skill of getSkillsForHook('tool:after-execute')) {

   await skill.onComplete(tool, result)

  }

}

### Problem to solve

## 需求标题
**Skill Hook: 工具执行前自动调用 Skill 审查**

## 背景

基于 Claude Code 源码深度分析,我为 OpenClaw 创建了以下安全/优化技能:

1. **bash-security** - 23条 Bash 安全规则检查器
2. **context-compression** - 5级上下文压缩体系
3. **memory-三层架构** -//冷记忆分层
4. **prompt-cache-optimization** - Prompt 缓存优化
5. **tool-orchestration** - 工具并发安全控制

这些技能目前只能**手动调用**,无法在 OpenClaw 执行工具(如 `exec`)时**自动触发**
## 需求描述

### 当前问题

OpenClaw 的 `exec` 工具是核心内置工具,执行命令时:
1. 无安全检查流程
2. 无压缩触发机制
3. 无工具结果清理

用户需要手动调用技能进行检查,不能实现"命令发出前自动安全审查"
### 期望功能

在工具执行前增加 Skill Hook 机制:

```typescript

// 伪代码:工具执行流程

async function executeTool(tool, input) {

  // 1. 执行前 Hook

  for (const skill of getSkillsForHook('tool:before-execute')) {

   const result = await skill.check(tool, input)

   if (result.blocked) {

   throw new Error(`Blocked by ${skill.name}: ${result.reason}`)

   }

  }

  

  // 2. 执行工具

  return await tool.execute(input)

  

  // 3. 执行后 Hook

  for (const skill of getSkillsForHook('tool:after-execute')) {

   await skill.onComplete(tool, result)

  }

}

### Proposed solution


# skills/bash-security/hook.yaml

hooks:

  - event: tool:before-execute

   filter: tool.name === 'exec'

   priority: 100

   async: true

### Alternatives considered

_No response_

### Impact


const toolMiddleware = [

  bashSecurityMiddleware,

  tokenBudgetMiddleware,

  compressionMiddleware,

]

### Evidence/examples

_No response_

### Additional information

_No response_

extent analysis

TL;DR

Implement a Skill Hook mechanism to automatically trigger security and optimization skills before executing tools like exec in OpenClaw.

Guidance

  1. Define the Skill Hook interface: Establish a standard interface for skills to implement, such as check and onComplete methods, to ensure consistency across different skills.
  2. Register skills for hooks: Create a mechanism for skills to register themselves for specific hooks, like tool:before-execute, to enable automatic triggering.
  3. Integrate hooks into tool execution: Modify the tool execution flow to invoke registered skills before and after execution, as shown in the provided pseudo-code.
  4. Configure skill priorities and filters: Allow skills to specify priorities and filters, such as tool.name === 'exec', to control the order and applicability of skill execution.

Example

The provided pseudo-code demonstrates how to integrate Skill Hooks into the tool execution flow:

async function executeTool(tool, input) {
  // 1. 执行前 Hook
  for (const skill of getSkillsForHook('tool:before-execute')) {
    const result = await skill.check(tool, input)
    if (result.blocked) {
      throw new Error(`Blocked by ${skill.name}: ${result.reason}`)
    }
  }
  // ...
}

Notes

The proposed solution assumes that the getSkillsForHook function is implemented to retrieve skills registered for a specific hook.

Recommendation

Apply the proposed Skill Hook mechanism to enable automatic security and optimization checks before executing tools like exec. This will improve the overall security and performance of OpenClaw.

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]: [Feature Request] Skill Hook: 工具执行前自动调用 Skill 审查 [1 comments, 2 participants]