skills-experimental/hooks/SKILL.md
Lifecycle hooks system for custom shell commands at various points. Execute user-defined hooks at PreToolUse, PostToolUse, Notification, Stop events. Use when [hooks] is needed.
npx skillsauth add bianhaifeng789-hue/openclaw-config hooksInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
在各种生命周期事件时执行用户自定义的 shell 命令。
场景:
Claude Code 方案:hooks.ts(5000+行)+ 多种 HookEvent OpenClaw 飞书适配:简化版 + 飞书卡片通知
| Event | 触发时机 | 用途 | |-------|----------|------| | PreToolUse | 工具执行前 | 检查、拦截、准备 | | PostToolUse | 工具执行后 | 后处理、记录、通知 | | Notification | 通知发送时 | 自定义通知 | | Stop | 会话停止时 | 清理、保存、报告 | | PrePrompt | 提示发送前 | 修改提示内容 | | PostPrompt | 提示发送后 | 记录提示历史 |
// hooks-config.json
{
"hooks": [
{
"event": "PreToolUse",
"matcher": {
"toolName": "BashTool"
},
"command": "./scripts/check-command.sh",
"timeout": 5000
},
{
"event": "PostToolUse",
"matcher": {
"toolName": "FileEditTool"
},
"command": "./scripts/record-edit.sh",
"timeout": 10000
},
{
"event": "Notification",
"command": "./scripts/custom-notify.sh",
"timeout": 3000
},
{
"event": "Stop",
"command": "./scripts/session-cleanup.sh",
"timeout": 30000
}
]
}
interface HookInput {
event: HookEvent
toolName?: string
toolInput?: object
toolResult?: object
message?: string
timestamp: Date
sessionId: string
}
interface HookOutput {
// 同步输出(直接返回)
status: 'success' | 'error' | 'blocked'
message?: string
modifiedInput?: object // PreToolUse 可修改输入
// 异步输出(JSON 格式)
prompt?: string // PrePrompt 可修改提示
permission?: 'allow' | 'deny' | 'ask'
notification?: {
title: string
message: string
}
}
{
"config": {"wide_screen_mode": true},
"elements": [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": "**🪝 Hook 已执行**\n\n**事件**:PreToolUse\n**工具**:BashTool\n**命令**:./scripts/check-command.sh\n\n**结果**:✅ 成功\n**耗时**:125ms\n\n**输出**:\n命令检查通过,允许执行。"
}
}
]
}
{
"config": {"wide_screen_mode": true},
"elements": [
{
"tag": "div",
"text": {
"tag": "lark_md",
"content": "**🪝 Hook 拦截**\n\n**事件**:PreToolUse\n**工具**:BashTool\n**命令**:rm -rf /\n\n**结果**:❌ 阻止\n**理由**:危险命令,禁止执行\n\n**建议**:使用 trash 命令替代。"
}
}
]
}
Startup:
1. 读取 hooks-config.json
2. 解析 hooks 数组
3. 按事件类型分组
4. 注册到 hookRegistry
Lifecycle Event:
1. 检查是否有匹配的 hook
2. 构造 HookInput
3. 执行 shell 命令(spawn child process)
4. 等待输出(timeout 限制)
5. 解析 HookOutput
6. 根据输出执行后续操作:
- success: 继续
- blocked: 拦截,返回错误
- modifiedInput: 使用修改后的输入
function executeHook(command: string, input: HookInput): Promise<HookOutput> {
const child = spawn(command, {
env: {
...process.env,
HOOK_EVENT: input.event,
HOOK_TOOL_NAME: input.toolName,
HOOK_SESSION_ID: input.sessionId,
HOOK_INPUT: JSON.stringify(input.toolInput)
}
})
// 等待输出,超时则终止
const output = await waitForOutput(child, timeout)
// 解析 JSON 输出
if (isJSON(output)) {
return JSON.parse(output)
}
// 同步输出
return { status: 'success', message: output }
}
interface HookMatcher {
toolName?: string | string[] // 工具名匹配
toolInput?: object // 输入匹配
messagePattern?: RegExp // 消息模式
}
示例:
{
"matcher": {
"toolName": ["BashTool", "FileEditTool"],
"toolInput": {
"command": "rm*"
}
}
}
// memory/hooks-state.json
{
"hooksRegistered": [
{
"event": "PreToolUse",
"matcher": {"toolName": "BashTool"},
"command": "./scripts/check-command.sh",
"enabled": true
}
],
"hooksExecuted": [
{
"hookId": "hook-1",
"event": "PreToolUse",
"toolName": "BashTool",
"status": "success",
"timestamp": "2026-04-11T23:30:00Z",
"duration": 125
}
],
"stats": {
"hooksExecuted": 0,
"hooksBlocked": 0,
"hooksFailed": 0
}
}
| Claude Code | OpenClaw 飞书场景 | |-------------|------------------| | hooks.ts(5000+行) | 简化版 Skill | | HookInput/Output 复杂类型 | 简化 JSON | | 多种 Matcher 类型 | 工具名/输入匹配 | | Shell + PowerShell | Shell 命令 | | 终端通知 | 飞书卡片 | | PermissionRequestResult | allow/deny/ask |
此 Skill 在工具执行前后、通知发送、会话停止时自动触发。
business
IAA 日报飞书输出能力。 支持把固定 CSV 模板一键转换成: - 中文运营结论 - 飞书卡片 JSON - 飞书发送载荷 Use when: - 需要把 IAA 日报直接发到飞书 - 需要从 CSV 一键生成运营日报
data-ai
IAA日报分析模型 功能: - 渠道日报自动分析 - 小时级+日级ROI联动判断 - 按地区输出加量/降量/停投建议 - 按产品类型输出阈值 - 自动识别利润区/观察区/止损区 Use when: - 分析每天投放数据 - 生成运营日报结论 - 判断是否加量/降量/停投 - 对比美加澳/日韩表现 Keywords: - 日报模型, 投放日报, 加量, 降量, 停投, ROI日报, 分地区分析
data-ai
IAA固定日报分析模板 功能: - 固定字段模板(可直接贴每天数据) - 自动输出总盘结论 - 自动输出美加澳/日韩结论 - 自动给出加量/降量/停投建议 - 适配文件修复/清理两类产品 Use when: - 需要固定日报格式 - 每天复盘渠道表现 - 给运营团队出统一结论 Keywords: - 固定模板, 日报模板, ROI模板, IAA日报, 运营模板
development
# HyperlinkPool Pattern Skill HyperlinkPool Pattern - HyperlinkPool class + strings array + stringMap + Index 0 no hyperlink + intern(hyperlink) + get(id) + undefined handling + 5-minute reset + OSC8 hyperlink interning。 ## 功能概述 从Claude Code的ink/screen.ts提取的HyperlinkPool模式,用于OpenClaw的OSC8超链接池管理。 ## 核心机制 ### HyperlinkPool Class ```typescript export class HyperlinkPool { private strings: string[] = [''] // Index 0 = no hyperlink private stringMap = new Map<string, number>() // strings