Claude Code 教學:把硬性規則移到 settings.json,讓 Hook 用 exit 2 擋下操作
Move the NEVER lines out of your CLAUDE.md and into settings.json (and make your hooks exit 2)
重點導讀
只把「絕對不要讀 .env」寫在 CLAUDE.md,Claude Code 仍可能把它當成可自行判斷的指引。
- 作者整理 Anthropic 檔案與 Claude Code 團隊分享的做法,建議把讀取機密、保護資料庫遷移檔等硬性規則放進 settings.json 和 Hook。
- Hook 遇到要阻止的操作時要回傳 exit 2,回傳 exit 1 則不會擋下操作。文章也提醒,許可權規則無法看見指令執行後做了什麼,因此保護機密時還要搭配 sandbox,並留意 Hook 或 MCP 伺服器不受 sandbox 保護。
AI 伴隨問答
針對這篇報導有疑問?可直接點選快捷問題或向 AI 追問背景脈絡與技術細節:
信源出處dev.to
Move the NEVER lines out of your CLAUDE.md and into settings.json (and make your hooks exit 2)
本文為 888news 精選之重點導讀。若需閱讀作者完整原文、技術細節與官方討論,請前往原始網站。
來源: Dev.to Top Tech (dev.to)
開啟原文