{"id":12,"date":"2026-03-21T22:47:13","date_gmt":"2026-03-21T14:47:13","guid":{"rendered":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/automation-hooks\/"},"modified":"2026-03-21T23:09:26","modified_gmt":"2026-03-21T15:09:26","slug":"automation-hooks","status":"publish","type":"post","link":"https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/automation-hooks\/","title":{"rendered":"Hooks"},"content":{"rendered":"<h1>Hooks<\/h1>\n<p>Hooks \u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ef\u6269\u5c55\u7684\u4e8b\u4ef6\u9a71\u52a8\u7cfb\u7edf\uff0c\u7528\u4e8e\u5728\u54cd\u5e94\u667a\u80fd\u4f53\u547d\u4ee4\u548c\u4e8b\u4ef6\u65f6\u81ea\u52a8\u6267\u884c\u64cd\u4f5c\u3002Hooks \u4f1a\u4ece\u76ee\u5f55\u4e2d\u81ea\u52a8\u53d1\u73b0\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7 CLI \u547d\u4ee4\u8fdb\u884c\u7ba1\u7406\uff0c\u65b9\u5f0f\u4e0e OpenClaw \u4e2d\u7684 Skills \u7c7b\u4f3c\u3002<\/p>\n<h2>\u719f\u6089\u57fa\u7840<\/h2>\n<p>Hooks \u662f\u5728\u67d0\u4e9b\u4e8b\u60c5\u53d1\u751f\u65f6\u8fd0\u884c\u7684\u5c0f\u811a\u672c\u3002\u5b83\u4eec\u6709\u4e24\u79cd\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li><strong>Hooks<\/strong>\uff08\u672c\u9875\uff09\uff1a\u5f53\u667a\u80fd\u4f53\u4e8b\u4ef6\u89e6\u53d1\u65f6\uff0c\u5728 Gateway \u7f51\u5173\u5185\u8fd0\u884c\uff0c\u4f8b\u5982 <code>\/new<\/code>\u3001<code>\/reset<\/code>\u3001<code>\/stop<\/code> \u6216\u751f\u547d\u5468\u671f\u4e8b\u4ef6\u3002<\/li>\n<li><strong>Webhooks<\/strong>\uff1a\u5916\u90e8 HTTP webhook\uff0c\u53ef\u8ba9\u5176\u4ed6\u7cfb\u7edf\u5728 OpenClaw \u4e2d\u89e6\u53d1\u5de5\u4f5c\u3002\u8bf7\u53c2\u9605 <a href=\"\/automation\/webhook\">Webhook Hooks<\/a>\uff0c\u6216\u4f7f\u7528 <code>openclaw webhooks<\/code> \u83b7\u53d6 Gmail \u8f85\u52a9\u547d\u4ee4\u3002<\/li>\n<\/ul>\n<p>Hooks \u4e5f\u53ef\u4ee5\u6253\u5305\u5728\u63d2\u4ef6\u4e2d\uff1b\u8bf7\u53c2\u9605 <a href=\"\/tools\/plugin#plugin-hooks\">Plugins<\/a>\u3002<\/p>\n<p>\u5e38\u89c1\u7528\u9014\uff1a<\/p>\n<ul>\n<li>\u5f53\u4f60\u91cd\u7f6e\u4f1a\u8bdd\u65f6\u4fdd\u5b58\u4e00\u4efd\u5185\u5b58\u5feb\u7167<\/li>\n<li>\u4e3a\u6545\u969c\u6392\u9664\u6216\u5408\u89c4\u4fdd\u7559\u547d\u4ee4\u5ba1\u8ba1\u8f68\u8ff9<\/li>\n<li>\u5f53\u4f1a\u8bdd\u5f00\u59cb\u6216\u7ed3\u675f\u65f6\u89e6\u53d1\u540e\u7eed\u81ea\u52a8\u5316<\/li>\n<li>\u5f53\u4e8b\u4ef6\u89e6\u53d1\u65f6\uff0c\u5c06\u6587\u4ef6\u5199\u5165\u667a\u80fd\u4f53\u5de5\u4f5c\u533a\u6216\u8c03\u7528\u5916\u90e8 API<\/li>\n<\/ul>\n<p>\u5982\u679c\u4f60\u4f1a\u5199\u4e00\u4e2a\u5c0f\u578b TypeScript \u51fd\u6570\uff0c\u4f60\u5c31\u80fd\u7f16\u5199\u4e00\u4e2a hook\u3002Hooks \u4f1a\u88ab\u81ea\u52a8\u53d1\u73b0\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7 CLI \u542f\u7528\u6216\u7981\u7528\u5b83\u4eec\u3002<\/p>\n<h2>\u6982\u89c8<\/h2>\n<p>Hooks \u7cfb\u7edf\u5141\u8bb8\u4f60\uff1a<\/p>\n<ul>\n<li>\u5f53\u53d1\u51fa <code>\/new<\/code> \u65f6\uff0c\u5c06\u4f1a\u8bdd\u4e0a\u4e0b\u6587\u4fdd\u5b58\u5230 memory<\/li>\n<li>\u8bb0\u5f55\u6240\u6709\u547d\u4ee4\u4ee5\u4f9b\u5ba1\u8ba1<\/li>\n<li>\u5728\u667a\u80fd\u4f53\u751f\u547d\u5468\u671f\u4e8b\u4ef6\u4e0a\u89e6\u53d1\u81ea\u5b9a\u4e49\u81ea\u52a8\u5316<\/li>\n<li>\u5728\u4e0d\u4fee\u6539\u6838\u5fc3\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u6269\u5c55 OpenClaw \u7684\u884c\u4e3a<\/li>\n<\/ul>\n<h2>\u5165\u95e8\u6307\u5357<\/h2>\n<h3>\u5185\u7f6e Hooks<\/h3>\n<p>OpenClaw \u81ea\u5e26\u56db\u4e2a\u4f1a\u88ab\u81ea\u52a8\u53d1\u73b0\u7684\u5185\u7f6e hook\uff1a<\/p>\n<ul>\n<li><strong>\ud83d\udcbe session-memory<\/strong>\uff1a\u5f53\u4f60\u53d1\u51fa <code>\/new<\/code> \u65f6\uff0c\u5c06\u4f1a\u8bdd\u4e0a\u4e0b\u6587\u4fdd\u5b58\u5230\u4f60\u7684\u667a\u80fd\u4f53\u5de5\u4f5c\u533a\uff08\u9ed8\u8ba4\u662f <code>~\/.openclaw\/workspace\/memory\/<\/code>\uff09<\/li>\n<li><strong>\ud83d\udcce bootstrap-extra-files<\/strong>\uff1a\u5728 <code>agent:bootstrap<\/code> \u671f\u95f4\uff0c\u4ece\u5df2\u914d\u7f6e\u7684 glob\/\u8def\u5f84\u6a21\u5f0f\u4e2d\u6ce8\u5165\u989d\u5916\u7684\u5de5\u4f5c\u533a\u5f15\u5bfc\u6587\u4ef6<\/li>\n<li><strong>\ud83d\udcdd command-logger<\/strong>\uff1a\u5c06\u6240\u6709\u547d\u4ee4\u4e8b\u4ef6\u8bb0\u5f55\u5230 <code>~\/.openclaw\/logs\/commands.log<\/code><\/li>\n<li><strong>\ud83d\ude80 boot-md<\/strong>\uff1a\u5f53 Gateway \u7f51\u5173\u542f\u52a8\u65f6\u8fd0\u884c <code>BOOT.md<\/code>\uff08\u9700\u8981\u542f\u7528\u5185\u90e8 hooks\uff09<\/li>\n<\/ul>\n<p>\u5217\u51fa\u53ef\u7528 hooks\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks list<\/p>\n<pre><code>\n\u542f\u7528\u4e00\u4e2a hook\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nopenclaw hooks enable session-memory\n<\/code><\/pre>\n<p>\u68c0\u67e5 hook \u72b6\u6001\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks check<\/p>\n<pre><code>\n\u83b7\u53d6\u8be6\u7ec6\u4fe1\u606f\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nopenclaw hooks info session-memory\n<\/code><\/pre>\n<h3>\u65b0\u624b\u5f15\u5bfc<\/h3>\n<p>\u5728\u65b0\u624b\u5f15\u5bfc\u671f\u95f4\uff08<code>openclaw onboard<\/code>\uff09\uff0c\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u542f\u7528\u63a8\u8350\u7684 hooks\u3002\u5411\u5bfc\u4f1a\u81ea\u52a8\u53d1\u73b0\u7b26\u5408\u6761\u4ef6\u7684 hooks \u5e76\u4f9b\u4f60\u9009\u62e9\u3002<\/p>\n<h2>Hook \u53d1\u73b0<\/h2>\n<p>Hooks \u4f1a\u4ece\u4e09\u4e2a\u76ee\u5f55\u4e2d\u81ea\u52a8\u53d1\u73b0\uff08\u6309\u4f18\u5148\u7ea7\u987a\u5e8f\uff09\uff1a<\/p>\n<ol>\n<li><strong>\u5de5\u4f5c\u533a hooks<\/strong>\uff1a<code>&lt;workspace&gt;\/hooks\/<\/code>\uff08\u6bcf\u4e2a\u667a\u80fd\u4f53\u5355\u72ec\u914d\u7f6e\uff0c\u4f18\u5148\u7ea7\u6700\u9ad8\uff09<\/li>\n<li><strong>\u6258\u7ba1 hooks<\/strong>\uff1a<code>~\/.openclaw\/hooks\/<\/code>\uff08\u7528\u6237\u5b89\u88c5\uff0c\u5728\u5404\u5de5\u4f5c\u533a\u4e4b\u95f4\u5171\u4eab\uff09<\/li>\n<li><strong>\u5185\u7f6e hooks<\/strong>\uff1a<code>&lt;openclaw&gt;\/dist\/hooks\/bundled\/<\/code>\uff08\u968f OpenClaw \u4e00\u8d77\u63d0\u4f9b\uff09<\/li>\n<\/ol>\n<p>\u6258\u7ba1 hook \u76ee\u5f55\u65e2\u53ef\u4ee5\u662f <strong>\u5355\u4e2a hook<\/strong>\uff0c\u4e5f\u53ef\u4ee5\u662f <strong>hook \u5305<\/strong>\uff08\u5305\u76ee\u5f55\uff09\u3002<\/p>\n<p>\u6bcf\u4e2a hook \u90fd\u662f\u4e00\u4e2a\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u76ee\u5f55\uff1a<\/p>\n<pre><code>my-hook\/\n\u251c\u2500\u2500 HOOK.md          # \u5143\u6570\u636e + \u6587\u6863\n\u2514\u2500\u2500 handler.ts       # \u5904\u7406\u5668\u5b9e\u73b0\n<\/code><\/pre>\n<h2>Hook \u5305\uff08npm\/\u5f52\u6863\uff09<\/h2>\n<p>Hook \u5305\u662f\u6807\u51c6\u7684 npm \u5305\uff0c\u5b83\u4eec\u901a\u8fc7 <code>package.json<\/code> \u4e2d\u7684 <code>openclaw.hooks<\/code> \u5bfc\u51fa\u4e00\u4e2a\u6216\u591a\u4e2a hook\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks install <\/p>\n<pre><code>\nnpm spec \u4ec5\u652f\u6301\u6ce8\u518c\u8868\u5f62\u5f0f\uff08\u5305\u540d + \u53ef\u9009\u7684\u7cbe\u786e\u7248\u672c\u6216 dist-tag\uff09\u3002\nGit\/URL\/file spec \u548c semver \u8303\u56f4\u4f1a\u88ab\u62d2\u7edd\u3002\n\n\u88f8 spec \u548c `@latest` \u4f1a\u4fdd\u6301\u5728\u7a33\u5b9a\u8f68\u9053\u4e0a\u3002\u5982\u679c npm \u5c06\u5176\u4e2d\u4efb\u610f\u4e00\u79cd\u89e3\u6790\u4e3a\u9884\u53d1\u5e03\u7248\u672c\uff0cOpenClaw \u4f1a\u505c\u6b62\u5e76\u8981\u6c42\u4f60\u901a\u8fc7\u9884\u53d1\u5e03\u6807\u7b7e\uff08\u4f8b\u5982 `@beta`\/`@rc`\uff09\u6216\u7cbe\u786e\u7684\u9884\u53d1\u5e03\u7248\u672c\u663e\u5f0f\u9009\u62e9\u52a0\u5165\u3002\n\n`package.json` \u793a\u4f8b\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;name&quot;: &quot;@acme\/my-hooks&quot;,\n  &quot;version&quot;: &quot;0.1.0&quot;,\n  &quot;openclaw&quot;: {\n    &quot;hooks&quot;: [&quot;.\/hooks\/my-hook&quot;, &quot;.\/hooks\/other-hook&quot;]\n  }\n}\n<\/code><\/pre>\n<p>\u6bcf\u4e2a\u6761\u76ee\u90fd\u6307\u5411\u4e00\u4e2a\u5305\u542b <code>HOOK.md<\/code> \u548c <code>handler.ts<\/code>\uff08\u6216 <code>index.ts<\/code>\uff09\u7684 hook \u76ee\u5f55\u3002<br \/>\nHook \u5305\u53ef\u4ee5\u643a\u5e26\u4f9d\u8d56\uff1b\u5b83\u4eec\u4f1a\u5b89\u88c5\u5230 <code>~\/.openclaw\/hooks\/&lt;id&gt;<\/code> \u4e0b\u3002<br \/>\n\u6bcf\u4e2a <code>openclaw.hooks<\/code> \u6761\u76ee\u5728\u89e3\u6790\u7b26\u53f7\u94fe\u63a5\u540e\u90fd\u5fc5\u987b\u4fdd\u6301\u5728\u5305\u76ee\u5f55\u5185\u90e8\uff1b\u8d85\u51fa\u76ee\u5f55\u8303\u56f4\u7684\u6761\u76ee\u4f1a\u88ab\u62d2\u7edd\u3002<\/p>\n<p>\u5b89\u5168\u8bf4\u660e\uff1a<code>openclaw hooks install<\/code> \u4f1a\u4f7f\u7528 <code>npm install --ignore-scripts<\/code> \u5b89\u88c5\u4f9d\u8d56<br \/>\n\uff08\u4e0d\u8fd0\u884c\u751f\u547d\u5468\u671f\u811a\u672c\uff09\u3002\u8bf7\u4fdd\u6301 hook \u5305\u4f9d\u8d56\u6811\u4e3a\u201c\u7eaf JS\/TS\u201d\uff0c\u5e76\u907f\u514d\u4f9d\u8d56 <code>postinstall<\/code> \u6784\u5efa\u7684\u5305\u3002<\/p>\n<h2>Hook \u7ed3\u6784<\/h2>\n<h3>HOOK.md \u683c\u5f0f<\/h3>\n<p><code>HOOK.md<\/code> \u6587\u4ef6\u5305\u542b YAML frontmatter \u4e2d\u7684\u5143\u6570\u636e\u4ee5\u53ca Markdown \u6587\u6863\uff1a<\/p>\n<h2>&#8220;`markdown  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/h2>\n<p>name: my-hook<br \/>\ndescription: &#8220;\u5173\u4e8e\u6b64 hook \u529f\u80fd\u7684\u7b80\u77ed\u63cf\u8ff0&#8221;<br \/>\nhomepage: https:\/\/pa.yingzhi8.cn\/index.php\/2026\/03\/21\/automation-hooks\/#my-hook<br \/>\nmetadata:<br \/>\n  { &#8220;openclaw&#8221;: { &#8220;emoji&#8221;: &#8220;\ud83d\udd17&#8221;, &#8220;events&#8221;: [&#8220;command:new&#8221;], &#8220;requires&#8221;: { &#8220;bins&#8221;: [&#8220;node&#8221;] } } }<\/p>\n<hr \/>\n<h1>My Hook<\/h1>\n<p>\u8be6\u7ec6\u6587\u6863\u5199\u5728\u8fd9\u91cc\u2026\u2026<\/p>\n<h2>\u5b83\u7684\u4f5c\u7528<\/h2>\n<ul>\n<li>\u76d1\u542c <code>\/new<\/code> \u547d\u4ee4<\/li>\n<li>\u6267\u884c\u67d0\u4e9b\u64cd\u4f5c<\/li>\n<li>\u8bb0\u5f55\u7ed3\u679c<\/li>\n<\/ul>\n<h2>\u8981\u6c42<\/h2>\n<ul>\n<li>\u5fc5\u987b\u5b89\u88c5 Node.js<\/li>\n<\/ul>\n<h2>\u914d\u7f6e<\/h2>\n<p>\u65e0\u9700\u914d\u7f6e\u3002<\/p>\n<pre><code>\n### \u5143\u6570\u636e\u5b57\u6bb5\n\n`metadata.openclaw` \u5bf9\u8c61\u652f\u6301\uff1a\n\n* **`emoji`**\uff1aCLI \u663e\u793a\u7528 emoji\uff08\u4f8b\u5982 `&quot;\ud83d\udcbe&quot;`\uff09\n* **`events`**\uff1a\u8981\u76d1\u542c\u7684\u4e8b\u4ef6\u6570\u7ec4\uff08\u4f8b\u5982 `[&quot;command:new&quot;, &quot;command:reset&quot;]`\uff09\n* **`export`**\uff1a\u8981\u4f7f\u7528\u7684\u547d\u540d\u5bfc\u51fa\uff08\u9ed8\u8ba4\u4e3a `&quot;default&quot;`\uff09\n* **`homepage`**\uff1a\u6587\u6863 URL\n* **`requires`**\uff1a\u53ef\u9009\u8981\u6c42\n  * **`bins`**\uff1aPATH \u4e2d\u5fc5\u987b\u5b58\u5728\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u4f8b\u5982 `[&quot;git&quot;, &quot;node&quot;]`\uff09\n  * **`anyBins`**\uff1a\u8fd9\u4e9b\u4e8c\u8fdb\u5236\u6587\u4ef6\u4e2d\u81f3\u5c11\u8981\u5b58\u5728\u4e00\u4e2a\n  * **`env`**\uff1a\u5fc5\u9700\u7684\u73af\u5883\u53d8\u91cf\n  * **`config`**\uff1a\u5fc5\u9700\u7684\u914d\u7f6e\u8def\u5f84\uff08\u4f8b\u5982 `[&quot;workspace.dir&quot;]`\uff09\n  * **`os`**\uff1a\u652f\u6301\u7684\u5e73\u53f0\uff08\u4f8b\u5982 `[&quot;darwin&quot;, &quot;linux&quot;]`\uff09\n* **`always`**\uff1a\u7ed5\u8fc7\u8d44\u683c\u68c0\u67e5\uff08\u5e03\u5c14\u503c\uff09\n* **`install`**\uff1a\u5b89\u88c5\u65b9\u5f0f\uff08\u5bf9\u4e8e\u5185\u7f6e hooks\uff1a`[{&quot;id&quot;:&quot;bundled&quot;,&quot;kind&quot;:&quot;bundled&quot;}]`\uff09\n\n### \u5904\u7406\u5668\u5b9e\u73b0\n\n`handler.ts` \u6587\u4ef6\u4f1a\u5bfc\u51fa\u4e00\u4e2a `HookHandler` \u51fd\u6570\uff1a\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nconst myHandler = async (event) =&gt; {\n  \/\/ \u4ec5\u5728 'new' \u547d\u4ee4\u65f6\u89e6\u53d1\n  if (event.type !== &quot;command&quot; || event.action !== &quot;new&quot;) {\n    return;\n  }\n\n  console.log(`[my-hook] New command triggered`);\n  console.log(`  Session: ${event.sessionKey}`);\n  console.log(`  Timestamp: ${event.timestamp.toISOString()}`);\n\n  \/\/ \u4f60\u7684\u81ea\u5b9a\u4e49\u903b\u8f91\u5199\u5728\u8fd9\u91cc\n\n  \/\/ \u53ef\u9009\uff1a\u5411\u7528\u6237\u53d1\u9001\u6d88\u606f\n  event.messages.push(&quot;\u2728 My hook executed!&quot;);\n};\n\nexport default myHandler;\n<\/code><\/pre>\n<h4>\u4e8b\u4ef6\u4e0a\u4e0b\u6587<\/h4>\n<p>\u6bcf\u4e2a\u4e8b\u4ef6\u90fd\u5305\u542b\uff1a<\/p>\n<p>&#8220;`typescript  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  type: &#8216;command&#8217; | &#8216;session&#8217; | &#8216;agent&#8217; | &#8216;gateway&#8217; | &#8216;message&#8217;,<br \/>\n  action: string,              \/\/ \u4f8b\u5982 &#8216;new&#8217;\u3001&#8217;reset&#8217;\u3001&#8217;stop&#8217;\u3001&#8217;received&#8217;\u3001&#8217;sent&#8217;<br \/>\n  sessionKey: string,          \/\/ \u4f1a\u8bdd\u6807\u8bc6\u7b26<br \/>\n  timestamp: Date,             \/\/ \u4e8b\u4ef6\u53d1\u751f\u65f6\u95f4<br \/>\n  messages: string[],          \/\/ \u5c06\u6d88\u606f\u63a8\u5165\u8fd9\u91cc\u4ee5\u53d1\u9001\u7ed9\u7528\u6237<br \/>\n  context: {<br \/>\n    \/\/ \u547d\u4ee4\u4e8b\u4ef6\uff1a<br \/>\n    sessionEntry?: SessionEntry,<br \/>\n    sessionId?: string,<br \/>\n    sessionFile?: string,<br \/>\n    commandSource?: string,    \/\/ \u4f8b\u5982 &#8216;whatsapp&#8217;\u3001&#8217;telegram&#8217;<br \/>\n    senderId?: string,<br \/>\n    workspaceDir?: string,<br \/>\n    bootstrapFiles?: WorkspaceBootstrapFile[],<br \/>\n    cfg?: OpenClawConfig,<br \/>\n    \/\/ \u6d88\u606f\u4e8b\u4ef6\uff08\u5b8c\u6574\u8be6\u60c5\u89c1\u201c\u6d88\u606f\u4e8b\u4ef6\u201d\u90e8\u5206\uff09\uff1a<br \/>\n    from?: string,             \/\/ message:received<br \/>\n    to?: string,               \/\/ message:sent<br \/>\n    content?: string,<br \/>\n    channelId?: string,<br \/>\n    success?: boolean,         \/\/ message:sent<br \/>\n  }<br \/>\n}<\/p>\n<pre><code>\n## \u4e8b\u4ef6\u7c7b\u578b\n\n### \u547d\u4ee4\u4e8b\u4ef6\n\n\u5728\u53d1\u51fa\u667a\u80fd\u4f53\u547d\u4ee4\u65f6\u89e6\u53d1\uff1a\n\n* **`command`**\uff1a\u6240\u6709\u547d\u4ee4\u4e8b\u4ef6\uff08\u901a\u7528\u76d1\u542c\u5668\uff09\n* **`command:new`**\uff1a\u53d1\u51fa `\/new` \u547d\u4ee4\u65f6\n* **`command:reset`**\uff1a\u53d1\u51fa `\/reset` \u547d\u4ee4\u65f6\n* **`command:stop`**\uff1a\u53d1\u51fa `\/stop` \u547d\u4ee4\u65f6\n\n### \u4f1a\u8bdd\u4e8b\u4ef6\n\n* **`session:compact:before`**\uff1a\u5728\u538b\u7f29\u5f00\u59cb\u603b\u7ed3\u5386\u53f2\u8bb0\u5f55\u4e4b\u524d\n* **`session:compact:after`**\uff1a\u5728\u538b\u7f29\u5b8c\u6210\u5e76\u5e26\u6709\u6458\u8981\u5143\u6570\u636e\u4e4b\u540e\n\n\u5185\u90e8 hook \u8d1f\u8f7d\u4f1a\u5c06\u8fd9\u4e9b\u4e8b\u4ef6\u8868\u793a\u4e3a `type: &quot;session&quot;`\uff0c\u5e76\u5c06 `action` \u8bbe\u4e3a `&quot;compact:before&quot;` \/ `&quot;compact:after&quot;`\uff1b\u76d1\u542c\u5668\u4f7f\u7528\u4e0a\u9762\u7684\u7ec4\u5408\u952e\u8fdb\u884c\u8ba2\u9605\u3002\n\u5177\u4f53\u5904\u7406\u5668\u6ce8\u518c\u4f7f\u7528\u5b57\u9762\u91cf\u952e\u683c\u5f0f `${type}:${action}`\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u4e8b\u4ef6\uff0c\u8bf7\u6ce8\u518c `session:compact:before` \u548c `session:compact:after`\u3002\n\n### \u667a\u80fd\u4f53\u4e8b\u4ef6\n\n* **`agent:bootstrap`**\uff1a\u5728\u5de5\u4f5c\u533a\u5f15\u5bfc\u6587\u4ef6\u88ab\u6ce8\u5165\u4e4b\u524d\uff08hooks \u53ef\u4ee5\u4fee\u6539 `context.bootstrapFiles`\uff09\n\n### Gateway \u7f51\u5173\u4e8b\u4ef6\n\n\u5728 Gateway \u7f51\u5173\u542f\u52a8\u65f6\u89e6\u53d1\uff1a\n\n* **`gateway:startup`**\uff1a\u5728\u6e20\u9053\u542f\u52a8\u4e14 hooks \u5df2\u52a0\u8f7d\u4e4b\u540e\n\n### \u6d88\u606f\u4e8b\u4ef6\n\n\u5728\u6d88\u606f\u88ab\u63a5\u6536\u6216\u53d1\u9001\u65f6\u89e6\u53d1\uff1a\n\n* **`message`**\uff1a\u6240\u6709\u6d88\u606f\u4e8b\u4ef6\uff08\u901a\u7528\u76d1\u542c\u5668\uff09\n* **`message:received`**\uff1a\u5f53\u4ece\u4efb\u610f\u6e20\u9053\u6536\u5230\u5165\u7ad9\u6d88\u606f\u65f6\u3002\u5728\u5904\u7406\u7684\u65e9\u671f\u9636\u6bb5\u89e6\u53d1\uff0c\u6b64\u65f6\u5a92\u4f53\u7406\u89e3\u5c1a\u672a\u5b8c\u6210\u3002\u5bf9\u4e8e\u5c1a\u672a\u5904\u7406\u7684\u5a92\u4f53\u9644\u4ef6\uff0c\u5185\u5bb9\u4e2d\u53ef\u80fd\u5305\u542b\u7c7b\u4f3c `&lt;media:audio&gt;` \u7684\u539f\u59cb\u5360\u4f4d\u7b26\u3002\n* **`message:transcribed`**\uff1a\u5f53\u4e00\u6761\u6d88\u606f\u5df2\u88ab\u5b8c\u5168\u5904\u7406\uff0c\u5305\u62ec\u97f3\u9891\u8f6c\u5199\u548c\u94fe\u63a5\u7406\u89e3\u65f6\u89e6\u53d1\u3002\u6b64\u65f6\uff0c`transcript` \u5305\u542b\u97f3\u9891\u6d88\u606f\u7684\u5b8c\u6574\u8f6c\u5199\u6587\u672c\u3002\u5f53\u4f60\u9700\u8981\u8bbf\u95ee\u5df2\u8f6c\u5199\u7684\u97f3\u9891\u5185\u5bb9\u65f6\uff0c\u8bf7\u4f7f\u7528\u6b64 hook\u3002\n* **`message:preprocessed`**\uff1a\u5728\u6240\u6709\u5a92\u4f53 + \u94fe\u63a5\u7406\u89e3\u5b8c\u6210\u540e\uff0c\u4e3a\u6bcf\u6761\u6d88\u606f\u89e6\u53d1\uff0c\u4f7f hooks \u53ef\u4ee5\u5728\u667a\u80fd\u4f53\u770b\u5230\u6d88\u606f\u4e4b\u524d\u8bbf\u95ee\u5b8c\u5168\u589e\u5f3a\u7684\u6b63\u6587\uff08\u8f6c\u5199\u3001\u56fe\u50cf\u63cf\u8ff0\u3001\u94fe\u63a5\u6458\u8981\uff09\u3002\n* **`message:sent`**\uff1a\u5f53\u51fa\u7ad9\u6d88\u606f\u6210\u529f\u53d1\u9001\u65f6\n\n#### \u6d88\u606f\u4e8b\u4ef6\u4e0a\u4e0b\u6587\n\n\u6d88\u606f\u4e8b\u4ef6\u5305\u542b\u5173\u4e8e\u6d88\u606f\u7684\u4e30\u5bcc\u4e0a\u4e0b\u6587\uff1a\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n\/\/ message:received context\n{\n  from: string,           \/\/ \u53d1\u9001\u8005\u6807\u8bc6\u7b26\uff08\u7535\u8bdd\u53f7\u7801\u3001\u7528\u6237 ID \u7b49\uff09\n  content: string,        \/\/ \u6d88\u606f\u5185\u5bb9\n  timestamp?: number,     \/\/ \u63a5\u6536\u65f6\u7684 Unix \u65f6\u95f4\u6233\n  channelId: string,      \/\/ \u6e20\u9053\uff08\u4f8b\u5982 &quot;whatsapp&quot;\u3001&quot;telegram&quot;\u3001&quot;discord&quot;\uff09\n  accountId?: string,     \/\/ \u591a\u8d26\u53f7\u8bbe\u7f6e\u4e2d\u7684\u63d0\u4f9b\u5546\u8d26\u53f7 ID\n  conversationId?: string, \/\/ \u804a\u5929\/\u4f1a\u8bdd ID\n  messageId?: string,     \/\/ \u63d0\u4f9b\u5546\u8fd4\u56de\u7684\u6d88\u606f ID\n  metadata?: {            \/\/ \u989d\u5916\u7684\u63d0\u4f9b\u5546\u7279\u5b9a\u6570\u636e\n    to?: string,\n    provider?: string,\n    surface?: string,\n    threadId?: string,\n    senderId?: string,\n    senderName?: string,\n    senderUsername?: string,\n    senderE164?: string,\n  }\n}\n\n\/\/ message:sent context\n{\n  to: string,             \/\/ \u63a5\u6536\u8005\u6807\u8bc6\u7b26\n  content: string,        \/\/ \u5df2\u53d1\u9001\u7684\u6d88\u606f\u5185\u5bb9\n  success: boolean,       \/\/ \u53d1\u9001\u662f\u5426\u6210\u529f\n  error?: string,         \/\/ \u5982\u679c\u53d1\u9001\u5931\u8d25\uff0c\u5219\u4e3a\u9519\u8bef\u6d88\u606f\n  channelId: string,      \/\/ \u6e20\u9053\uff08\u4f8b\u5982 &quot;whatsapp&quot;\u3001&quot;telegram&quot;\u3001&quot;discord&quot;\uff09\n  accountId?: string,     \/\/ \u63d0\u4f9b\u5546\u8d26\u53f7 ID\n  conversationId?: string, \/\/ \u804a\u5929\/\u4f1a\u8bdd ID\n  messageId?: string,     \/\/ \u63d0\u4f9b\u5546\u8fd4\u56de\u7684\u6d88\u606f ID\n  isGroup?: boolean,      \/\/ \u6b64\u51fa\u7ad9\u6d88\u606f\u662f\u5426\u5c5e\u4e8e\u7fa4\u7ec4\/\u6e20\u9053\u4e0a\u4e0b\u6587\n  groupId?: string,       \/\/ \u7528\u4e8e\u4e0e message:received \u5173\u8054\u7684\u7fa4\u7ec4\/\u6e20\u9053\u6807\u8bc6\u7b26\n}\n\n\/\/ message:transcribed context\n{\n  body?: string,          \/\/ \u589e\u5f3a\u524d\u7684\u539f\u59cb\u5165\u7ad9\u6b63\u6587\n  bodyForAgent?: string,  \/\/ \u5bf9\u667a\u80fd\u4f53\u53ef\u89c1\u7684\u589e\u5f3a\u6b63\u6587\n  transcript: string,     \/\/ \u97f3\u9891\u8f6c\u5199\u6587\u672c\n  channelId: string,      \/\/ \u6e20\u9053\uff08\u4f8b\u5982 &quot;telegram&quot;\u3001&quot;whatsapp&quot;\uff09\n  conversationId?: string,\n  messageId?: string,\n}\n\n\/\/ message:preprocessed context\n{\n  body?: string,          \/\/ \u539f\u59cb\u5165\u7ad9\u6b63\u6587\n  bodyForAgent?: string,  \/\/ \u5a92\u4f53\/\u94fe\u63a5\u7406\u89e3\u540e\u7684\u6700\u7ec8\u589e\u5f3a\u6b63\u6587\n  transcript?: string,    \/\/ \u5b58\u5728\u97f3\u9891\u65f6\u7684\u8f6c\u5199\u5185\u5bb9\n  channelId: string,      \/\/ \u6e20\u9053\uff08\u4f8b\u5982 &quot;telegram&quot;\u3001&quot;whatsapp&quot;\uff09\n  conversationId?: string,\n  messageId?: string,\n  isGroup?: boolean,\n  groupId?: string,\n}\n<\/code><\/pre>\n<h4>\u793a\u4f8b\uff1a\u6d88\u606f\u8bb0\u5f55\u5668 Hook<\/h4>\n<p>&#8220;`typescript  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nconst isMessageReceivedEvent = (event: { type: string; action: string }) =&gt;<br \/>\n  event.type === &#8220;message&#8221; &amp;&amp; event.action === &#8220;received&#8221;;<br \/>\nconst isMessageSentEvent = (event: { type: string; action: string }) =&gt;<br \/>\n  event.type === &#8220;message&#8221; &amp;&amp; event.action === &#8220;sent&#8221;;<\/p>\n<p>const handler = async (event) =&gt; {<br \/>\n  if (isMessageReceivedEvent(event as { type: string; action: string })) {<br \/>\n    console.log(<code>[message-logger] Received from ${event.context.from}: ${event.context.content}<\/code>);<br \/>\n  } else if (isMessageSentEvent(event as { type: string; action: string })) {<br \/>\n    console.log(<code>[message-logger] Sent to ${event.context.to}: ${event.context.content}<\/code>);<br \/>\n  }<br \/>\n};<\/p>\n<p>export default handler;<\/p>\n<pre><code>\n### \u5de5\u5177\u7ed3\u679c Hooks\uff08\u63d2\u4ef6 API\uff09\n\n\u8fd9\u4e9b hooks \u4e0d\u662f\u4e8b\u4ef6\u6d41\u76d1\u542c\u5668\uff1b\u5b83\u4eec\u5141\u8bb8\u63d2\u4ef6\u5728 OpenClaw \u6301\u4e45\u5316\u5de5\u5177\u7ed3\u679c\u4e4b\u524d\u540c\u6b65\u8c03\u6574\u5de5\u5177\u7ed3\u679c\u3002\n\n* **`tool_result_persist`**\uff1a\u5728\u5de5\u5177\u7ed3\u679c\u5199\u5165\u4f1a\u8bdd\u8f6c\u5f55\u4e4b\u524d\u5bf9\u5176\u8fdb\u884c\u8f6c\u6362\u3002\u5fc5\u987b\u662f\u540c\u6b65\u7684\uff1b\u8fd4\u56de\u66f4\u65b0\u540e\u7684\u5de5\u5177\u7ed3\u679c\u8d1f\u8f7d\uff0c\u6216\u8fd4\u56de `undefined` \u4ee5\u4fdd\u6301\u539f\u6837\u3002\u8bf7\u53c2\u9605 [Agent Loop](\/concepts\/agent-loop)\u3002\n\n### \u63d2\u4ef6 Hook \u4e8b\u4ef6\n\n\u901a\u8fc7\u63d2\u4ef6 hook \u8fd0\u884c\u5668\u516c\u5f00\u7684\u538b\u7f29\u751f\u547d\u5468\u671f hooks\uff1a\n\n* **`before_compaction`**\uff1a\u5728\u538b\u7f29\u524d\u8fd0\u884c\uff0c\u5e76\u5e26\u6709\u8ba1\u6570\/token \u5143\u6570\u636e\n* **`after_compaction`**\uff1a\u5728\u538b\u7f29\u540e\u8fd0\u884c\uff0c\u5e76\u5e26\u6709\u538b\u7f29\u6458\u8981\u5143\u6570\u636e\n\n### \u672a\u6765\u4e8b\u4ef6\n\n\u8ba1\u5212\u4e2d\u7684\u4e8b\u4ef6\u7c7b\u578b\uff1a\n\n* **`session:start`**\uff1a\u5f53\u65b0\u4f1a\u8bdd\u5f00\u59cb\u65f6\n* **`session:end`**\uff1a\u5f53\u4f1a\u8bdd\u7ed3\u675f\u65f6\n* **`agent:error`**\uff1a\u5f53\u667a\u80fd\u4f53\u9047\u5230\u9519\u8bef\u65f6\n\n## \u521b\u5efa\u81ea\u5b9a\u4e49 Hooks\n\n### 1. \u9009\u62e9\u4f4d\u7f6e\n\n* **\u5de5\u4f5c\u533a hooks**\uff08`&lt;workspace&gt;\/hooks\/`\uff09\uff1a\u6bcf\u4e2a\u667a\u80fd\u4f53\u5355\u72ec\u914d\u7f6e\uff0c\u4f18\u5148\u7ea7\u6700\u9ad8\n* **\u6258\u7ba1 hooks**\uff08`~\/.openclaw\/hooks\/`\uff09\uff1a\u8de8\u5de5\u4f5c\u533a\u5171\u4eab\n\n### 2. \u521b\u5efa\u76ee\u5f55\u7ed3\u6784\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nmkdir -p ~\/.openclaw\/hooks\/my-hook\ncd ~\/.openclaw\/hooks\/my-hook\n<\/code><\/pre>\n<h3>3. \u521b\u5efa HOOK.md<\/h3>\n<h2>&#8220;`markdown  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/h2>\n<p>name: my-hook<br \/>\ndescription: &#8220;\u6267\u884c\u67d0\u4e9b\u6709\u7528\u7684\u4e8b\u60c5&#8221;<br \/>\nmetadata: { &#8220;openclaw&#8221;: { &#8220;emoji&#8221;: &#8220;\ud83c\udfaf&#8221;, &#8220;events&#8221;: [&#8220;command:new&#8221;] } }<\/p>\n<hr \/>\n<h1>My Custom Hook<\/h1>\n<p>\u5f53\u4f60\u53d1\u51fa <code>\/new<\/code> \u65f6\uff0c\u6b64 hook \u4f1a\u6267\u884c\u4e00\u4e9b\u6709\u7528\u7684\u4e8b\u60c5\u3002<\/p>\n<pre><code>\n### 4. \u521b\u5efa handler.ts\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nconst handler = async (event) =&gt; {\n  if (event.type !== &quot;command&quot; || event.action !== &quot;new&quot;) {\n    return;\n  }\n\n  console.log(&quot;[my-hook] Running!&quot;);\n  \/\/ \u4f60\u7684\u903b\u8f91\u5199\u5728\u8fd9\u91cc\n};\n\nexport default handler;\n<\/code><\/pre>\n<h3>5. \u542f\u7528\u5e76\u6d4b\u8bd5<\/h3>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<h1>\u9a8c\u8bc1 hook \u5df2\u88ab\u53d1\u73b0<\/h1>\n<p>openclaw hooks list<\/p>\n<h1>\u542f\u7528\u5b83<\/h1>\n<p>openclaw hooks enable my-hook<\/p>\n<h1>\u91cd\u542f\u4f60\u7684 Gateway \u7f51\u5173\u8fdb\u7a0b\uff08macOS \u4e0a\u91cd\u542f\u83dc\u5355\u680f\u5e94\u7528\uff0c\u6216\u91cd\u542f\u4f60\u7684\u5f00\u53d1\u8fdb\u7a0b\uff09<\/h1>\n<h1>\u89e6\u53d1\u4e8b\u4ef6<\/h1>\n<h1>\u901a\u8fc7\u4f60\u7684\u6d88\u606f\u6e20\u9053\u53d1\u9001 \/new<\/h1>\n<pre><code>\n## \u914d\u7f6e\n\n### \u65b0\u914d\u7f6e\u683c\u5f0f\uff08\u63a8\u8350\uff09\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;hooks&quot;: {\n    &quot;internal&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;entries&quot;: {\n        &quot;session-memory&quot;: { &quot;enabled&quot;: true },\n        &quot;command-logger&quot;: { &quot;enabled&quot;: false }\n      }\n    }\n  }\n}\n<\/code><\/pre>\n<h3>\u6bcf\u4e2a Hook \u7684\u914d\u7f6e<\/h3>\n<p>Hooks \u53ef\u4ee5\u5177\u6709\u81ea\u5b9a\u4e49\u914d\u7f6e\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  &#8220;hooks&#8221;: {<br \/>\n    &#8220;internal&#8221;: {<br \/>\n      &#8220;enabled&#8221;: true,<br \/>\n      &#8220;entries&#8221;: {<br \/>\n        &#8220;my-hook&#8221;: {<br \/>\n          &#8220;enabled&#8221;: true,<br \/>\n          &#8220;env&#8221;: {<br \/>\n            &#8220;MY_CUSTOM_VAR&#8221;: &#8220;value&#8221;<br \/>\n          }<br \/>\n        }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<pre><code>\n### \u989d\u5916\u76ee\u5f55\n\n\u4ece\u989d\u5916\u76ee\u5f55\u52a0\u8f7d hooks\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;hooks&quot;: {\n    &quot;internal&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;load&quot;: {\n        &quot;extraDirs&quot;: [&quot;\/path\/to\/more\/hooks&quot;]\n      }\n    }\n  }\n}\n<\/code><\/pre>\n<h3>\u65e7\u7248\u914d\u7f6e\u683c\u5f0f\uff08\u4ecd\u53d7\u652f\u6301\uff09<\/h3>\n<p>\u65e7\u914d\u7f6e\u683c\u5f0f\u4ecd\u53ef\u7528\u4e8e\u5411\u540e\u517c\u5bb9\uff1a<\/p>\n<p>&#8220;`json  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\n{<br \/>\n  &#8220;hooks&#8221;: {<br \/>\n    &#8220;internal&#8221;: {<br \/>\n      &#8220;enabled&#8221;: true,<br \/>\n      &#8220;handlers&#8221;: [<br \/>\n        {<br \/>\n          &#8220;event&#8221;: &#8220;command:new&#8221;,<br \/>\n          &#8220;module&#8221;: &#8220;.\/hooks\/handlers\/my-handler.ts&#8221;,<br \/>\n          &#8220;export&#8221;: &#8220;default&#8221;<br \/>\n        }<br \/>\n      ]<br \/>\n    }<br \/>\n  }<br \/>\n}<\/p>\n<pre><code>\n\u6ce8\u610f\uff1a`module` \u5fc5\u987b\u662f\u76f8\u5bf9\u4e8e\u5de5\u4f5c\u533a\u7684\u8def\u5f84\u3002\u7edd\u5bf9\u8def\u5f84\u548c\u8d85\u51fa\u5de5\u4f5c\u533a\u8303\u56f4\u7684\u904d\u5386\u8def\u5f84\u4f1a\u88ab\u62d2\u7edd\u3002\n\n**\u8fc1\u79fb**\uff1a\u5bf9\u4e8e\u65b0\u7684 hooks\uff0c\u8bf7\u4f7f\u7528\u57fa\u4e8e\u53d1\u73b0\u7684\u65b0\u7cfb\u7edf\u3002\u65e7\u7248 handlers \u4f1a\u5728\u57fa\u4e8e\u76ee\u5f55\u7684 hooks \u4e4b\u540e\u52a0\u8f7d\u3002\n\n## CLI \u547d\u4ee4\n\n### \u5217\u51fa Hooks\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n# \u5217\u51fa\u6240\u6709 hooks\nopenclaw hooks list\n\n# \u4ec5\u663e\u793a\u7b26\u5408\u6761\u4ef6\u7684 hooks\nopenclaw hooks list --eligible\n\n# \u8be6\u7ec6\u8f93\u51fa\uff08\u663e\u793a\u7f3a\u5931\u7684\u8981\u6c42\uff09\nopenclaw hooks list --verbose\n\n# JSON \u8f93\u51fa\nopenclaw hooks list --json\n<\/code><\/pre>\n<h3>Hook \u4fe1\u606f<\/h3>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<h1>\u663e\u793a\u67d0\u4e2a hook \u7684\u8be6\u7ec6\u4fe1\u606f<\/h1>\n<p>openclaw hooks info session-memory<\/p>\n<h1>JSON \u8f93\u51fa<\/h1>\n<p>openclaw hooks info session-memory &#8211;json<\/p>\n<pre><code>\n### \u68c0\u67e5\u8d44\u683c\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n# \u663e\u793a\u8d44\u683c\u6458\u8981\nopenclaw hooks check\n\n# JSON \u8f93\u51fa\nopenclaw hooks check --json\n<\/code><\/pre>\n<h3>\u542f\u7528\/\u7981\u7528<\/h3>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<h1>\u542f\u7528\u4e00\u4e2a hook<\/h1>\n<p>openclaw hooks enable session-memory<\/p>\n<h1>\u7981\u7528\u4e00\u4e2a hook<\/h1>\n<p>openclaw hooks disable command-logger<\/p>\n<pre><code>\n## \u5185\u7f6e hook \u53c2\u8003\n\n### session-memory\n\n\u5f53\u4f60\u53d1\u51fa `\/new` \u65f6\uff0c\u5c06\u4f1a\u8bdd\u4e0a\u4e0b\u6587\u4fdd\u5b58\u5230 memory\u3002\n\n**\u4e8b\u4ef6**\uff1a`command:new`\n\n**\u8981\u6c42**\uff1a\u5fc5\u987b\u914d\u7f6e `workspace.dir`\n\n**\u8f93\u51fa**\uff1a`&lt;workspace&gt;\/memory\/YYYY-MM-DD-slug.md`\uff08\u9ed8\u8ba4\u662f `~\/.openclaw\/workspace`\uff09\n\n**\u5b83\u7684\u4f5c\u7528**\uff1a\n\n1. \u4f7f\u7528\u91cd\u7f6e\u524d\u7684\u4f1a\u8bdd\u6761\u76ee\u5b9a\u4f4d\u6b63\u786e\u7684\u8f6c\u5f55\n2. \u63d0\u53d6\u6700\u8fd1 15 \u884c\u5bf9\u8bdd\n3. \u4f7f\u7528 LLM \u751f\u6210\u63cf\u8ff0\u6027\u7684\u6587\u4ef6\u540d slug\n4. \u5c06\u4f1a\u8bdd\u5143\u6570\u636e\u4fdd\u5b58\u5230\u5e26\u65e5\u671f\u7684 memory \u6587\u4ef6\u4e2d\n\n**\u793a\u4f8b\u8f93\u51fa**\uff1a\n\n```markdown  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n# Session: 2026-01-16 14:30:00 UTC\n\n- **Session Key**: agent:main:main\n- **Session ID**: abc123def456\n- **Source**: telegram\n<\/code><\/pre>\n<p><strong>\u6587\u4ef6\u540d\u793a\u4f8b<\/strong>\uff1a<\/p>\n<ul>\n<li><code>2026-01-16-vendor-pitch.md<\/code><\/li>\n<li><code>2026-01-16-api-design.md<\/code><\/li>\n<li><code>2026-01-16-1430.md<\/code>\uff08\u5982\u679c slug \u751f\u6210\u5931\u8d25\uff0c\u5219\u56de\u9000\u4e3a\u65f6\u95f4\u6233\uff09<\/li>\n<\/ul>\n<p><strong>\u542f\u7528<\/strong>\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks enable session-memory<\/p>\n<pre><code>\n### bootstrap-extra-files\n\n\u5728 `agent:bootstrap` \u671f\u95f4\u6ce8\u5165\u989d\u5916\u7684\u5f15\u5bfc\u6587\u4ef6\uff08\u4f8b\u5982 monorepo \u672c\u5730\u7684 `AGENTS.md` \/ `TOOLS.md`\uff09\u3002\n\n**\u4e8b\u4ef6**\uff1a`agent:bootstrap`\n\n**\u8981\u6c42**\uff1a\u5fc5\u987b\u914d\u7f6e `workspace.dir`\n\n**\u8f93\u51fa**\uff1a\u4e0d\u5199\u5165\u6587\u4ef6\uff1b\u4ec5\u5728\u5185\u5b58\u4e2d\u4fee\u6539\u5f15\u5bfc\u4e0a\u4e0b\u6587\u3002\n\n**\u914d\u7f6e**\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;hooks&quot;: {\n    &quot;internal&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;entries&quot;: {\n        &quot;bootstrap-extra-files&quot;: {\n          &quot;enabled&quot;: true,\n          &quot;paths&quot;: [&quot;packages\/*\/AGENTS.md&quot;, &quot;packages\/*\/TOOLS.md&quot;]\n        }\n      }\n    }\n  }\n}\n<\/code><\/pre>\n<p><strong>\u8bf4\u660e<\/strong>\uff1a<\/p>\n<ul>\n<li>\u8def\u5f84\u76f8\u5bf9\u4e8e\u5de5\u4f5c\u533a\u89e3\u6790\u3002<\/li>\n<li>\u6587\u4ef6\u5fc5\u987b\u4fdd\u6301\u5728\u5de5\u4f5c\u533a\u5185\u90e8\uff08\u901a\u8fc7 realpath \u68c0\u67e5\uff09\u3002<\/li>\n<li>\u4ec5\u52a0\u8f7d\u5df2\u8bc6\u522b\u7684\u5f15\u5bfc\u57fa\u7840\u6587\u4ef6\u540d\u3002<\/li>\n<li>\u4f1a\u4fdd\u7559\u5b50\u667a\u80fd\u4f53\u5141\u8bb8\u5217\u8868\uff08\u4ec5 <code>AGENTS.md<\/code> \u548c <code>TOOLS.md<\/code>\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u542f\u7528<\/strong>\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks enable bootstrap-extra-files<\/p>\n<pre><code>\n### command-logger\n\n\u5c06\u6240\u6709\u547d\u4ee4\u4e8b\u4ef6\u8bb0\u5f55\u5230\u96c6\u4e2d\u5f0f\u5ba1\u8ba1\u6587\u4ef6\u3002\n\n**\u4e8b\u4ef6**\uff1a`command`\n\n**\u8981\u6c42**\uff1a\u65e0\n\n**\u8f93\u51fa**\uff1a`~\/.openclaw\/logs\/commands.log`\n\n**\u5b83\u7684\u4f5c\u7528**\uff1a\n\n1. \u6355\u83b7\u4e8b\u4ef6\u8be6\u60c5\uff08\u547d\u4ee4\u64cd\u4f5c\u3001\u65f6\u95f4\u6233\u3001\u4f1a\u8bdd\u952e\u3001\u53d1\u9001\u8005 ID\u3001\u6765\u6e90\uff09\n2. \u4ee5 JSONL \u683c\u5f0f\u9644\u52a0\u5230\u65e5\u5fd7\u6587\u4ef6\n3. \u5728\u540e\u53f0\u9759\u9ed8\u8fd0\u884c\n\n**\u793a\u4f8b\u65e5\u5fd7\u6761\u76ee**\uff1a\n\n```jsonl  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{&quot;timestamp&quot;:&quot;2026-01-16T14:30:00.000Z&quot;,&quot;action&quot;:&quot;new&quot;,&quot;sessionKey&quot;:&quot;agent:main:main&quot;,&quot;senderId&quot;:&quot;+1234567890&quot;,&quot;source&quot;:&quot;telegram&quot;}\n{&quot;timestamp&quot;:&quot;2026-01-16T15:45:22.000Z&quot;,&quot;action&quot;:&quot;stop&quot;,&quot;sessionKey&quot;:&quot;agent:main:main&quot;,&quot;senderId&quot;:&quot;user@example.com&quot;,&quot;source&quot;:&quot;whatsapp&quot;}\n<\/code><\/pre>\n<p><strong>\u67e5\u770b\u65e5\u5fd7<\/strong>\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<h1>\u67e5\u770b\u6700\u8fd1\u7684\u547d\u4ee4<\/h1>\n<p>tail -n 20 ~\/.openclaw\/logs\/commands.log<\/p>\n<h1>\u4f7f\u7528 jq \u7f8e\u5316\u8f93\u51fa<\/h1>\n<p>cat ~\/.openclaw\/logs\/commands.log | jq .<\/p>\n<h1>\u6309\u64cd\u4f5c\u7b5b\u9009<\/h1>\n<p>grep &#8216;&#8221;action&#8221;:&#8221;new&#8221;&#8216; ~\/.openclaw\/logs\/commands.log | jq .<\/p>\n<pre><code>\n**\u542f\u7528**\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nopenclaw hooks enable command-logger\n<\/code><\/pre>\n<h3>boot-md<\/h3>\n<p>\u5f53 Gateway \u7f51\u5173\u542f\u52a8\u65f6\uff08\u6e20\u9053\u542f\u52a8\u4e4b\u540e\uff09\u8fd0\u884c <code>BOOT.md<\/code>\u3002<br \/>\n\u5fc5\u987b\u542f\u7528\u5185\u90e8 hooks\uff0c\u6b64\u529f\u80fd\u624d\u4f1a\u8fd0\u884c\u3002<\/p>\n<p><strong>\u4e8b\u4ef6<\/strong>\uff1a<code>gateway:startup<\/code><\/p>\n<p><strong>\u8981\u6c42<\/strong>\uff1a\u5fc5\u987b\u914d\u7f6e <code>workspace.dir<\/code><\/p>\n<p><strong>\u5b83\u7684\u4f5c\u7528<\/strong>\uff1a<\/p>\n<ol>\n<li>\u4ece\u4f60\u7684\u5de5\u4f5c\u533a\u8bfb\u53d6 <code>BOOT.md<\/code><\/li>\n<li>\u901a\u8fc7\u667a\u80fd\u4f53\u8fd0\u884c\u5668\u6267\u884c\u5176\u4e2d\u7684\u6307\u4ee4<\/li>\n<li>\u901a\u8fc7\u6d88\u606f\u5de5\u5177\u53d1\u9001\u4efb\u4f55\u8bf7\u6c42\u7684\u51fa\u7ad9\u6d88\u606f<\/li>\n<\/ol>\n<p><strong>\u542f\u7528<\/strong>\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks enable boot-md<\/p>\n<pre><code>\n## \u6700\u4f73\u5b9e\u8df5\n\n### \u4fdd\u6301\u5904\u7406\u5668\u5feb\u901f\n\nHooks \u5728\u547d\u4ee4\u5904\u7406\u671f\u95f4\u8fd0\u884c\u3002\u8bf7\u4fdd\u6301\u5176\u8f7b\u91cf\uff1a\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n\/\/ \u2713 \u597d - \u5f02\u6b65\u5de5\u4f5c\uff0c\u7acb\u5373\u8fd4\u56de\nconst handler: HookHandler = async (event) =&gt; {\n  void processInBackground(event); \/\/ \u89e6\u53d1\u540e\u4e0d\u7b49\u5f85\n};\n\n\/\/ \u2717 \u5dee - \u963b\u585e\u547d\u4ee4\u5904\u7406\nconst handler: HookHandler = async (event) =&gt; {\n  await slowDatabaseQuery(event);\n  await evenSlowerAPICall(event);\n};\n<\/code><\/pre>\n<h3>\u4f18\u96c5\u5730\u5904\u7406\u9519\u8bef<\/h3>\n<p>\u59cb\u7ec8\u5305\u88c5\u9ad8\u98ce\u9669\u64cd\u4f5c\uff1a<\/p>\n<p>&#8220;`typescript  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nconst handler: HookHandler = async (event) =&gt; {<br \/>\n  try {<br \/>\n    await riskyOperation(event);<br \/>\n  } catch (err) {<br \/>\n    console.error(&#8220;[my-handler] Failed:&#8221;, err instanceof Error ? err.message : String(err));<br \/>\n    \/\/ \u4e0d\u8981\u629b\u51fa\u9519\u8bef &#8211; \u8ba9\u5176\u4ed6\u5904\u7406\u5668\u7ee7\u7eed\u8fd0\u884c<br \/>\n  }<br \/>\n};<\/p>\n<pre><code>\n### \u5c3d\u65e9\u8fc7\u6ee4\u4e8b\u4ef6\n\n\u5982\u679c\u4e8b\u4ef6\u4e0d\u76f8\u5173\uff0c\u8bf7\u5c3d\u65e9\u8fd4\u56de\uff1a\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nconst handler: HookHandler = async (event) =&gt; {\n  \/\/ \u4ec5\u5904\u7406 'new' \u547d\u4ee4\n  if (event.type !== &quot;command&quot; || event.action !== &quot;new&quot;) {\n    return;\n  }\n\n  \/\/ \u4f60\u7684\u903b\u8f91\u5199\u5728\u8fd9\u91cc\n};\n<\/code><\/pre>\n<h3>\u4f7f\u7528\u5177\u4f53\u4e8b\u4ef6\u952e<\/h3>\n<p>\u5982\u679c\u53ef\u80fd\uff0c\u8bf7\u5728\u5143\u6570\u636e\u4e2d\u6307\u5b9a\u7cbe\u786e\u4e8b\u4ef6\uff1a<\/p>\n<p>&#8220;`yaml  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nmetadata: { &#8220;openclaw&#8221;: { &#8220;events&#8221;: [&#8220;command:new&#8221;] } } # \u7cbe\u786e<\/p>\n<pre><code>\n\u800c\u4e0d\u662f\uff1a\n\n```yaml  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nmetadata: { &quot;openclaw&quot;: { &quot;events&quot;: [&quot;command&quot;] } } # \u901a\u7528 - \u5f00\u9500\u66f4\u5927\n<\/code><\/pre>\n<h2>\u8c03\u8bd5<\/h2>\n<h3>\u542f\u7528 Hook \u65e5\u5fd7<\/h3>\n<p>Gateway \u7f51\u5173\u4f1a\u5728\u542f\u52a8\u65f6\u8bb0\u5f55 hook \u52a0\u8f7d\u60c5\u51b5\uff1a<\/p>\n<pre><code>Registered hook: session-memory -&gt; command:new\nRegistered hook: bootstrap-extra-files -&gt; agent:bootstrap\nRegistered hook: command-logger -&gt; command\nRegistered hook: boot-md -&gt; gateway:startup\n<\/code><\/pre>\n<h3>\u68c0\u67e5\u53d1\u73b0\u60c5\u51b5<\/h3>\n<p>\u5217\u51fa\u6240\u6709\u5df2\u53d1\u73b0\u7684 hooks\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks list &#8211;verbose<\/p>\n<pre><code>\n### \u68c0\u67e5\u6ce8\u518c\u60c5\u51b5\n\n\u5728\u4f60\u7684\u5904\u7406\u5668\u4e2d\uff0c\u8bb0\u5f55\u5b83\u4f55\u65f6\u88ab\u8c03\u7528\uff1a\n\n```typescript  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nconst handler: HookHandler = async (event) =&gt; {\n  console.log(&quot;[my-handler] Triggered:&quot;, event.type, event.action);\n  \/\/ \u4f60\u7684\u903b\u8f91\n};\n<\/code><\/pre>\n<h3>\u9a8c\u8bc1\u8d44\u683c<\/h3>\n<p>\u68c0\u67e5\u67d0\u4e2a hook \u4e3a\u4ec0\u4e48\u4e0d\u7b26\u5408\u6761\u4ef6\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nopenclaw hooks info my-hook<\/p>\n<pre><code>\n\u67e5\u770b\u8f93\u51fa\u4e2d\u7f3a\u5931\u7684\u8981\u6c42\u3002\n\n## \u6d4b\u8bd5\n\n### Gateway \u7f51\u5173\u65e5\u5fd7\n\n\u76d1\u63a7 Gateway \u7f51\u5173\u65e5\u5fd7\u4ee5\u67e5\u770b hook \u6267\u884c\u60c5\u51b5\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n# macOS\n.\/scripts\/clawlog.sh -f\n\n# \u5176\u4ed6\u5e73\u53f0\ntail -f ~\/.openclaw\/gateway.log\n<\/code><\/pre>\n<h3>\u76f4\u63a5\u6d4b\u8bd5 Hooks<\/h3>\n<p>\u5355\u72ec\u6d4b\u8bd5\u4f60\u7684 handlers\uff1a<\/p>\n<p>&#8220;`typescript  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<br \/>\nimport { test } from &#8220;vitest&#8221;;<br \/>\nimport myHandler from &#8220;.\/hooks\/my-hook\/handler.js&#8221;;<\/p>\n<p>test(&#8220;my handler works&#8221;, async () =&gt; {<br \/>\n  const event = {<br \/>\n    type: &#8220;command&#8221;,<br \/>\n    action: &#8220;new&#8221;,<br \/>\n    sessionKey: &#8220;test-session&#8221;,<br \/>\n    timestamp: new Date(),<br \/>\n    messages: [],<br \/>\n    context: { foo: &#8220;bar&#8221; },<br \/>\n  };<\/p>\n<p>await myHandler(event);<\/p>\n<p>\/\/ \u65ad\u8a00\u526f\u4f5c\u7528<br \/>\n});<\/p>\n<pre><code>\n## \u67b6\u6784\n\n### \u6838\u5fc3\u7ec4\u4ef6\n\n* **`src\/hooks\/types.ts`**\uff1a\u7c7b\u578b\u5b9a\u4e49\n* **`src\/hooks\/workspace.ts`**\uff1a\u76ee\u5f55\u626b\u63cf\u4e0e\u52a0\u8f7d\n* **`src\/hooks\/frontmatter.ts`**\uff1a`HOOK.md` \u5143\u6570\u636e\u89e3\u6790\n* **`src\/hooks\/config.ts`**\uff1a\u8d44\u683c\u68c0\u67e5\n* **`src\/hooks\/hooks-status.ts`**\uff1a\u72b6\u6001\u62a5\u544a\n* **`src\/hooks\/loader.ts`**\uff1a\u52a8\u6001\u6a21\u5757\u52a0\u8f7d\u5668\n* **`src\/cli\/hooks-cli.ts`**\uff1aCLI \u547d\u4ee4\n* **`src\/gateway\/server-startup.ts`**\uff1a\u5728 Gateway \u7f51\u5173\u542f\u52a8\u65f6\u52a0\u8f7d hooks\n* **`src\/auto-reply\/reply\/commands-core.ts`**\uff1a\u89e6\u53d1\u547d\u4ee4\u4e8b\u4ef6\n\n### \u53d1\u73b0\u6d41\u7a0b\n\n<\/code><\/pre>\n<p>Gateway \u7f51\u5173\u542f\u52a8<br \/>\n    \u2193<br \/>\n\u626b\u63cf\u76ee\u5f55\uff08\u5de5\u4f5c\u533a \u2192 \u6258\u7ba1 \u2192 \u5185\u7f6e\uff09<br \/>\n    \u2193<br \/>\n\u89e3\u6790 HOOK.md \u6587\u4ef6<br \/>\n    \u2193<br \/>\n\u68c0\u67e5\u8d44\u683c\uff08bins\u3001env\u3001config\u3001os\uff09<br \/>\n    \u2193<br \/>\n\u4ece\u7b26\u5408\u6761\u4ef6\u7684 hooks \u52a0\u8f7d handlers<br \/>\n    \u2193<br \/>\n\u4e3a\u4e8b\u4ef6\u6ce8\u518c handlers<\/p>\n<pre><code>\n### \u4e8b\u4ef6\u6d41\u7a0b\n\n<\/code><\/pre>\n<p>\u7528\u6237\u53d1\u9001 \/new<br \/>\n    \u2193<br \/>\n\u547d\u4ee4\u6821\u9a8c<br \/>\n    \u2193<br \/>\n\u521b\u5efa hook \u4e8b\u4ef6<br \/>\n    \u2193<br \/>\n\u89e6\u53d1 hook\uff08\u6240\u6709\u5df2\u6ce8\u518c\u7684 handlers\uff09<br \/>\n    \u2193<br \/>\n\u547d\u4ee4\u5904\u7406\u7ee7\u7eed<br \/>\n    \u2193<br \/>\n\u4f1a\u8bdd\u91cd\u7f6e<\/p>\n<pre><code>\n## \u6545\u969c\u6392\u9664\n\n### Hook \u672a\u88ab\u53d1\u73b0\n\n1. \u68c0\u67e5\u76ee\u5f55\u7ed3\u6784\uff1a\n\n   ```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n   ls -la ~\/.openclaw\/hooks\/my-hook\/\n   # \u5e94\u663e\u793a\uff1aHOOK.md, handler.ts\n   ```\n\n2. \u9a8c\u8bc1 HOOK.md \u683c\u5f0f\uff1a\n\n   ```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n   cat ~\/.openclaw\/hooks\/my-hook\/HOOK.md\n   # \u5e94\u5305\u542b\u5e26\u6709 name \u548c metadata \u7684 YAML frontmatter\n   ```\n\n3. \u5217\u51fa\u6240\u6709\u5df2\u53d1\u73b0\u7684 hooks\uff1a\n\n   ```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n   openclaw hooks list\n   ```\n\n### Hook \u4e0d\u7b26\u5408\u6761\u4ef6\n\n\u68c0\u67e5\u8981\u6c42\uff1a\n\n```bash  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\nopenclaw hooks info my-hook\n<\/code><\/pre>\n<p>\u67e5\u770b\u662f\u5426\u7f3a\u5c11\uff1a<\/p>\n<ul>\n<li>\u4e8c\u8fdb\u5236\u6587\u4ef6\uff08\u68c0\u67e5 PATH\uff09<\/li>\n<li>\u73af\u5883\u53d8\u91cf<\/li>\n<li>\u914d\u7f6e\u503c<\/li>\n<li>OS \u517c\u5bb9\u6027<\/li>\n<\/ul>\n<h3>Hook \u672a\u6267\u884c<\/h3>\n<ol>\n<li>\u9a8c\u8bc1 hook \u5df2\u542f\u7528\uff1a<\/li>\n<\/ol>\n<p><code>bash  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n   openclaw hooks list<br \/>\n   # \u5e94\u5728\u5df2\u542f\u7528\u7684 hooks \u65c1\u663e\u793a \u2713<\/code><\/p>\n<ol start=\"2\">\n<li>\n<p>\u91cd\u542f\u4f60\u7684 Gateway \u7f51\u5173\u8fdb\u7a0b\u4ee5\u91cd\u65b0\u52a0\u8f7d hooks\u3002<\/p>\n<\/li>\n<li>\n<p>\u68c0\u67e5 Gateway \u7f51\u5173\u65e5\u5fd7\u4e2d\u7684\u9519\u8bef\uff1a<\/p>\n<\/li>\n<\/ol>\n<p><code>bash  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n   .\/scripts\/clawlog.sh | grep hook<\/code><\/p>\n<h3>\u5904\u7406\u5668\u9519\u8bef<\/h3>\n<p>\u68c0\u67e5 TypeScript\/import \u9519\u8bef\uff1a<\/p>\n<p>&#8220;`bash  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<h1>\u76f4\u63a5\u6d4b\u8bd5\u5bfc\u5165<\/h1>\n<p>node -e &#8220;import(&#8216;.\/path\/to\/handler.ts&#8217;).then(console.log)&#8221;<\/p>\n<pre><code>\n## \u8fc1\u79fb\u6307\u5357\n\n### \u4ece\u65e7\u7248\u914d\u7f6e\u8fc1\u79fb\u5230\u53d1\u73b0\u673a\u5236\n\n**\u8fc1\u79fb\u524d**\uff1a\n\n```json  theme={&quot;theme&quot;:{&quot;light&quot;:&quot;min-light&quot;,&quot;dark&quot;:&quot;min-dark&quot;}}\n{\n  &quot;hooks&quot;: {\n    &quot;internal&quot;: {\n      &quot;enabled&quot;: true,\n      &quot;handlers&quot;: [\n        {\n          &quot;event&quot;: &quot;command:new&quot;,\n          &quot;module&quot;: &quot;.\/hooks\/handlers\/my-handler.ts&quot;\n        }\n      ]\n    }\n  }\n}\n<\/code><\/pre>\n<p><strong>\u8fc1\u79fb\u540e<\/strong>\uff1a<\/p>\n<ol>\n<li>\u521b\u5efa hook \u76ee\u5f55\uff1a<\/li>\n<\/ol>\n<p><code>bash  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n   mkdir -p ~\/.openclaw\/hooks\/my-hook<br \/>\n   mv .\/hooks\/handlers\/my-handler.ts ~\/.openclaw\/hooks\/my-hook\/handler.ts<\/code><\/p>\n<ol start=\"2\">\n<li>\u521b\u5efa HOOK.md\uff1a<\/li>\n<\/ol>\n<p>&#8220;`markdown  theme={&#8220;theme&#8221;:{&#8220;light&#8221;:&#8221;min-light&#8221;,&#8221;dark&#8221;:&#8221;min-dark&#8221;}}<\/p>\n<hr \/>\n<p>name: my-hook<br \/>\n   description: &#8220;\u6211\u7684\u81ea\u5b9a\u4e49 hook&#8221;<br \/>\n   metadata: { &#8220;openclaw&#8221;: { &#8220;emoji&#8221;: &#8220;\ud83c\udfaf&#8221;, &#8220;events&#8221;: [&#8220;command:new&#8221;] } }<\/p>\n<hr \/>\n<p># My Hook<\/p>\n<p>\u6267\u884c\u67d0\u4e9b\u6709\u7528\u7684\u4e8b\u60c5\u3002<br \/>\n   &#8220;`<\/p>\n<ol start=\"3\">\n<li>\u66f4\u65b0\u914d\u7f6e\uff1a<\/li>\n<\/ol>\n<p><code>json  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n   {<br \/>\n     \"hooks\": {<br \/>\n       \"internal\": {<br \/>\n         \"enabled\": true,<br \/>\n         \"entries\": {<br \/>\n           \"my-hook\": { \"enabled\": true }<br \/>\n         }<br \/>\n       }<br \/>\n     }<br \/>\n   }<\/code><\/p>\n<ol start=\"4\">\n<li>\u9a8c\u8bc1\u5e76\u91cd\u542f\u4f60\u7684 Gateway \u7f51\u5173\u8fdb\u7a0b\uff1a<\/li>\n<\/ol>\n<p><code>bash  theme={\"theme\":{\"light\":\"min-light\",\"dark\":\"min-dark\"}}<br \/>\n   openclaw hooks list<br \/>\n   # \u5e94\u663e\u793a\uff1a\ud83c\udfaf my-hook \u2713<\/code><\/p>\n<p><strong>\u8fc1\u79fb\u7684\u597d\u5904<\/strong>\uff1a<\/p>\n<ul>\n<li>\u81ea\u52a8\u53d1\u73b0<\/li>\n<li>CLI \u7ba1\u7406<\/li>\n<li>\u8d44\u683c\u68c0\u67e5<\/li>\n<li>\u66f4\u597d\u7684\u6587\u6863<\/li>\n<li>\u4e00\u81f4\u7684\u7ed3\u6784<\/li>\n<\/ul>\n<h2>\u53e6\u8bf7\u53c2\u9605<\/h2>\n<ul>\n<li><a href=\"\/cli\/hooks\">CLI Reference: hooks<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/openclaw\/openclaw\/tree\/main\/src\/hooks\/bundled\">Bundled Hooks README<\/a><\/li>\n<li><a href=\"\/automation\/webhook\">Webhook Hooks<\/a><\/li>\n<li><a href=\"\/gateway\/configuration#hooks\">Configuration<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Hooks Hooks \u63d0\u4f9b\u4e86\u4e00\u4e2a\u53ef\u6269\u5c55\u7684\u4e8b\u4ef6\u9a71\u52a8\u7cfb\u7edf\uff0c\u7528\u4e8e\u5728\u54cd\u5e94\u667a\u80fd\u4f53\u547d\u4ee4\u548c\u4e8b\u4ef6\u65f6\u81ea\u52a8\u6267\u884c\u64cd\u4f5c\u3002Hooks  [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-docs"],"_links":{"self":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":2,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":765,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/765"}],"wp:attachment":[{"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pa.yingzhi8.cn\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}