/dev-flow:context-hygienefrom dev-flow
Use when 對話很長 / context 變長 / context 快滿 / 感覺 Claude 變笨 / 連續修同一錯誤失敗 / 即將切換到無關任務 / 要讀大量檔案探索 / agent 交接(handoff)/ 使用者說「對話太長」「感覺變笨」「context 滿了」「要不要清一下」「clean context」時。
Ships in dev-flow. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
核心信念:Context 是 Claude Code 最重要的資源。長對話品質下降不是「Claude 變笨」,而是 context 填滿後注意力被稀釋(官方稱 context degradation)。
每次 Claude 回應結束、收到下一則訊息時,由上而下評估,命中即停:
flowchart TD
Start([每次 Claude 回應結束]) --> C1{同任務<br/>AND 連續修同錯誤 ≥2 次?}
C1 -->|是| A1[提醒 Esc Esc Rewind<br/>還原到失敗前帶教訓重試]
C1 -->|否| C2{同任務<br/>AND 部分段落冗餘?}
C2 -->|是| A2["提醒 /rewind → Summarize from here<br/>精準壓縮局部"]
C2 -->|否| C3{同任務<br/>AND 對話已相當長?}
C3 -->|是| A3["提醒 /compact focus on 本任務重點"]
C3 -->|否| C4{使用者訊息<br/>跳到無關新任務?}
C4 -->|是| A4["提醒 /clear + 主動提供 brief 模板"]
C4 -->|否| C5{接下來要讀 ≥5 檔<br/>OR 跨模組探索?}
C5 -->|是| A5[建議派 subagent<br/>fresh context, 主對話只收結論]
C5 -->|否| A6[Continue 不打擾]
判定規則:
/clear / /compact / /rewind。| 動作 | 使用者指令 | 何時用 | 留下什麼 | 丟掉什麼 |
|---|---|---|---|---|
| Continue | (繼續打字) | 同任務延續 | 全部 | 無 |
| Rewind | Esc Esc 或 /rewind → Restore | 失敗嘗試要重試 | 選定訊息前 | 選定訊息起全部 |
| Summarize from here | Esc Esc 或 /rewind → Summarize | 部分段落已冗餘 | 選定訊息前全部 | 選定訊息起被壓縮 |
| Compact | /compact focus on {重點} | 對話長但要繼續 | 摘要 | 原始對話細節 |
| Clear | /clear + 手寫 brief | 切換無關任務 | 手寫 brief | 整個 session |
| Subagent | Agent tool(Claude 代召) | 探索/研究/驗證 | 結論 | tool output 細節 |
/compact focus on ... 寫法官方格式:/compact <instructions> — instructions 指示 compact 後要保留的重點。
| 情境 | 差寫法 | 好寫法 |
|---|---|---|
| debug 完成要繼續寫 code | /compact | /compact focus on the root cause found and the fix approach, drop the failed attempts |
| 多檔案重構中 | /compact | /compact focus on the file list modified so far and the naming convention decided |
| API 設計討論後要實作 | /compact | /compact focus on the final API contract and rejected alternatives with reasons |
原則:告訴 compact 三件事 — 保留什麼、丟掉什麼、為什麼。
按 Esc Esc 或打 /rewind:
| 選項 | 效果 |
|---|---|
| Restore code and conversation | 還原程式碼 + 對話到選定點 |
| Restore conversation | 只還原對話,保留當前程式碼 |
| Restore code | 只還原程式碼,保留對話 |
| Summarize from here | 選定點之前保留,之後壓縮為摘要(可附 instructions) |
使用時機:
/compact 精準)。/clear + 手寫 brief 模板/clear 後立即貼入:
[任務背景]
我正在 {重構 / 實作 / 除錯} {具體目標}。
[已知事實]
- 相關檔案:A, B, C
- 已排除方案:方案 X(原因:...)
- 關鍵限制:{如 runtime 版本鎖定 / 不能改動某個外部相依}
[當前狀態]
{目前做到哪、下一步要做什麼}
這段 brief 取代原本整個對話,但品質遠高於 auto-compact 的摘要。
官方原話:「Will I need this tool output again, or just the conclusion?」
| 我之後需要... | 做法 |
|---|---|
| 每個檔案的完整 tool output | 主對話做(不能 subagent) |
| 只要結論 / 分析結果 | 派 subagent(fresh context window) |
| 不確定 | 先假設只要結論,若真的需要細節再用 Read 重讀 |
明確召喚 subagent 的句法(官方建議):
實作上對應到 Agent tool,並依任務選擇合適的 subagent 類型(如唯讀探索型、規劃型或審查型)。
/btw — 側邊問題不入 context官方機制:打 /btw {問題} — 答案顯示於可關閉 overlay,不進入對話歷史。適合「順便問一下」類問題,避免污染主流程 context。
當工作跨多個階段、由不同 agent 接力(如探索 → 規劃 → 實作 → 驗證),每個交接點都是 context 洩漏與污染的高風險處。原則:交接的是結論與必要事實,不是過程痕跡。
/rewind 或 /compact 掉試錯過程,避免污染下一階段。本 skill 載入後,Claude 在偵測下列情境時以問句提醒(不得擅自執行):
| 偵測訊號 | Claude 的提問模板 |
|---|---|
| 對話已累積相當長 | 「對話已累積相當長,要不要 /compact focus on ...?若有偏好的保留重點請告訴我」 |
| 同主題連續 2 次修正失敗 | 「這是第 3 次修同問題,context 可能被失敗痕跡污染。要不要 Esc Esc rewind 回失敗前再試?」 |
| 使用者訊息語意跳到無關領域 | 「這看起來是新任務(從 {舊任務} 跳到 {新任務}),要不要 /clear 重開?我可以先幫你整理一段 brief」 |
| 即將讀 >5 個檔案 | 「這段要讀很多檔案,要不要我派 subagent 處理只回報結論?」 |
| subagent 剛回報、主對話只用到結論 | 「subagent 的 tool output 之後還要用嗎?若只要結論可以 /compact focus on 結論 清掉」 |
提問規矩:同一提醒被使用者拒 1 次後,本對話中不再重提該動作(避免打擾)。
| Pattern | 症狀 | Claude 應做 |
|---|---|---|
| Kitchen sink session | 一任務混入無關提問後回到原任務 | 偵測到跳主題時提醒 /clear 或改用 /btw |
| Correcting over and over | 反覆糾正同錯誤,failed attempts 堆滿 context | 2 次失敗後提醒 /rewind |
| Infinite exploration | 未 scope 就叫 Claude 探索整個 codebase | 建議改用 subagent,給明確 scope |
| Over-specified CLAUDE.md | CLAUDE.md 過長導致重要規則被淹沒 | 提醒檢視可否精簡或轉為 skill/rule;分層判準見 references/config-layering.md |
/clear / /compact / /rewind(屬於使用者指令)。What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub kerryhuang/kerryhuang-plugins --plugin dev-flow17 skills in this plugin
/agent-orchestration適用於多階段 agent chain(≥2 個 agent 接力)、需要用 output file 交棒、把多步工作流展示給使用者確認、偵測到「工作完成」需清理階段性產物、跨 agent 任務串接決策。涵蓋 chain 規範、output 路徑、清理流程、工作流呈現格式、subagent 作為 context 隔離工具的使用時機。觸發語:「召喚某 agent」「多階段流程」「派 subagent」「工作流規劃」「agent 交棒」「orchestration」。/commit建立符合 Conventional Commits 規範的語義化提交訊息,支援 Git Flow + Semantic Release 工作流程。Use when creating git commits, "commit 這些變更", "幫我提交", "建立 commit", "semantic commit"./convention-first適用於在既有 codebase 撰寫任何新元件(class / module / handler / component 等)、審查程式碼是否引入新風格、判斷「該自己發揮還是模仿既有寫法」。先 grep 既有實作當樣板,禁止單方面引入新模式。慣例 > 創新。觸發語:「這樣寫對嗎」「有沒有既有寫法」「該模仿哪個」「引入新 pattern」「convention first」「follow existing pattern」。Other plugins' skills for the same job