Claude.md 的使用與優點


基本設置與自訂

  • 建立 CLAUDE.md 文件

    • 放在專案根目錄、子目錄、父目錄或家目錄(~/.claude/CLAUDE.md),Claude 會自動讀取。

    • 沒有固定格式,重點是簡潔、易讀,內容可涵蓋指令、規範、流程、環境設定等。

    • 可用 /init 指令自動產生初始 CLAUDE.md

  • 持續優化 CLAUDE.md

    • 隨時根據專案需求與 Claude 的表現調整內容。

    • 可用 # 指令快速新增內容,並將變更納入 git 版本控制。

    • 強調重要規範可用「IMPORTANT」等字眼。

  • 管理 Claude 的工具許可

    • 可用「Always allow」、/permissions 指令、手動編輯設定檔或 CLI 參數調整允許的工具,確保安全與便利。
  • 整合 GitHub CLI

    • 安裝 gh CLI,讓 Claude 能自動處理 GitHub 相關操作(如 PR、issue、留言等)。

CLAUDE.md 內容對開發的幫助

  1. 常用指令與工具說明

    • 讓 Claude 知道專案常用的 bash 指令(如 build、test、deploy),能自動協助執行或解釋。

    • 例:

      - npm run build: Build the project
      - npm run typecheck: Run the typechecker
      
      
  2. 程式風格與規範

    • 明確告訴 Claude 你的 code style(如用 ES modules、不用 CommonJS),Claude 產生的程式碼會自動符合團隊標準。

    • 例:

      - Use ES modules (import/export) syntax, not CommonJS (require)
      - Destructure imports when possible
      
      
  3. 測試與驗證流程

    • 說明怎麼跑測試、什麼時候要 typecheck,Claude 可以自動幫你檢查或提醒。

    • 例:

      - Be sure to typecheck when you’re done making a series of code changes
      - Prefer running single tests, and not the whole test suite, for performance
      
      
  4. 專案工作流程與規則

    • 包含分支命名、合併策略、commit message 格式等,Claude 可以協助自動化這些流程。

    • 例:

      - Branch naming: feature/xxx, bugfix/xxx
      - Prefer merge over rebase
      
      
  5. 開發環境設定

    • 指定要用的 Python 版本、編譯器、依賴安裝方式等,Claude 能協助新成員快速建好環境。

    • 例:

      - Use pyenv with Python 3.10
      - Install dependencies with poetry
      
      
  6. 專案特殊注意事項或警告

    • 記錄容易踩雷的地方或常見錯誤,Claude 可以主動提醒或避免重複犯錯。

    • 例:

      - IMPORTANT: Do not run migration scripts on production DB
      - WARNING: The config file is overwritten on every deploy
      
      
  7. 常見問題與解法

    • FAQ 形式的說明,Claude 可以直接用來回答新手問題。