響應定製
說明 GitHub Copilot custom instructions、prompt files、AGENTS.md 類檔案和優先順序如何影響回答。
響應定製(response customization)解決的是“每次都要重新解釋專案約定”的問題。GitHub 官方文件把它描述為給 Copilot 提供個人偏好、團隊工作方式、工具和專案上下文,讓回答更貼合真實環境。
定製不是越多越好。它會隨每次相關請求進入上下文,應該只寫穩定、廣泛適用、不會洩露敏感資訊的規則。
閱讀目標:讀完本章,你應該能區分 personal、repository、organization、path-specific 和 agent instructions,並知道它們的優先順序。
1. 定製型別
官方文件列出幾類常用定製方式:
- Personal instructions:個人偏好,適用於 GitHub.com 上的 Copilot Chat。
- Repository-wide custom instructions:儲存庫級規則,寫在
.github/copilot-instructions.md。 - Path-specific instructions:路徑級規則,寫在
.github/instructions/下的*.instructions.md檔案。 - Agent instructions:類似儲存庫規則,但不是所有 Copilot 功能都支援;檔名可以是
AGENTS.md、CLAUDE.md或GEMINI.md。 - Organization custom instructions:組織級規則,由 organization owner 設定,面向 Copilot Business 或 Copilot Enterprise 訂閱。
- Prompt files:工作區裡的 Markdown prompt 檔案,用於複用某類 Chat 請求。
flowchart TD
Request["Copilot request"] --> Personal["Personal instructions"]
Request --> Repo["Repository instructions"]
Repo --> Path[".github/instructions/*.instructions.md"]
Repo --> Wide[".github/copilot-instructions.md"]
Repo --> Agent["AGENTS.md / CLAUDE.md / GEMINI.md"]
Request --> Org["Organization instructions"]
Request --> Prompt["Prompt file"]
Personal --> Response["Customized response"]
Path --> Response
Wide --> Response
Agent --> Response
Org --> Response
Prompt --> Response
style Personal fill:#dbeafe,stroke:#2563eb,stroke-width:2px
style Repo fill:#fef3c7,stroke:#d97706,stroke-width:2px
style Response fill:#dcfce7,stroke:#16a34a,stroke-width:2px
2. 優先順序
官方頁面說明,多種 instructions 可以同時適用於一次請求。優先順序從高到低是:
- Personal instructions。
- Path-specific instructions。
- Repository-wide
.github/copilot-instructions.md。 - Agent instructions,例如
AGENTS.md。 - Organization custom instructions。
注意:優先順序高並不代表低優先順序完全不生效。相關 instructions 都可能提供給 Copilot;衝突越少,結果越穩定。
3. 什麼時候寫進 instructions
適合寫:
- 專案架構和目錄職責。
- 穩定技術堆疊、框架和版本約束。
- 命名、錯誤處理、測試風格、lint 規則。
- 安全紅線,例如不能記錄 token。
- 團隊固定語言和回答格式偏好。
不適合寫:
- 一次性任務說明。
- 具體 bug 的臨時方案。
- 金鑰、賬號、內網地址、客戶資訊。
- 過期遷移步驟。
- 互相沖突的多套規範。
4. 路徑級規則更適合複雜儲存庫
大型儲存庫不要把所有內容塞進一個儲存庫級檔案。官方文件說明,path-specific instructions 可以避免 repository-wide instructions 過載。
例子:
.github/copilot-instructions.md
.github/instructions/frontend.instructions.md
.github/instructions/backend.instructions.md
.github/instructions/tests.instructions.md這樣前端、後端和測試可以有不同要求,Copilot 不需要每次都讀無關規則。
5. Organization instructions 的邊界
官方頁面說明,organization custom instructions 當前主要支援 GitHub.com 上的 Copilot Chat、Copilot code review 和 Copilot cloud agent。它適合統一組織偏好,例如語言、安全知識庫、回答風格。
組織級規則不應該替代儲存庫規則。組織級寫原則,儲存庫級寫專案事實,路徑級寫區域性約束。
6. 寫法原則
有效 instructions 應該短、獨立、可長期複用。建議包含:
- 專案用途和核心目標。
- 重要目錄結構。
- 編碼標準和命名約定。
- 關鍵框架、庫和版本。
- 測試、構建和審查要求。
不要寫成長篇教程。Copilot code review 對 custom instruction file 還有讀取長度限制;官方文件提示 code review 只讀取每個 custom instruction file 的前 4,000 字元,這個限制不適用於 Copilot Chat 或 cloud agent。
深讀:為什麼定製規則會降低也會放大風險
好的 instructions 會減少重複解釋,讓 Copilot 更貼合專案;壞的 instructions 會把錯誤規則自動注入所有任務。最危險的是過期規則和衝突規則,因為使用者很難在每次回答裡察覺它們被使用了。
所以 instructions 需要像程式碼一樣維護:有 owner、有 review、有刪除機制,不把一次性經驗永久化。
本章自檢
完成本章後,用這 4 個問題檢查:
- 這條規則是個人偏好、儲存庫事實、路徑約束,還是組織原則?
- 它是否會反覆適用,而不是一次性任務?
- 它是否和已有 instructions 衝突?
- 它是否包含敏感資訊、過期事實或不可驗證口號?
透過標準:你能把穩定規則沉澱進正確層級,並把臨時任務留在 prompt 或 issue 裡。
官方來源
- About customizing GitHub Copilot responses —— 官方響應定製頁,覆蓋 custom instructions、prompt files、優先順序和寫法原則。
- Customization cheat sheet —— 官方定製速查表,用於核對不同定製入口的適用場景。
- Support for different types of custom instructions —— 官方支援矩陣,用於核對不同 Copilot 功能讀取哪些 instructions。