CLI commands
鉤子
openclaw hooks
管理代理程式鉤子(由 /new、/reset 等命令及閘道啟動事件驅動的自動化)。不加參數的 openclaw hooks 等同於 openclaw hooks list。
列出鉤子
openclaw hooks list [--eligible] [--json] [-v|--verbose]列出從工作區、受管理、額外及隨附目錄中探索到的鉤子。
--eligible:僅列出符合需求的鉤子。--json:結構化輸出。-v, --verbose:包含顯示未滿足需求的「缺少項目」欄。
鉤子(4/5 已就緒) 已就緒: 🚀 boot-md ✓ - 閘道啟動時執行 BOOT.md 📎 bootstrap-extra-files ✓ - 代理程式啟動載入期間注入其他工作區啟動載入檔案 📝 command-logger ✓ - 將所有命令事件記錄至集中式稽核檔案 💾 session-memory ✓ - 發出 /new 或 /reset 命令時,將工作階段內容儲存至記憶體取得鉤子資訊
openclaw hooks info <name> [--json]<name> 是鉤子名稱或鉤子鍵(例如 session-memory)。顯示來源、檔案/處理常式路徑、首頁、事件,以及各項需求的狀態(二進位檔、環境變數、設定、作業系統)。
檢查適用性
openclaw hooks check [--json]輸出已就緒/未就緒的數量摘要;若有尚未就緒的鉤子,則逐一列出及其阻礙原因。
啟用鉤子
openclaw hooks enable <name>在設定中新增或更新 hooks.internal.entries.<name>.enabled = true,並同時開啟 hooks.internal.enabled 主開關(至少設定一個鉤子前,閘道不會載入任何內部鉤子處理常式)。若鉤子不存在、由外掛管理,或不符合適用條件(缺少需求),則操作失敗。
由外掛管理的鉤子會在 hooks list 中顯示 plugin:<id>,且無法在此啟用或停用;請改為啟用或停用其所屬外掛。
啟用後請重新啟動閘道(重新啟動 macOS 選單列應用程式,或在開發環境中重新啟動閘道程序),以重新載入鉤子。
停用鉤子
openclaw hooks disable <name>設定 hooks.internal.entries.<name>.enabled = false。之後請重新啟動閘道。
安裝及更新鉤子套件
openclaw plugins install <package> # 預設使用 npmopenclaw plugins install npm:<package> # 僅使用 npmopenclaw plugins install <package> --pin # 鎖定解析後的版本openclaw plugins install <path> # 本機目錄或封存檔openclaw plugins install -l <path> # 連結本機目錄,而非複製 openclaw plugins update <id>openclaw plugins update --allopenclaw plugins update --dry-run鉤子套件透過統一的外掛安裝程式/更新程式安裝;openclaw hooks install/openclaw hooks update 仍可作為已棄用的別名使用,它們會輸出警告並轉交給 plugins 命令。
- Npm 規格僅限登錄檔:套件名稱加上選用的確切版本或 dist-tag。不接受 Git/URL/檔案規格及語意化版本範圍。相依套件會在專案本機使用
--ignore-scripts安裝。 - 不含版本的規格及
@latest會維持在穩定版軌道;若 npm 解析到預發行版本,OpenClaw 會停止並要求你明確選擇加入(@beta、@rc或確切的預發行版本)。 - 支援的封存格式:
.zip、.tgz、.tar.gz、.tar。 -l, --link會連結本機目錄,而非複製該目錄(將其加入hooks.internal.load.extraDirs);連結的鉤子套件是來自操作人員設定目錄的受管理鉤子,而非工作區鉤子。--pin會在hooks.internal.installs中將 npm 安裝記錄為解析後的確切name@version。- 安裝程序會將套件複製到
~/.openclaw/hooks/<id>,在hooks.internal.entries.*下啟用其中的鉤子,並將安裝記錄到hooks.internal.installs。 - 若已儲存的完整性雜湊不再符合擷取的成品,OpenClaw 會發出警告並在繼續前提示確認;可傳入全域
--yes以略過提示(例如在 CI 中)。
隨附鉤子
| 鉤子 | 事件 | 功能 |
|---|---|---|
| boot-md | gateway:startup |
在閘道啟動時,針對每個已設定的代理程式範圍執行 BOOT.md |
| bootstrap-extra-files | agent:bootstrap |
在代理程式啟動載入期間注入額外的啟動載入檔案(例如單一儲存庫中的 AGENTS.md/TOOLS.md) |
| command-logger | command |
將命令事件記錄到 ~/.openclaw/logs/commands.log |
| compaction-notifier | session:compact:before, session:compact:after |
工作階段壓縮開始及完成時,傳送可見的聊天通知 |
| session-memory | command:new, command:reset |
執行 /new 或 /reset 時,將工作階段內容儲存至記憶體 |
使用 openclaw hooks enable <hook-name> 啟用任何隨附鉤子。完整詳細資訊、設定鍵及預設值:隨附鉤子。
command-logger 記錄檔
tail -n 20 ~/.openclaw/logs/commands.log # 最近的命令cat ~/.openclaw/logs/commands.log | jq . # 美化輸出grep '"action":"new"' ~/.openclaw/logs/commands.log | jq . # 依動作篩選注意事項
hooks list --json、info --json及check --json會將結構化 JSON 直接寫入標準輸出。
相關內容
Was this useful?