The git plugin now ships a PreToolUse Bash hook that refuses a git push whose destination is main. Pushes to other branches and tags go through.
Behaviour
Refused: explicit destinations (main, HEAD:main, feat:main, refs/heads/main), deletes, bulk pushes (--all, --mirror, :, wildcard refspecs), and a bare push, HEAD or @ while on main. Force variants, rtk git push and git -C <dir> push are covered too.
Claude Code only: apm also deploys the hook to Copilot and Codex, where the script exits 0 without checking anything.
If the hook fails, the push goes through. This is a guardrail; server-side branch protection is the real control.
Opt-out: set GIT_ALLOW_PUSH_TO_MAIN=1 under env in the Claude Code settings. Writing it inline in the command has no effect.
delivery depends on git, so its consumers get the hook too. ADR-0032 has a short amendment recording that git ships its own guardrail hook.
Known gaps
The plugin README lists the limits. The last review found these, which it does not list yet:
A directory change after git checkout main can let a bare push to main through, for example git checkout main && git pull && cd sub && git push.
Less common ways of leaving main in the same command, such as a git alias or git stash branch, can cause a wrong refusal. Pushing the branch by name avoids it.
Nested double quotes inside "$(...)" can be misread and cause a wrong refusal.
nice git push origin main is let through.
Verification
tests/test-git-push-main-hook.sh: 180 passed
tests/run-tests.sh --strict: 26 suites passed
All pre-commit and pre-push hooks passed. This repo has no forge CI.
Not tested: the hook in a live Claude Code session, which needs the merge first, and behaviour in Copilot or Codex sessions.
After merge
Commit the refreshed apm.lock.yaml and deployed hook files after the next session start on main.
Cut the git-v1.4.0 release tag, with the maintainer's approval.
Closes #178
The `git` plugin now ships a `PreToolUse` Bash hook that refuses a `git push` whose destination is `main`. Pushes to other branches and tags go through.
## Behaviour
- **Refused:** explicit destinations (`main`, `HEAD:main`, `feat:main`, `refs/heads/main`), deletes, bulk pushes (`--all`, `--mirror`, `:`, wildcard refspecs), and a bare push, `HEAD` or `@` while on `main`. Force variants, `rtk git push` and `git -C <dir> push` are covered too.
- **Claude Code only:** apm also deploys the hook to Copilot and Codex, where the script exits 0 without checking anything.
- **If the hook fails,** the push goes through. This is a guardrail; server-side branch protection is the real control.
- **Opt-out:** set `GIT_ALLOW_PUSH_TO_MAIN=1` under `env` in the Claude Code settings. Writing it inline in the command has no effect.
`delivery` depends on `git`, so its consumers get the hook too. ADR-0032 has a short amendment recording that `git` ships its own guardrail hook.
## Known gaps
The plugin README lists the limits. The last review found these, which it does not list yet:
- A directory change after `git checkout main` can let a bare push to `main` through, for example `git checkout main && git pull && cd sub && git push`.
- Less common ways of leaving `main` in the same command, such as a git alias or `git stash branch`, can cause a wrong refusal. Pushing the branch by name avoids it.
- Nested double quotes inside `"$(...)"` can be misread and cause a wrong refusal.
- `nice git push origin main` is let through.
## Verification
- `tests/test-git-push-main-hook.sh`: 180 passed
- `tests/run-tests.sh --strict`: 26 suites passed
- All pre-commit and pre-push hooks passed. This repo has no forge CI.
Not tested: the hook in a live Claude Code session, which needs the merge first, and behaviour in Copilot or Codex sessions.
## After merge
- Commit the refreshed `apm.lock.yaml` and deployed hook files after the next session start on `main`.
- Cut the `git-v1.4.0` release tag, with the maintainer's approval.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
An agent on main can push straight to it when the server does not protect the branch. The git
plugin now ships a Claude Code hook that refuses such a push before it runs. It fails open, does
nothing on other runtimes, and has an opt-out read only from the hook's own environment.
Closes: #178
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Review found pushes refused after `gh pr checkout` or `git branch -m`, and pushes to main allowed
after `git switch main` or `cd <repo>`. The hook now follows literal branch and directory changes
and treats any other as unknown. Heredoc stripping is linear and handles several per line.
Refs: #178
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
`git rebase <upstream> <branch>` checks out <branch>, so a later bare push was refused as if main
were still checked out. Pushes through xargs get refspecs the hook cannot see, so only an explicit
main is refused there.
Refs: #178
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Closes #178
The
gitplugin now ships aPreToolUseBash hook that refuses agit pushwhose destination ismain. Pushes to other branches and tags go through.Behaviour
main,HEAD:main,feat:main,refs/heads/main), deletes, bulk pushes (--all,--mirror,:, wildcard refspecs), and a bare push,HEADor@while onmain. Force variants,rtk git pushandgit -C <dir> pushare covered too.GIT_ALLOW_PUSH_TO_MAIN=1underenvin the Claude Code settings. Writing it inline in the command has no effect.deliverydepends ongit, so its consumers get the hook too. ADR-0032 has a short amendment recording thatgitships its own guardrail hook.Known gaps
The plugin README lists the limits. The last review found these, which it does not list yet:
git checkout maincan let a bare push tomainthrough, for examplegit checkout main && git pull && cd sub && git push.mainin the same command, such as a git alias orgit stash branch, can cause a wrong refusal. Pushing the branch by name avoids it."$(...)"can be misread and cause a wrong refusal.nice git push origin mainis let through.Verification
tests/test-git-push-main-hook.sh: 180 passedtests/run-tests.sh --strict: 26 suites passedNot tested: the hook in a live Claude Code session, which needs the merge first, and behaviour in Copilot or Codex sessions.
After merge
apm.lock.yamland deployed hook files after the next session start onmain.git-v1.4.0release tag, with the maintainer's approval.🤖 Generated with Claude Code
https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi