From 377121d1c53ca691c5fec198b2998fe0f7c37cca Mon Sep 17 00:00:00 2001 From: Jeffery Date: Tue, 28 Jul 2026 14:21:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(hooks):=20=E8=A3=9C=E4=B8=8A=E8=88=87=20do?= =?UTF-8?q?c=EF=BC=8Fgeneric=20=E7=9B=B8=E5=90=8C=E7=9A=84=E5=90=88?= =?UTF-8?q?=E4=BD=B5=E8=B6=85=E9=9B=86=20hooks.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 三個 repo 的 plugin.json 名稱都是 jsc,Claude Code 以 plugin 名稱為鍵註冊 hooks,同名時只保留一份(實測 stop_hook_summary 的 hookCount 為 1),無法 預期哪一份會贏。因此每個 repo 都必須帶同一份合併超集,否則贏的那份缺少的 hook 會靜默失效。 code 本身沒有 hook 腳本,此檔僅作為超集載體:SessionStart 載入角色、Stop 執行 worklog 與角色記憶記錄;指令先試 CLAUDE_PLUGIN_ROOT,找不到再依 「擁有者 marketplace 優先 → 全 cache 後援」搜尋 ~/.claude 與 ~/.codex 快取。 Co-Authored-By: Claude Opus 5 (1M context) --- hooks/hooks.json | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 hooks/hooks.json diff --git a/hooks/hooks.json b/hooks/hooks.json new file mode 100644 index 0000000..6eab4fe --- /dev/null +++ b/hooks/hooks.json @@ -0,0 +1,31 @@ +{ + "hooks": { + "SessionStart": [ + { + "hooks": [ + { + "type": "command", + "command": "rel='scripts/role/role_load.sh'; own='generic'; root=\"${CLAUDE_PLUGIN_ROOT:-}\"; if [ -n \"$root\" ] && [ -f \"$root/$rel\" ]; then exec \"$root/$rel\"; fi; for base in \"$HOME/.claude/plugins/cache\" \"$HOME/.codex/plugins/cache\"; do for dir in \"$base/$own/jsc\" \"$base\"; do s=$(find \"$dir\" -path \"*/jsc/*/$rel\" -type f 2>/dev/null | sort -V | tail -n 1); if [ -n \"$s\" ]; then exec \"$s\"; fi; done; done; exit 0", + "timeout": 20 + } + ] + } + ], + "Stop": [ + { + "hooks": [ + { + "type": "command", + "command": "rel='scripts/worklog/worklog.sh'; own='doc'; root=\"${CLAUDE_PLUGIN_ROOT:-}\"; if [ -n \"$root\" ] && [ -f \"$root/$rel\" ]; then exec \"$root/$rel\"; fi; for base in \"$HOME/.claude/plugins/cache\" \"$HOME/.codex/plugins/cache\"; do for dir in \"$base/$own/jsc\" \"$base\"; do s=$(find \"$dir\" -path \"*/jsc/*/$rel\" -type f 2>/dev/null | sort -V | tail -n 1); if [ -n \"$s\" ]; then exec \"$s\"; fi; done; done; exit 0", + "timeout": 60 + }, + { + "type": "command", + "command": "rel='scripts/role/role_capture.sh'; own='generic'; root=\"${CLAUDE_PLUGIN_ROOT:-}\"; if [ -n \"$root\" ] && [ -f \"$root/$rel\" ]; then exec \"$root/$rel\"; fi; for base in \"$HOME/.claude/plugins/cache\" \"$HOME/.codex/plugins/cache\"; do for dir in \"$base/$own/jsc\" \"$base\"; do s=$(find \"$dir\" -path \"*/jsc/*/$rel\" -type f 2>/dev/null | sort -V | tail -n 1); if [ -n \"$s\" ]; then exec \"$s\"; fi; done; done; exit 0", + "timeout": 60 + } + ] + } + ] + } +}