New Tool Radar

AI Agents & Automation

How to Block a Claude Code Subagent From Running Git Push

Add a permissions.deny rule for git push in Claude Code settings so a subagent can run tests and builds but cannot push.

Schematic diagram with three steps: Open the settings file, Add the deny rule, then Test a push attempt.

Permission rules, not disallowedTools, are the right tool for blocking a single command. A disallowedTools entry with a specifier such as Bash(git push *) removes the whole Bash tool, not only the matching commands. A permissions.deny rule blocks the one command and keeps Bash for tests and builds.

Before you start

You need a Claude Code project with a .claude/settings.json file you can edit. Decide the exact command to block: git push is the usual one, because a push publishes work.

Add the deny rule to the settings file

Open .claude/settings.json and add a permissions block with a deny list containing Bash(git push *). The rule covers the main conversation and every subagent, so one entry protects the whole project. Keep Bash itself allowed: the subagent still needs it for tests and builds.

Test the push and a normal command

Ask the subagent to run git push origin main and check it is blocked, then ask it to run the test suite and check that works. If both are blocked, the rule was written as a tool denial instead of a permission rule, and the settings file needs the permissions form.

Worked example: Permission check for a fictional shop project

Maple Shop is a fictional online shop. Its settings block git push for all agents. The table shows the test.

Command Allowed? Why
git push origin main No A push publishes work
npm test Yes Tests are safe to run
git status Yes Reading status changes nothing

Expected result (UNTESTED): the push is refused and the test suite runs. We checked the Claude Code subagents guide, which describes the permissions.deny rule and the disallowedTools trap, but we did not edit settings on this machine.

Limits

A deny rule is a guardrail, not a sandbox: the permissions docs list forms the pattern does not catch, such as git -C . push origin main. Treat it as one layer, and keep pushes behind a human review for shared branches.

Sources

See all