DEV Community

Ahsan Ali
Ahsan Ali

Posted on

How I stop 18 Claude Code agents from pushing to main or touching secrets

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.

Top comments (1)

Collapse
 
manojkagitha profile image
Manoj Kumar Kagitha •

The crashed-hook gotcha is the part worth the read. A safety control that silently fails open is worse than no control, so the .catch that denies is the most important line in the whole setup.