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
Skills and agents for working with a local Git clone over the git wire protocol, and for authoring and running the pre-commit hooks that guard it.
Install
apm is the only supported install path (ADR-0024). Declare this package in the consuming project's apm.yml:
dependencies:
apm:
- git: https://git.rkdr.net/Mortis/Holocron.git
path: plugins/git
Then:
apm install
The entry above is unpinned and tracks the remote's default branch. To pin a release, add ref: git-v<x.y.z> after path:; see Pinning a plugin to a release. Registering the catalogue instead (apm marketplace add https://git.rkdr.net/Mortis/Holocron.git --name holocron) gets you the git@holocron short name, but writes to ~/.apm/marketplaces.json at user scope; the git+path object needs nothing beyond the manifest.
Native plugin installs do not work. This package ships no per-plugin manifest and no flat content directories, so a host that installs it natively gets zero skills and zero agents — and Claude Code raises no error while doing it (ADR-0024).
Conventions
Skills here run local git commands through the org's rtk wrapper. When a command is prefixed, when it stays bare, and why some executable commands must stay bare are all decided by ADR-0023 (docs/adr/0023-rtk-prefix-marks-executable-commands-only.md), which is repo-wide and not specific to this plugin. check-rtk-prefix enforces the part of it that is machine-decidable.
Installing this plugin without rtk? Every prefixed command is a plain git invocation with a word in front of it — drop the rtk and it is correct.
Contents
| Component | Path | Description |
|---|---|---|
| Skills | .apm/skills/ |
git-commits, git-branches, git-history, git-remotes, git-submodules, git-workflow, git-worktrees, pc-author, pc-run |
| Agents | .apm/agents/ |
git-orchestrate |
| Hooks | .apm/hooks/ |
refuse-push-to-main.py, see Push-to-main hook |
.apm/ is the authoring source and the only thing apm deploys (ADR-0024).
Push-to-main hook
On Claude Code, a PreToolUse hook refuses a Bash git push that can update main:
- an explicit destination:
main,HEAD:main,<branch>:main,refs/heads/main, or deletingmain - a bare
git push,HEADor@whilemainis checked out - a bulk push:
--all,--mirror,:, or a wildcard refspec that coversmain - any of these with
--forceor--force-with-lease
Pushes to other branches, tag pushes and --dry-run go through. apm also deploys the files to Copilot and Codex, where the hook does nothing.
Limits
The hook is a guardrail against accidents. Server-side branch protection is the real control. If the hook itself fails, the push goes through. It does not see:
- git aliases, shell variables such as
$BRANCH, scripts,bash -c, command substitution inside double quotes, or pushes made through an MCP server - git config that redirects a push (
push.default=upstream,remote.<name>.push) - a push behind a wrapper option that takes a separate value, such as
sudo -u <user>orenv -u <name> - a bare
git push,HEADor@when the branch is not known: after a branch change in the same command other than a literalgit switch mainorgit checkout main, after acdto a path that is not literal, or with--git-dirorGIT_DIR=
Opt-out
To allow pushes to main, set the variable under env in .claude/settings.json, or in .claude/settings.local.json for yourself only:
{
"env": {
"GIT_ALLOW_PUSH_TO_MAIN": "1"
}
}
Claude Code puts env values into its own environment, which hooks inherit. Setting the variable inside the command (GIT_ALLOW_PUSH_TO_MAIN=1 git push) has no effect. After you remove the setting, restart Claude Code for the hook to refuse again.
Approval
The hook is an executable primitive, so whether it deploys depends on the executables: block in the consuming project's apm.yml:
- No
executables:block: hooks deploy without approval. - With an
executables:block: the hook is parked until it is granted. Grant it in one of two ways, then runapm installand commit theexecutablesentry:-
apm approvewrites the entry and pins it to the hook's content, so a later change to the script needs approval again. -
A hand-written entry under the full package identity is not pinned:
executables: allow: git.rkdr.net/Mortis/Holocron/plugins/git: hooks: true
-
The first apm approve in a project creates the block and so turns the gate on. The next install then parks every other package's unapproved executables.
Author
Defame1297