📚職涯停看聽・知識庫← 總部儀表板
📅最後更新:2026/05/10
📑 目錄

Claude Code Hooks × Sub-Agent × /plugins 深度研究(2026-05-02)

🔗 承接:knowledge/analyses/2026-04-27-threads-inspiri-flow-agent-hooks.md(概念層) 本文補入:技術規格 + tzlth-hq 現況對照 + P3暫緩條件重評 研究工具:claude-code-guide agent(官方文件直接查詢) 研究日期:2026-05-02


背景與目的

2026-04-27 已完成 Agent 5層架構的概念層分析,結論:

  • 前 3 層(CLAUDE.md + SKILL + Hooks)已完整覆蓋 ✅
  • 後 2 層(Sub-agent + Plugin/外掛)P3暫緩,重啟條件已定義

本次深入到技術規格層,目標:

  1. Hooks:確認完整事件類型(現有知識只列了 7 種,實際更多)
  2. Sub-Agent:理解技術限制與應用邊界
  3. /plugins:釐清這個概念在 Claude Code 中的確切定義

Part 1:Hooks 完整技術規格

1-1 事件類型完整清單(共 25+ 種)

⚠️ 重要發現claude-code-structure-guide.md(2026-03-30 記錄)只列了 8 種,實際目前有 25+ 種。

類別 事件名稱 觸發時機
工具相關 PreToolUse 工具執行前(可阻止/修改)
PostToolUse 工具執行成功後
PostToolUseFailure 工具執行失敗後
PermissionRequest 權限對話框出現時
PermissionDenied 工具被自動分類器拒絕時
PostToolBatch 整批平行工具呼叫完成後
會話相關 SessionStart 會話開始或恢復時
SessionEnd 會話終止時
Setup --init-only-p --init
Stop Claude 完成回應時
StopFailure API 錯誤導致回合結束時
提示相關 UserPromptSubmit 使用者提交提示時(執行前)
UserPromptExpansion 使用者輸入命令擴展為提示時(可阻止)
壓縮相關 PreCompact 上下文壓縮前
PostCompact 上下文壓縮完成後
InstructionsLoaded CLAUDE.md 或 rules/*.md 加載時
檔案與設定 ConfigChange 設定文件在 session 期間變更
CwdChanged 工作目錄變更時
FileChanged 監視的檔案在磁碟上變更
WorktreeCreate 建立 worktree 時
WorktreeRemove 移除 worktree 時
Sub-agent 相關 SubagentStart 生成子代理時
SubagentStop 子代理完成時
TaskCreated 透過 TaskCreate 建立任務時
TaskCompleted 任務標記完成時
TeammateIdle 代理團隊成員即將空閒時
MCP 相關 Elicitation MCP 伺服器要求使用者輸入時
ElicitationResult 使用者回應 MCP elicitation 後
通知 Notification Claude Code 發送通知時

1-2 關鍵事件 JSON 規格

PreToolUse(最重要 — 可攔截/修改)

// Input (stdin)
{
  "session_id": "abc123",
  "cwd": "/project",
  "hook_event_name": "PreToolUse",
  "tool_name": "Bash",
  "tool_input": { "command": "npm test" }
}

// Output (stdout) — 阻止
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "理由回傳給 Claude"
  }
}

// Output — 修改 input
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "allow",
    "updatedInput": { "command": "npm test --coverage" }
  }
}

permissionDecision 值:

  • "allow" → 跳過互動權限提示
  • "deny" → 取消工具呼叫,原因回傳 Claude
  • "ask" → 顯示正常權限提示
  • "defer" → 非互動模式保留待處理

PostToolUse(唯讀 — 可注入上下文)

// Input
{
  "hook_event_name": "PostToolUse",
  "tool_name": "Edit",
  "tool_input": { "file_path": "..." },
  "tool_output": { "result": "..." }
}
// Output — 只能注入上下文
{
  "hookSpecificOutput": {
    "hookEventName": "PostToolUse",
    "additionalContext": "注入給 Claude 的補充說明"
  }
}

❌ PostToolUse 無法阻止或修改輸出。工具已執行。

Stop(完成後品質控制)

// Input
{
  "hook_event_name": "Stop",
  "stop_hook_active": false  // true = 已觸發過,防無限迴圈
}
// Output — 可阻止 Claude 停止
{ "decision": "block", "reason": "收尾七件事尚未完成" }
{ "decision": "allow" }

⚠️ 必須檢查 stop_hook_active!若為 true 時仍返回 "block" = 無限迴圈。

UserPromptSubmit(提示前注入上下文)

// Input
{
  "hook_event_name": "UserPromptSubmit",
  "prompt": "使用者輸入的文字"
}
// Output — 注入上下文(exit 0 + stdout = 直接注入)
// 直接 echo 文字即可,不需 JSON

PostCompact(壓縮後注入提醒)

// Input
{
  "hook_event_name": "PostCompact",
  "source": "manual|auto"
}
// Output — 注入重要提醒
{
  "hookSpecificOutput": {
    "hookEventName": "PostCompact",
    "additionalContext": "壓縮後需執行的重要提醒"
  }
}

1-3 Exit Code 完整規範

Exit Code 意義 行為
0 成功 解析 JSON output;stdout 文字注入 Claude 上下文
2 阻止錯誤 工具呼叫取消;stderr 回傳 Claude 作為反饋
其他 非阻止錯誤 動作繼續;Transcript 顯示 " hook error"

❌ 不可混用:不能同時 exit 2 又輸出 JSON。兩者選其一。


1-4 settings.json 完整格式

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash|Edit|Write",
        "hooks": [
          {
            "type": "command",
            "command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/my-hook.py",
            "timeout": 30,
            "statusMessage": "檢查中..."
          }
        ]
      }
    ],
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo '今日:$(date +%Y-%m-%d)'"
          }
        ]
      }
    ]
  }
}

Hook type 選項:

type 說明
command 執行 shell 命令(預設 600s timeout)
http POST 到 URL
mcp_tool 呼叫 MCP 工具
prompt 用 Claude 模型(預設 Haiku, 30s timeout)評估
agent 啟動 sub-agent(60s timeout)

1-5 tzlth-hq 現有 Hooks 狀態 vs 升規機會

現有(已實作):

Hook 檔案 事件 功能
query-gate-hook.py scripts/ PreToolUse _pending.flag 存在,阻止 Edit/Write
knowledge-hook.py scripts/ PostToolUse 知識庫查詢後注入上下文提醒
UserPromptSubmit settings.local.json UserPromptSubmit 注入知識庫查詢結果(每次 Tim 輸入前)

高價值升規機會(建議 P2):

機會 事件 做什麼 價值
A. PostCompact 接續提醒 PostCompact 自動注入「壓縮後接續規則 Step 0-4:清除 _pending.flag → 讀 tasks.md → 輸出壓縮後查照」 直接解決壓縮後忘記接續規則的模式(IMP-089)
B. Stop 品質自查觸發 Stop 提示收尾七件事自查(注意:需 stop_hook_active 防無限迴圈) 強制收尾,但有風險(無限迴圈)→ 先 P3 觀察
C. PostToolBatch 批次紀錄 PostToolBatch 多工具平行呼叫完成後注入摘要 低優先,可選

建議立即實作(A)的理由: PostCompact 是被動壓縮最痛的痛點——壓縮後 Claude 重新開始,容易忘記執行 Step 0(清除旗標)。PostCompact Hook 可以在壓縮完成後自動注入一段文字到新的 context,讓 Claude 看到即執行。這是目前人工依賴規則記憶的唯一補強方式。


Part 2:Sub-Agent 完整技術規格

2-1 .claude/agents/ 定義格式

---
name: code-reviewer
description: Expert code reviewer. Analyzes code quality, security, and best practices.
tools: Read, Grep, Glob, Bash
disallowedTools: Write, Edit
model: sonnet
permissionMode: default
maxTurns: 20
background: true
isolation: worktree
---

You are a senior code reviewer...

完整 frontmatter 欄位:

欄位 型別 必填 說明
name string 唯一識別符(小寫加連字號)
description string Claude 何時自動委派
tools string[] 白名單工具(預設繼承全部)
disallowedTools string[] 黑名單工具
model string sonnet/opus/haiku/inherit(預設)
permissionMode string default/acceptEdits/auto/bypassPermissions
maxTurns number 最大 agentic turn 數
skills string[] 預載入的 skill
memory string user/project/local
background boolean 強制背景執行
effort string low/medium/high/xhigh/max
isolation string worktree(目前唯一模式)
initialPrompt string 自動執行的首個 turn

2-2 Context 隔離規則(重要)

特性 說明
父 session 歷史 ❌ Sub-agent 看不到。獨立上下文,只接收傳入的 prompt
工具繼承 ✅ 預設繼承父 session 全部工具,可用 tools/disallowedTools 限制
遞迴(Sub-agent 內再 spawn) 不支援。Sub-agent 不能再生成 sub-agent
Fork 模式 CLAUDE_CODE_FORK_SUBAGENT=1 時 sub-agent 繼承完整歷史
繼續已存在的 sub-agent ✅ 透過 SendMessage 工具(to: agentId)繼續
輸出回傳 摘要結果回到父 session;詳細 transcript 儲存於 ~/.claude/projects/.../subagents/

2-3 Token 費用計算

  • Sub-agent 的 token(prompt + completion)另外計費,不計入父 session token
  • Prompt cache 可跨 fork 共享
  • 無官方記載的 sub-agent 數量上限(可多個平行執行)

2-4 P3暫緩條件重評(2026-05-02)

來源:2026-04-27 分析中設定的重啟條件

條件 設定標準 目前狀態 達成?
人員擴張 Tim 有長期合作夥伴或助理 Tim 仍為單人工作室
任務量 > 10/日連續 4 週 穩定 > 10 個並行任務 目前任務量遠低於此
Claude Code /Agents 成熟 Agent 功能文件完整、社群有實戰案例 ✅ 文件完整、功能豐富

結論:P3暫緩決策維持不變(3 條件中 1 條達成,需至少 2 條)

技術層面已成熟,但業務規模條件未達。建議:下次重評時間 → 人員擴張時 or 任務量達標時。


Part 3:/plugins 定性

3-1 /plugin 指令(是什麼)

Claude Code CLI 有 /plugin(單數)指令,功能:

/plugin install <plugin-name>   # 從市場安裝
/plugin uninstall <plugin-name> # 移除
/plugin list                    # 列出已安裝
/plugin update                  # 更新所有
/plugin enable / disable        # 管理狀態

⚠️ 命名澄清:指令為 /plugin(單數),非 /plugins(複數)。Tim 說的「/plugins 探索」可能指「plugin 系統的探索」,而非一個具體指令。


3-2 Plugin 架構

Plugin = 目錄結構,包含:

my-plugin/
├── .claude-plugin/
│   └── plugin.json         # 必需:清單(name/version/description)
├── skills/                 # Skill 定義
├── agents/                 # Agent 定義
├── hooks/
│   └── hooks.json          # Hook 配置
├── .mcp.json               # MCP 伺服器
├── bin/                    # 執行檔(加入 PATH)
└── settings.json           # 預設設定

用途:封裝 skills + agents + hooks + MCP 為一個可分佈的套件。


3-3 Skills(新格式)vs Commands(舊格式)

比較維度 Skills(新 ✅) Commands(舊 ❌)
位置 .claude/skills/<name>/SKILL.md .claude/commands/<name>.md
觸發 Claude 自動調用 or /name 只能 /name 手動觸發
Frontmatter description, disable-model-invocation, allowed-tools, model, context 不支援
模型自動調用 ✅(基於 description)
參數 $ARGUMENTS 佔位符
建議 ✅ 現在應用此格式 ❌ 已過時

tzlth-hq 現況: 我們用 .claude/skills/ 目錄 ✅ 已是正確的新格式


3-4 Plugin 對 tzlth-hq 的意義

tzlth-hq 是個人工作室單人專案,Plugin 的主要價值是「分佈給團隊/社群」。

面向 評估
需要 /plugin install 安裝外部 plugin? 目前無此需求
將 tzlth-hq 的 SKILL 打包成 Plugin 分佈? 個人使用,無分佈需求
使用 Plugin 機制重組現有 SKILL? 無必要,現有 .claude/skills/ 已夠用

結論:Plugin 系統對 tzlth-hq 目前無直接應用需求。維持現有 SKILL 架構即可。

📌 深度研究後記(2026-05-10):本 Part 3 為定性框架(無 marketplace 清單)。2026-05-10 進行了完整官方 Marketplace 探索,含 Glob 本機掃描現有安裝確認(ak-threads-booster v1.1.0)+ WebSearch 官方目錄調查(27 個 Plugin,含 LSP 語言服務 / 整合 / 開發工作流 / 輸出風格)+ 三標準評估。評估結論:typescript-lsp 有潛力(Next.js 開發,零外部依賴),其餘無立即需求。完整報告見 analyses/2026-05-10-claude-code-plugins-official-marketplace.md


維度 9:採用評估(2026-05-02)

✅ 立即採用建議(P2)

採用點 A:PostCompact Hook 自動注入接續提醒

  • 觸發事件:PostCompact
  • 做什麼:每次壓縮完成後,自動注入一段文字:「⚠️ 壓縮後接續規則已觸發:Step 0 清除 _pending.flag → Step 1 讀取 dev/tasks.md → Step 2 輸出壓縮後查照格式」
  • 實作:在 scripts/postcompact-reminder-hook.py 中 echo 這段文字到 stdout,設定於 settings.local.json PostCompact 事件
  • 解決問題:IMP-089 壓縮後旗標殘留 + 接續規則忘記執行(出現次數 3+)
  • 難度:低(約 15 行 Python)
  • 注意事項:此 hook 在 PostCompact 只能注入文字,不能阻止(無 block 機制)

🔍 觀察期(P3)

觀察點 B:Stop Hook 收尾七件事品質控制

  • 概念:用 type: "prompt" 的 Stop Hook 讓 Claude 自我評估是否完成收尾七件事
  • 風險:需精確處理 stop_hook_active,否則無限迴圈
  • 評估:風險高於收益(現有 HARD STOP 已能達到類似效果)→ 待觀察
  • 重評時機:收尾七件事遺漏率 > 2次/月時

觀察點 C:SubagentStart/Stop Hook 監控

  • 概念:追蹤 sub-agent 的啟動和結束,記錄使用量
  • 評估:目前 sub-agent 使用頻率低,監控價值不高 → P3

❌ 不採用

Plugin 系統:個人使用無分佈需求,現有 .claude/skills/ 架構已足夠。

Sub-Agent 擴張:P3暫緩條件 2/3 未達成(人員、任務量),維持現有暫緩決策。


關鍵發現摘要

  1. Hooks 遠比我們知道的豐富:25+ 種事件(vs 現有知識 8 種)。最有價值但尚未使用的:PostCompactUserPromptExpansionSubagentStart/Stop
  2. Sub-agent 不能遞迴:sub-agent 內不能再 spawn sub-agent,限制了複雜協作場景
  3. PostCompact Hook = 壓縮接續問題的技術解:自動注入提醒,比靠規則記憶更可靠
  4. /plugins = plugin 系統 + /plugin CLI 指令,對 tzlth-hq 無即時應用需求
  5. 我們的 SKILL 格式(.claude/skills/)已是正確的新格式,無需改變
  6. claude-code-structure-guide.md 需要更新:現有 Hooks 章節只列 8 種,實際 25+


Part 4:Stop Hook 擴充方案設計(Session 95 深度研究)

研究日期:2026-05-02 | 來源:Session 95 claude-code-guide agent 深度查詢 背景:現有 Stop Hook 為 auto-commit bash script。Tim 希望評估兩個升規方向: ① Windows 桌面通知(長任務完成提醒)② 收尾七件事「硬性觸發」


4-1 三個關鍵技術問題的研究結果

Q1:Stop Hook stdout 是否注入 Claude context?

結論:❌ 不注入(與 PostCompact 不同)

Hook 事件 exit 0 + stdout text 行為
SessionStart ✅ 注入 Claude context 對話開始時注入背景資訊
UserPromptSubmit ✅ 注入 Claude context 每次 Tim 輸入前注入提醒
PostCompact ✅ 注入 Claude context 已實測確認(postcompact-reminder-hook.py)
Stop ❌ 只寫 debug log 不會進入 Claude context
PostToolUse ❌ 只寫 debug log 工具已執行,無注入需求

⚠️ 代理研究差異:claude-code-guide agent 的 Q1 表格誤將 PostCompact 標為 ❌(無注入)。但 tzlth-hq 的 postcompact-reminder-hook.py 已實際驗證 PostCompact exit 0 + stdout text 有效注入 Claude context(Session 94 Tim 確認)。以實測為準,agent 查詢有誤。

Stop Hook 確認:Stop Hook stdout → debug log only,不進入 Claude context。若要影響 Claude 行為,只能透過 decision: block JSON 輸出。

設計影響:無法用 Stop Hook 的 stdout text 在 Claude 的 active context 注入「收尾七件事提醒」。


Q2:多 entry Stop Hook 執行順序 + stop_hook_active 作用域

結論 A:所有 entries 並行執行(不是串行)

settings.json Stop Hook 多 entry:

"Stop": [
  { "hooks": [{ entry1: git commit + push }] },   ──┐ 並行執行
  { "hooks": [{ entry2: decision logic    }] }    ──┘
]

→ 如果 entry2 返回 { "decision": "block" }:
  entry1 的 git commit 已在同時執行,block 只能阻止 Claude 停止,不能取消 entry1

結論 B:stop_hook_active 是「block-retry 週期」級別,不是 session 全局鎖

情況 stop_hook_active 值 建議行為
首次 Stop(正常停止) false 可執行驗證邏輯、可返回 block
被 block 後的立即重試 Stop true 必須 exit 0,不再 block(防無限迴圈)
新一輪獨立 Stop(之前無 block) false 可再次執行驗證邏輯

⚠️ 修正原始設計假設:Session 95 查照前假設「stop_hook_active = session 全局鎖,block 每 session 只能觸發一次」為錯誤。正確行為:每次新的獨立 Stop 事件都從 false 開始,stop_hook_active = true 只在「本次被 block 的重試流程」中有效。decision: block 在同一 session 可多次觸發(只要每次都是新的獨立 Stop 事件)。

設計影響decision: block 技術上可用於多輪攔截,但並行執行造成的雙 auto-commit 問題仍存在。


Q3:Windows 桌面通知(無管理員、無額外安裝)

推薦方案:PowerShell Windows.UI.Notifications API(原生,Windows 10+)

# 從 Git Bash 調用(Stop Hook script 片段)
powershell.exe -NonInteractive -Command "
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > \$null
\$tmpl = '<toast><visual><binding template=\"ToastText02\"><text id=\"1\">職涯停看聽 HQ</text><text id=\"2\">Claude 完成回應,請確認收尾七件事</text></binding></visual></toast>'
\$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
\$xml.LoadXml(\$tmpl)
\$toast = New-Object Windows.UI.Notifications.ToastNotification \$xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Claude Code').Show(\$toast)
" 2>/dev/null || true
方案 無管理員 無額外安裝 bash 調用 推薦度
PowerShell Windows.UI.Notifications powershell.exe -Command 🟢 首選
System.Windows.Forms NotifyIcon(氣球) powershell.exe -Command 🟡 備選(視覺效果弱)
BurntToast PowerShell 模組 ❌ 需安裝 簡單 🟡
msg * CMD 指令 ❌ 需設定 簡單

4-2 設計方案選擇矩陣

方案 描述 優點 問題 推薦度
A:通知 only(新 entry) 新增第二 Stop Hook entry,PowerShell 發送 toast 通知。不含 block 邏輯 簡單,不干擾現有 auto-commit;Tim 視覺提醒 每次 Claude 停止都通知(包含中間 turn,可能過多);不強制收尾 🟢
B:單一 hook 重構(auto-commit + 通知合一) 以新 Python 腳本取代現有 bash Stop Hook,腳本末尾 + 通知 清晰、無雙 entry 問題 中等複雜度;auto-commit 從 bash 改 Python,需測試 🟡
C:block + 通知 + 修復雙 commit(設計複雜) entry1 移至 block-check 腳本內部(allow 時才 commit),entry2 通知 理論上最完整 複雜度高;decision: block 攔截效果有限(Claude 可無視後再停);ROI 低 🔴
D:維持現狀(僅 CLAUDE.md) 不動 Stop Hook,收尾七件事靠規則 零風險,已運作 無技術補強,靠記憶 🟡

4-3 推薦方案:A(通知 only)+ 維持現有 auto-commit

理由:

  1. 收尾七件事無法真正「硬性強制」:Stop Hook 的 decision: block 只能中斷一次,Claude 可以選擇無視 reason 繼續停止(沒有真正的強制機制)。CLAUDE.md 的規則約束 + Tim 的攔截機制已是可達到的最佳軟性強制。
  2. Windows 通知有合理價值:長任務(30+ 分鐘)完成時,桌面通知讓 Tim 不必持續盯著螢幕。
  3. 最小修改風險:在現有 Stop Hook entries 旁新增一個通知 entry,不改動 auto-commit 邏輯。

實作建議(設計草稿):

// settings.local.json 修改
"Stop": [
  {
    "hooks": [
      {
        "type": "command",
        "command": "cd \"C:/Users/USER/Desktop/tzlth-hq\" && git add -A && git diff --cached --quiet || (git commit -m \"自動同步:$(date '+%Y-%m-%d %H:%M')\" && git push origin main) 2>/dev/null || true",
        "timeout": 30
      }
    ]
  },
  {
    "hooks": [
      {
        "type": "command",
        "command": "python -X utf8 C:/Users/USER/Desktop/tzlth-hq/scripts/stop-notification-hook.py",
        "timeout": 10
      }
    ]
  }
]

scripts/stop-notification-hook.py 草稿:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Stop Hook:Claude 完成回應時發送 Windows 桌面通知
- 目的:長任務完成時提醒 Tim,不需持續盯螢幕
- 注意:每次 Claude 停止都會觸發(包含中間 turn)
"""
import subprocess
import json
import sys

input_data = json.loads(sys.stdin.read())
# 如果是 block 重試中,不發通知(避免重複)
if input_data.get("stop_hook_active", False):
    sys.exit(0)

ps_command = """
try {
    [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
    $tmpl = '<toast><visual><binding template="ToastText02"><text id="1">職涯停看聽 HQ</text><text id="2">Claude 完成回應</text></binding></visual></toast>'
    $xml = New-Object Windows.Data.Xml.Dom.XmlDocument
    $xml.LoadXml($tmpl)
    $toast = New-Object Windows.UI.Notifications.ToastNotification $xml
    [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier('Claude Code').Show($toast)
} catch {}
"""

subprocess.run(
    ["powershell.exe", "-NonInteractive", "-Command", ps_command],
    capture_output=True, timeout=8
)
sys.exit(0)

⚠️ 每次 turn 都通知的潛在問題:如果對話頻繁,通知可能過多。解法:在腳本中加入「最小間隔 30 秒」的時間戳判斷(存入 scripts/.last-notification),或僅在 Tim 設定特定工作階段時觸發。建議先無條件通知試用 1 週,根據體驗調整。


4-4 誠實評估:可達 vs 不可達目標

目標 技術可達性 說明
長任務完成桌面通知 ✅ 可達 PowerShell Windows.UI.Notifications,無需管理員
收尾七件事「提醒」(軟性) ✅ 可達(有限制) 通知文字可包含提醒;但無法保證 Claude 執行
收尾七件事「強制執行」(硬性) ❌ 技術上不可達 Stop Hook 無法真正強制 Claude;CLAUDE.md 規則是最佳替代
收尾完成後才 auto-commit ⚠️ 可達但複雜 需重構為方案 C(block + 腳本內 commit);ROI 不值得

最終定位:Stop Hook 的正確用途是「完成後輔助動作」(auto-commit、通知),不是「行為強制」。行為強制的正確機制是 CLAUDE.md 規則 + Tim 的攔截指令。


Part 5:Sub-Agent 缺口補完 + C-level 平行架構評估(Session 100)

研究日期:2026-05-03 | 來源:Session 100 claude-code-guide agent + CEO 架構分析 背景:Session 93 研究了 Sub-agent 技術規格與 P3暫緩條件。本 Part 補完 3 個技術缺口,並評估是否為 tzlth-hq 設計 C-level 平行架構(CPO/COO/CTO)。


5-1 技術缺口補完(Session 93 遺漏)

缺口一:/agents 互動式 CLI vs .claude/agents/ 檔案,有何差異?

結論:兩者是「同一目的地、不同入口」

比較維度 /agents 互動式 CLI .claude/agents/ 檔案(手動)
性質 UI 介面層 底層儲存層
操作 圖形化:Running tab(查看/停止)/ Library tab(建立/編輯/刪除) 直接編輯 YAML frontmatter .md 檔案
結果 生成 .claude/agents/*.md 檔案 .claude/agents/*.md 本身就是
優勢 引導式設定、視覺化管理 可版本控制、可 batch 建立、CI/CD 友好
CLI 補充 claude agents(無 /):無互動、直接列出所有 agents

tzlth-hq 適用:手動編輯 .claude/agents/ 更符合現有工作流(git 管理、可審閱、可 Grep 搜尋)。若未來需要快速建立試驗性 agent,可用 /agents UI。


缺口二:Windows 相容性

面向 結論
.claude/agents/ 檔案格式 ✅ 完全支援 Windows(YAML/Markdown 無平台差異)
isolation: "worktree" ✅ 支援,前提:需安裝 Git for Windows(git worktree 指令可用)
路徑分隔符 agent 定義內使用正斜線(/),與 tzlth-hq 現有腳本慣例一致
WSL 跨檔案系統 ⚠️ 若從 WSL 存取 Windows 路徑(/mnt/c/...),搜尋效能下降;純 Windows 路徑無此問題
tzlth-hq 現況 純 Windows 環境(C:/Users/USER/...),無 WSL 跨檔案系統問題 ✅

缺口三:@agentname 語法

結論:@agentname 是「指定代理」機制,適用於所有來源的 agent

面向 說明
觸發方式 在對話輸入框輸入 @ 後,typeahead 自動顯示可用 agents
格式(本機 agent) @agent-<name> 或 typeahead 選取 <name> (agent)
格式(plugin agent) @agent-<plugin-name>:<agent-name>
效果 保證由指定 agent 執行,而非 Claude 自主決定是否委派
適用來源 所有 agent(/agents UI 建立的 / .claude/agents/ 手動建立的 / plugin agent)
實際行為 使用者輸入的整段任務描述 → 成為該 agent 的 task prompt;Claude 扮演橋接但指定 agent 執行

設計注意@agentname 的本質是「user-level routing override」——跳過 Claude 的自主委派判斷,直接指定執行者。適合已知特定 agent 能力的場景。


5-2 C-level 平行架構設計草稿

本節為設計評估,非採用決策。採用前需 Tim 確認 + 觸發 RCF(條件 3:組織架構異動)。

設計原則

原則 說明
CEO 層(Claude)仍是最高協調點 Tim → CEO → C-level 路由,非 Tim 直接呼叫 C-level
C-level = 領域協調,非技術部門 CPO/COO/CTO 各自管 3-5 個部門,做跨部門協調與方向整合
部門仍直接執行 實際執行任務的仍是各部門 agent,C-level 只做「路由 + 彙整」
STR(策略部)仍直屬 CEO 組織架構、長期規劃等 CEO 事務不下放

三層 C-level 部門分組

C-level 職稱 負責部門 核心關注
CPO Chief Product Officer CNT(內容)/ SOC(社群)/ PRD(產品)/ EDU(課程)/ GRW(成長分析) 什麼內容觸達什麼客群,產品如何成長
COO Chief Operations Officer BIZ(業務)/ FIN(財務)/ CRM(客戶)/ LEG(法務)/ KM(知識庫) 業務跑得順不順,流程有無漏洞
CTO Chief Technology Officer DEV(開發)/ SEC(資安)/ HR(系統清單)/ IAUD(內稽)/ EAUD(外稽) 技術系統健不健康,品質有無保障

HR 在 tzlth-hq 是「系統員工冊」而非人事部,因此歸 CTO 管(技術基礎建設)。

Frontmatter 範例(CPO)

---
name: cpo-agent
description: Chief Product Officer for 職涯停看聽. Coordinates CNT (content), SOC (community), PRD (product), EDU (courses), GRW (growth analytics). When given a task involving content strategy, product roadmap, or community growth, synthesize inputs from relevant departments and return integrated recommendations. Does NOT directly execute — routes to department-level agents.
tools: Read, Glob, Grep, Agent
disallowedTools: Write, Edit, Bash
model: sonnet
permissionMode: default
maxTurns: 15
background: false
---

# CPO 代理(Chief Product Officer)

## 職責
接收 CEO 的跨部門協調請求,整合 CNT / SOC / PRD / EDU / GRW 五個部門的輸入,輸出統一的行動方向建議。

## 禁止
- 不直接執行任務(Write/Edit 禁用)
- 不跨越 CTO / COO 管轄範圍
- 不決策公司方向(CEO 職責)

5-3 P3 重啟條件框架修訂

舊框架的問題

原始條件(2026-04-27 設定):

條件 類型 問題
人員擴張 需求(need) 合理
任務量 > 10/日 × 4 週 需求(need) 合理
Claude Code /Agents 成熟 可行性(feasibility) ⚠️ 性質不同

「3 條件需達 2 條」的問題:可行性條件(Condition 3)和需求條件(Conditions 1-2)被混合計算。但可行性條件是先決門檻(gate),不是替代需求條件的理由。即使「機制已成熟」,在需求不存在的情況下採用,仍是過早優化。

修訂框架

GATE(先決條件,必須通過才進入評估):
  ✅ Claude Code sub-agent 機制成熟(已於 2026-05-02 達成)

NEED(需求條件,以下三項任一成立即可重啟):
  N1: 人員擴張 — Tim 有穩定合作夥伴/助理,需要不同知識背景的上下文切換
  N2: 任務密度持續 — 每日並行任務 > 15 個,持續 4 週以上(非單日爆發)
  N3: CEO 協調瓶頸可觀察 — Tim 或 Claude 自主識別出「多個部門間的跨域決策,因 CEO 同時處理過多而反覆延誤」的具體模式

BENEFIT CHECK(評估時同步確認):
  Q1: C-level 架構是否能降低 CEO 的認知負荷?還是只是增加路由層?
  Q2: 單人工作室的順序任務模式,是否真的需要平行協調層?
  Q3: 每次 C-level 呼叫的 token 成本(獨立計費)vs 直接部門路由的節省?

當前狀態(2026-05-03)

條件 狀態
GATE ✅ 已通過
N1 人員擴張 ❌ 仍為單人工作室
N2 任務密度 ❌ 日常並行任務約 3-5 個,遠低於閾值
N3 CEO 協調瓶頸 ❌ 未識別出具體瓶頸模式

結論:維持 P3 暫緩(⏸) 下次重評觸發:N1/N2/N3 任一達成,或 Tim 主動提出「感覺 CEO 協調有瓶頸」


5-4 採用評估結論

項目 結論
/agents 互動式 CLI 知道有此工具,目前無需改變現有手動 .claude/agents/ 工作流
Windows 相容性 ✅ 無障礙,Git for Windows 已安裝(tzlth-hq 日常使用 git)
@agentname 語法 有用的「指定 agent」機制,C-level 採用後可用此語法精確路由
C-level 架構 ⏸ 設計草稿完成,不採用(GATE 通過但 N1/N2/N3 均未達)
P3 重啟條件 框架修訂:可行性(Gate)vs 需求(N1/N2/N3)分開處理,閾值更清晰

若 Tim 決定採用 C-level 架構

  1. 觸發 RCF(條件 3:組織架構新增 C-level 層)
  2. 建立 .claude/agents/cpo-agent.md / coo-agent.md / cto-agent.md(可從本節 frontmatter 範例起草)
  3. 更新主 CLAUDE.md 部門架構表(新增 C-level 層)
  4. 更新 strategy/department-charters.md(新增 C-level 職責邊界)

研究完整性:Part 5 補完 Part 2(Session 93)的 3 個技術缺口,並完成 C-level 設計草稿 + 決策框架修訂。


Part 4 研究完成日期:2026-05-02 | 研究方法:Session 95 claude-code-guide agent Q1/Q2/Q3 深度查詢 + 設計方案合成

← 返回 學習分析