feat(hooks): require human approval before git push - #81
Merged
Conversation
Add a Copilot preToolUse command hook that forces an explicit, interactive approval before the agent runs any `git push`. Local commits stay fully rewritable (amend/reset/rebase) until pushed, so `git push` is the first irreversible step to a remote — the right place for a human checkpoint. The hook reads the tool invocation on stdin and, when a shell tool contains a `git push`, emits `permissionDecision: "ask"` so the CLI prompts the user; all other tool calls fall through untouched. It always exits 0 because preToolUse command hooks are fail-closed (a non-zero exit would deny the call). Ships enabled; disable with SKIP_PUSH_APPROVAL=true. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a Copilot
preToolUsecommand hook that forces an explicit, interactive human approval before the agent runs anygit push..apm/hooks/git-push-approval.json— the hook definition (uses thebashcommand key, liketool-guardian).scripts/git-push-approval/require-push-approval.sh— the guard script.Why here (why
git push?)A local commit is fully rewritable —
git commit --amend,git reset,git rebaseall work freely until it's pushed.git pushis the first irreversible step that publishes work to a remote, so it's the correct chokepoint for a human checkpoint.How it works
toolName/toolArgs, and the VS Codetool_name/tool_inputvariant).bash/powershell/shell) contains agit … push, it emits{"permissionDecision":"ask", ...}so the CLI prompts the user to approve. Every other tool call produces no decision and flows through the normal permission path.preToolUsecommand hooks are fail-closed (a non-zero exit denies the call), so the script only ever upgrades the decision toaskand never blocks unrelated tools.; & |break the match), sogit status && npm run pushdoes not prompt;git push,git push origin main,git -C /repo push, and/usr/bin/git --no-pager pushdo.jqis used when present with a pure-grep/sed fallback when it isn't.Design choice: enabled by default
Unlike
tool-guardian(a heavy blocker shipped withdisableAllHooks), this hook ships enabled — an approval prompt is low-friction and being active is the entire point. Disable per session withSKIP_PUSH_APPROVAL=true.Validation
shellcheck(repo's strict.shellcheckrc) andshfmt(per.editorconfig): clean.tests/validate-prompts.shandscripts/generate-index.sh: pass, no index drift (hooks aren't indexed).ask; commits, separators,legit push, non-shell edits, and the disable switch → allow. Includes a no-jqfallback run.Ref: Copilot hooks reference.