使用 before_prompt_build hook 创建和管理插件
信息值版本1.0.0 — 2026-05-07状态运行中
使用 OpenClaw hook 系统创建和管理插件。
触发器行动"创建插件"初始化新插件"添加 hook"注册新 hook"注入上下文"使用 hook 注入上下文"修改网关"配置网关
Hook触发时机用途before_prompt_build构建提示前注入上下文、修改消息after_response响应后日志、监控on_error错误时错误处理
text
~/.openclaw/plugins/<plugin-name>/
├── plugin.json # 插件配置
├── hooks/
│ └── before_prompt_build.js
└── README.md
bash
mkdir -p ~/.openclaw/plugins/<plugin-name>/hooks
json
{
"name": "plugin-name",
"version": "1.0.0",
"hooks": [
{
"name": "before_prompt_build",
"file": "hooks/before_prompt_build.js"
}
],
"description": "插件描述"
}
javascript
// hooks/before_prompt_build.js
module.exports = async function(context) {
// 添加上下文
context.systemMessage = "你的系统消息";
// 或修改用户消息
// context.messages[0].content = "修改后的内容";
return context;
};
bash
# 启用插件
openclaw plugin enable <plugin-name>
# 禁用插件
openclaw plugin disable <plugin-name>
# 列出所有插件
openclaw plugin list
javascript
// hooks/before_prompt_build.js
module.exports = async function(context) {
// 添加时间上下文
const now = new Date();
context.systemMessage += `\n当前时间:${now.toISOString()}`;
return context;
};
javascript
module.exports = async function(context) {
// 检查用户消息
if (context.messages[0].content.includes("密码")) {
// 添加安全警告
context.messages[0].content += "\n\n⚠️ 安全提示:请勿分享敏感信息";
}
return context;
};
情况处理方法Hook 抛出错误记录错误,继续执行插件冲突禁用冲突插件Hook 无效检查语法和路径插件加载失败检查 plugin.json 格式
In Altum Per Plugin. 🔌 OpenClaw 插件 v1.0