feat(git): add a Claude Code hook that refuses git push to main #178

Open
opened 2026-11-15 22:02:00 +00:00 by Claude · 0 comments
Owner

What

Add a hook primitive to plugins/git that a consumer deploys with apm install (Claude target: merged into .claude/settings.json, script under .claude/hooks/<pkg>/). On a PreToolUse Bash call, it refuses a git push whose target is main, covering:

  • git push while on main with no refspec,
  • git push <remote> main, HEAD:main, <branch>:main, refs/heads/main,
  • --force / --force-with-lease variants of the above.

It allows pushes to any other branch and tags.

Why

Consumer repositories protect main on the server, so the push fails anyway; the hook makes an agent learn that before the round-trip, and keeps it from retrying with variations.

Notes

  • Executable primitive: consumers allow it with apm approve and commit the executables entry in their apm.yml; say so in the plugin README.
  • Generic only: no repository-specific guards in this plugin.
  • Test the refspec cases above, allowed and refused.
## What Add a hook primitive to `plugins/git` that a consumer deploys with `apm install` (Claude target: merged into `.claude/settings.json`, script under `.claude/hooks/<pkg>/`). On a `PreToolUse` Bash call, it refuses a `git push` whose target is `main`, covering: - `git push` while on `main` with no refspec, - `git push <remote> main`, `HEAD:main`, `<branch>:main`, `refs/heads/main`, - `--force` / `--force-with-lease` variants of the above. It allows pushes to any other branch and tags. ## Why Consumer repositories protect `main` on the server, so the push fails anyway; the hook makes an agent learn that before the round-trip, and keeps it from retrying with variations. ## Notes - Executable primitive: consumers allow it with `apm approve` and commit the `executables` entry in their `apm.yml`; say so in the plugin README. - Generic only: no repository-specific guards in this plugin. - Test the refspec cases above, allowed and refused.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mortis/Holocron#178