Claude Code Mods 如何阻止 18 個 Claude Code 智能體推送至 main 或接觸機密資料
How I stop 18 Claude Code agents from pushing to main or touching secrets
作者以 Claude Code Mods 的 hooks 限制 18 個 AI 智能體在 7 個儲存庫中的操作,阻止它們推送至 main、接觸機密檔案或進入其他儲存庫。
18 AI agents. 7 repos. Now none of them can push to main, touch a secret, or wander into another repo.
Claude Code Mods made that possible.
Every time Claude is about to act, it fires an event first. Your hook runs before the action and can let it through, change it, or block it.
What I'm setting up
tool.call: keep each agent in its lane
An edit outside its worktree pauses and asks me. No answer means refused.
tool.check: no pushing to main
It checks the current branch and denies git push on main, even if a permission rule allows it.
tool.call: protect secrets
It blocks any read or edit of .env, keystores or .p8 files.
prompt.submit: add context automatically
Every prompt gets the repo, branch and ticket number added. No more repeating myself.
turn.step: watch costs
It logs token usage and cache hits on every model call.
Why it works
When a hook blocks something, Claude reads the reason and changes approach instead of just failing.
One gotcha
If a hook crashes, Claude Code skips it and runs the action anyway. Add a .catch that denies.
CLAUDE.md says what you want. Mods decide what's allowed.
來源:DEV Community · dev.to