Subagent — 像資深開發者那樣委派
把專注任務派給專門 Claude 實例
⏱ 預估 ~6 分鐘
01 · 讀一讀
資深開發者不自己做所有事 — 他們委派。當初階開發者請資深調查 bug,資深不放棄目前工作。他們派人調查、回報。
Subagent 讓你用 Claude Code 做同樣事。不是一個大對話試著處理一切 — 讀檔、跑測試、調查架構 — 你可以把專注任務派給專門 subagent,它們在自己 context window 工作。
關鍵好處:subagent 讓你主對話保持乾淨。一個 subagent 可能讀 50 個檔了解你驗證系統,但只短總結回到你 context window。
💡 想像一下想 subagent 像派研究助理去圖書館。你不自己去、桌上堆滿書 — 他們去、讀一切、帶一頁總結回來。你桌子保持清,給重要的工作。
重點整理
- Subagent 在跟你主對話分開的 context window 跑
- 它們獨立調查、分析、執行任務
- 只總結回到你 context — 不是它們讀的所有檔
- 你主對話保持專注實作
02 · 讀一讀
Claude Code 有幾種內建 subagent 類型,每種為特定任務設計:- Explore — Read-only 研究。搜檔、讀程式、回答程式碼庫問題。不能編輯。 - Plan — 架構設計。探索程式碼庫、提實作計畫。你核准前 read-only。 - Bash — 指令專家。跑終端機指令。用在跑測試、build、系統檢查。
Claude 在認到該隔離的任務時自動生 subagent — 像調查大程式碼庫或跑測試套件。你也可以明確請。
重點整理
- Explore:read-only 研究跟程式碼庫分析
- Plan:架構設計跟實作規劃
- Bash:終端機指令跟系統操作
- Claude 適當時自動生 subagent
03 · 看程式碼
你可以直接請 Claude 用 subagent。下面是觸發 subagent 委派的 prompt。
觸發 subagent 的 prompt
"Use a subagent to investigate how auth works in this codebase"
"Explore the database schema and summarize what tables we have"
"Run the test suite and report which tests fail"
"Analyze the API routes and list all endpoints"
你請 Claude「調查」、「探索」、「分析」、或「跑測試」時,它常常自動委派給 subagent。Subagent 在自己 context 做重活,簡潔總結回到你對話。
04 · 讀一讀
你可以寫有 YAML frontmatter 的 SKILL.md 建自己的自訂 subagent。這定義有自己指令、工具限制、模型選擇的專門 agent。
自訂 agent 強大因為你可以限制能力。Code reviewer 只需要讀檔 — 不該編輯或跑指令。Test runner 需要 Bash 但不要 Edit。工具限制讓 agent 更安全更專注。
重點整理
- 自訂 agent 在有 YAML frontmatter 的 SKILL.md 定義
- tools: 欄位限制 agent 能做什麼
- Reviewer 需要 Read/Grep/Glob — 不是 Edit 或 Bash
- 限制讓 agent 更安全更專注
05 · 看程式碼
下面是怎麼建自訂 code-reviewer subagent。YAML frontmatter 設定它行為。
.claude/skills/code-reviewer/SKILL.md
---
name: code-reviewer
description: Expert code review specialist. Use after code changes.
tools: Read, Grep, Glob
model: sonnet
---
Review code for:
1. Bug risks and logic errors
2. Security vulnerabilities (injection, auth bypass)
3. Performance issues (N+1 queries, unnecessary loops)
4. Style inconsistencies with the existing codebase
Provide specific line references and severity ratings.
這 agent 只能讀程式碼 — 不能編檔或跑指令。tools: Read, Grep, Glob 限制確保它專注審查。model: sonnet 表示用 Sonnet(快、cost-effective)而不是你主對話用的模型。
06 · 選擇題
你實作新功能、需要了解現有驗證系統怎麼運作。它牽涉讀 20+ 個檔。最 context 效率的方法?
- 在主對話自己讀全部 20 個檔
- 請 Claude 不讀檔解釋驗證
- 為調查開新 Claude session
- 用 subagent 調查、回總結
07 · 配對
配對每種 subagent 類型到最佳用途。
(本節為互動練習,請啟用 JavaScript 體驗)
⚠ 完整互動體驗需要 JavaScript。請啟用 JavaScript 後重新整理。
※ 本站為獨立繁中教學專案,非 Anthropic 官方產品。Claude™ 為 Anthropic, PBC 商標。