在 AI 輔助開發的時代,我們都希望 AI 能幫我們寫出完美的程式碼。但現實往往是:我們花了大量時間在糾正 AI 的錯誤、重複提醒專案的規範,甚至要不斷將偏離軌道的 AI 拉回正題。
ClaudeCode之父使用的結構化 CLAUDE.md 檔案。這份檔案號稱能讓開發者獲得「10 倍工程師」的產出效率,而它的來頭絕對值得你留意。
源自 Claude Code 創作者的真實最佳實踐
這份 CLAUDE.md 並非網友們憑空想像的 Prompt 大全,它的核心內容源自 Anthropic 內部團隊(也就是開發 Claude 的公司)每日實際在使用的最佳實踐與工作流。
Claude Code 的創作者 Boris Cherny 在 X 上分享了他們團隊是如何與 AI 協作的。隨後,熱心的開發者將這些零散的 Threads 整理成了一份開箱即用的 CLAUDE.md 檔案,讓你能夠直接丟進任何專案的根目錄中。
CLAUDE.md 的 6 大核心引擎
只要在專案中加入這份檔案,就能為你的 AI 助手(特別是 Claude)注入強大的系統化能力。它涵蓋了以下六個關鍵模組:
-
工作流程編排 (Workflow orchestration): 不再是走一步算一步,AI 會學著宏觀規劃、執行並管理複雜的開發任務。
-
子代理策略 (Subagent strategy): 面對龐大需求,AI 會自動將任務拆解,宛如指派多個虛擬工程師分頭處理特定的子任務,大幅提升效率。
-
自我完善迴圈 (Self-improvement loop): 賦予 AI 覆盤能力,在產出過程中不斷自我檢查並優化程式碼品質。
-
完成前的驗證 (Verification before done): 告別「寫完就跑」的 AI!強制要求 AI 在宣告任務完成或提交前,必須進行嚴謹的測試與驗證。
-
自主修復 Bug (Autonomous bug fixing): 當遇到錯誤時,系統能引導 AI 主動偵測問題、分析 Log 並自行嘗試修復。
-
核心原則 (Core principles): 為 AI 設定鐵律,確保所有產出都嚴格遵守你的專案架構、編碼規範與基礎準則。
這份設定檔最迷人的地方,在於它是一個會產生複利效應的系統 (Compounding System)。
在傳統的 AI 協作中,你今天糾正了 AI 的錯誤,明天它可能還是會犯一樣的錯。但透過這套機制,你所做的每一次糾正,都會被系統捕捉並轉化為一條新的「規則」。
這意味著:
-
系統會主動從你的回饋中學習。
-
隨著專案推進,Claude 犯下相同錯誤的機率會呈指數級下降。
-
它會變得越來越像一個完全懂你習慣、默契十足的專屬資深工程師。
如果你每天的開發工作都高度依賴 AI 輔助,那麼建立一個專屬的 CLAUDE.md 絕對能為你省下海量的除錯與溝通時間。與其每天重複輸入相同的提示詞,不如一勞永逸,讓頂尖團隊的工作流成為你的預設開發環境。
完整的 calude.md 如下,可以直接複製回去使用。
## Workflow Orchestration
### 1. Plan Node Default
- Enter plan mode for ANY non-trivial task (3+ steps or architectural decisions)
- If something goes sideways, STOP and re-plan immediately - don't keep pushing
- Use plan mode for verification steps, not just building
- Write detailed specs upfront to reduce ambiguity
### 2. Subagent Strategy
- Use subagents liberally to keep main context window clean
- Offload research, exploration, and parallel analysis to subagents
- For complex problems, throw more compute at it via subagents
- One tack per subagent for focused execution
### 3. Self-Improvement Loop
- After ANY correction from the user: update `tasks/lessons.md` with the pattern
- Write rules for yourself that prevent the same mistake
- Ruthlessly iterate on these lessons until mistake rate drops
- Review lessons at session start for relevant project
### 4. Verification Before Done
- Never mark a task complete without proving it works
- Diff behavior between main and your changes when relevant
- Ask yourself: "Would a staff engineer approve this?"
- Run tests, check logs, demonstrate correctness
### 5. Demand Elegance (Balanced)
- For non-trivial changes: pause and ask "is there a more elegant way?"
- If a fix feels hacky: "Knowing everything I know now, implement the elegant solution"
- Skip this for simple, obvious fixes - don't over-engineer
- Challenge your own work before presenting it
### 6. Autonomous Bug Fixing
- When given a bug report: just fix it. Don't ask for hand-holding
- Point at logs, errors, failing tests - then resolve them
- Zero context switching required from the user
- Go fix failing CI tests without being told how
## Task Management
1. **Plan First**: Write plan to `tasks/todo.md` with checkable items
2. **Verify Plan**: Check in before starting implementation
3. **Track Progress**: Mark items complete as you go
4. **Explain Changes**: High-level summary at each step
5. **Document Results**: Add review section to `tasks/todo.md`
6. **Capture Lessons**: Update `tasks/lessons.md` after corrections
## Core Principles
- **Simplicity First**: Make every change as simple as possible. Impact minimal code.
- **No Laziness**: Find root causes. No temporary fixes. Senior developer standards.
- **Minimat Impact**: Changes should only touch what's necessary. Avoid introducing bugs.