SLOPSHOPPER

push-gate

Asks before every git push the model runs, in Claude Code's own question dialog: a click confirms that one command, anything else refuses it. The confirmed…

guardprocess
A shopper browsing a rack in a slop shop
README

push-gate

Asks before every git push the model runs. The question is Claude Code's own AskUserQuestion dialog: the full command, the repository, the branch and its upstream, how many commits go, and a warning for a force push or a protected branch (release, master, main). A click on «Пушить» lets that one call run. «Отмена», a typed answer, Esc or a session with no one to ask (claude -p) refuse it, and the model reads why.

Version: 0.2.0

What's New in 0.2.0

  • A confirmed command now runs from the mod itself, and its output reaches the model as the Bash call's result. Lifting a PreToolUse deny in tool.check stopped working in Claude Code 2.1.308: a managed-tier hook there hands the event past the user tier, so the click was asked for and then the push was denied anyway.
  • The command runs under bash -c in the session's working directory, not in the Bash tool's shell: a cd from an earlier Bash call does not carry over, so give the repository with git -C <path>. Ten minutes at most.

What's New in 0.1.1

  • A push is push as git's subcommand, not the word anywhere in the line: a path like core/push/…, a grep pattern or a commit message no longer opens the dialog.
  • The force and protected-branch warnings read only the push's own arguments: merge-base origin/release next to it is not a protected push.
  • The repository line expands -C "$R" from an R=… earlier in the same command and takes the -C of the push itself, not of the first git.
  • An inline alias (git -c alias.p=push p) still asks.

What's New in 0.1.0

  • The first release.

Installation

/plugin install push-gate --marketplace IvanLutsenko/awac-ai-agent-plugins

Requires Claude Code with function hooks (mods), 2.1.308 or later. This is early access: the hook API can change between releases.

What it asks about

  • Any Bash command where git, then its global options (-C <path>, -c <k=v>, --git-dir=…, --no-pager), then push stand in a row. It catches bash -c "git push", ( git push ), /usr/bin/git push, env git push, a quoted -C path, a push on the second line or after a backslash-newline, and a git alias set inline with -c alias.…. The word push in a path, a grep pattern or a commit message does not count.
  • glab … --push and gh pr create, which push on their own.
  • claude, codex or pi started with their guards off (--safe-mode, --bare, --dangerously-…).
  • A command over 2000 characters is refused outright: the dialog shows every command whole, so nothing can hide past its end.

Pairing with a PreToolUse guard

Alone, the mod refuses every push the person did not confirm. It is not a wall, though: a push from a script file, a git hook, an API call or another agent never passes through it. For a guard that also holds when mods are off (--safe-mode) or the mod is not installed, deny every push in a PreToolUse hook in settings.json:

# Same rule as GIT_PUSH in hooks/register.ts; keep the two in step.
read -r PUSH_RE <<'RE'
(^|[^[:alnum:]_.-])git(([[:space:]]+(-C|-c|--git-dir|--work-tree|--namespace)([[:space:]]+|=)("[^"]*"|'[^']*'|[^[:space:]]+)|[[:space:]]+--?[[:alnum:]_-]+(=[^[:space:]]*)?))*[[:space:]]+["']?push([[:space:];&|)"']|$)|(^|[^[:alnum:]_.-])git[[:space:]]([^;&|]*[[:space:]])?-c[[:space:]]*alias\.
RE
if printf '%s\n' "$CMD" | awk '{ if (sub(/\\$/, "")) printf "%s ", $0; else print }' | grep -qE "$PUSH_RE"; then
  deny 'Push only through the push-gate dialog.'
fi

A guard with a coarser rule than the mod's denies pushes the mod never asks about; a finer one lets them through unasked.

The mod does not lift that deny: on the click it runs the confirmed command itself and answers the call with its output, so PreToolUse and tool.check never see that one call, and the guard keeps denying every other push. The approval is the click itself, so there is nothing the model could write to forge it. The cost: a confirmed push runs outside the permission system, the auto mode classifier and any managed tool.check hook included; the click is the decision.

The server is the real boundary: protect the branches that matter (no force push, no deletion) on GitHub or GitLab.

Tests

claude plugin test plugins/push-gate
Source 1 files
hooks/register.ts 109 lines
1import type { EngineInterface, Register } from 'claude-code'
2
3const PUSH = 'Пушить'
4const MAX_SHOWN = 2000
5const PROTECTED = /\b(release|master|main)\b/
6
7// git, its global options (-C <path>, -c <k=v>, --git-dir=…, -P), then push as
8// the subcommand: `push` as a path segment (core/push/…) or a word in a grep
9// pattern or a commit message is not a push. The shape stays wide: bash -c,
10// subshells, /usr/bin/git, env prefixes, quoted -C paths, a push on a later
11// line or after a backslash-newline. Group 1: global options, group 2: the
12// push's own arguments up to the end of its command.
13// Mirror: ~/.claude/hooks/bash-footgun-guard.sh (PreToolUse deny); keep in step.
14const GIT_PUSH =
15  /(?:^|[^\w.-])git((?:\s+(?:-C|-c|--git-dir|--work-tree|--namespace)(?:\s+|=)(?:"[^"]*"|'[^']*'|\S+)|\s+--?[\w-]+(?:=\S*)?)*)\s+["']?push(?=$|[\s;&|)"'])([^;&|\n]*)/
16
17const unfold = (command: string) => command.replace(/\\\n/g, ' ')
18
19// Also a push hidden in an alias (`git -c alias.p=push p`), the tools that push
20// on their own, and child agents started with their guards off.
21export function needsConfirm(command: string): boolean {
22  const c = unfold(command)
23  return (
24    GIT_PUSH.test(c) ||
25    /(?:^|[^\w.-])git\s(?:[^;&|\n]*\s)?-c\s*alias\./.test(c) ||
26    /\bglab\b[^\n]*--push\b/.test(c) ||
27    /\bgh\s+pr\s+create\b/.test(c) ||
28    /\b(claude|codex|pi)\b[^\n]*--(safe-mode|bare|dangerously-[\w-]+)/.test(c)
29  )
30}
31
32// Only the push's own arguments: `merge-base origin/release` or `rm -rf` in a
33// neighbouring command is neither a protected branch nor a force.
34export function warnings(command: string, branch?: string): string[] {
35  const args = unfold(command).match(GIT_PUSH)?.[2] ?? command
36  const marks: string[] = []
37  if (/(^|\s)(--force|--force-with-lease|-[a-zA-Z]*f[a-zA-Z]*)(\s|=|$)|\s\+\S/.test(args)) marks.push('FORCE')
38  if (PROTECTED.test(args) || (branch !== undefined && PROTECTED.test(branch))) marks.push('защищённая ветка')
39  return marks
40}
41
42// Where the push runs: the -C path of the push itself, with $VAR / ${VAR} taken
43// from a VAR=value earlier in the same command; else the session's directory.
44// ponytail: an exported VAR or ~ stays as written and the branch line shows "?".
45export function repoDir(command: string): string | undefined {
46  const c = unfold(command)
47  const m = c.match(GIT_PUSH)?.[1].match(/-C\s+(?:"([^"]+)"|'([^']+)'|(\S+))/)
48  const dir = m == null ? undefined : (m[1] ?? m[2] ?? m[3])
49  return dir?.replace(/\$\{?(\w+)\}?/g, (raw, name: string) => {
50    const a = c.match(new RegExp(`(?:^|[\\s;&(])${name}=(?:"([^"]*)"|'([^']*)'|([^\\s;&|]*))`))
51    return a === null ? raw : (a[1] ?? a[2] ?? a[3])
52  })
53}
54
55async function git($: EngineInterface, cwd: string, ...args: string[]): Promise<string | undefined> {
56  try {
57    const run = await $.process.run(['git', ...args], { cwd, timeoutMs: 3000 })
58    return run.exitCode === 0 ? run.stdout.trim() : undefined
59  } catch {
60    return undefined
61  }
62}
63
64async function question($: EngineInterface, command: string): Promise<string> {
65  const cwd = repoDir(command) ?? (await $.session.cwd())
66  const branch = await git($, cwd, 'rev-parse', '--abbrev-ref', 'HEAD')
67  const upstream = await git($, cwd, 'rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}')
68  const ahead = upstream === undefined ? undefined : await git($, cwd, 'rev-list', '--count', '@{u}..HEAD')
69  const marks = warnings(command, branch)
70
71  return [
72    'Пушу?',
73    command,
74    '',
75    `Репо: ${cwd}`,
76    `Ветка: ${branch ?? '?'} → ${upstream ?? 'нет upstream'}${ahead === undefined ? '' : ` (коммитов впереди: ${ahead})`}`,
77    ...(marks.length > 0 ? [`ВНИМАНИЕ: ${marks.join(' · ')}`] : []),
78  ].join('\n')
79}
80
81// Up to 10 minutes, $.process.run's ceiling: a push over a slow link, gh pr create.
82const RUN_MS = 10 * 60 * 1000
83
84// The mod asks in tool.call and, on the click, runs the command itself and
85// answers with its output in place of next: PreToolUse and tool.check never
86// see a confirmed push, so a PreToolUse guard that denies every push stays
87// the backstop for sessions without the mod. Lifting that deny in tool.check
88// stopped working once a managed tier hook there began handing the event past
89// the user tier (CC 2.1.308). The click is the decision; nothing to forge.
90// ponytail: runs in the session's cwd under bash, not the Bash tool's shell;
91// a `cd` the model ran earlier in the Bash tool does not carry over.
92export const register: Register = on => {
93  on('tool.call', { tool: 'Bash' }, async ($, e, next) => {
94    if (!needsConfirm(e.command)) return next(e)
95    if (e.command.length > MAX_SHOWN) {
96      return { deny: `push-gate: the command is longer than ${MAX_SHOWN} characters and cannot be shown whole; split it.` }
97    }
98
99    const answer = await $.ui.ask(await question($, e.command), { options: [PUSH, 'Отмена'], header: 'push-gate' })
100    if (answer !== PUSH) return { deny: 'The person declined this push in the push-gate dialog.' }
101
102    const run = await $.process.run(['bash', '-c', e.command], { cwd: await $.session.cwd(), timeoutMs: RUN_MS })
103    const exit = run.exitCode === 0 ? '' : `${run.stderr === '' ? '' : '\n'}Exit code ${run.exitCode}`
104    return { result: { stdout: run.stdout, stderr: run.stderr + exit, interrupted: false } }
105  }).catch(($, e, next) =>
106    next.called ? next(e) : { deny: 'push-gate could not ask the person or run the push; push refused.' },
107  )
108}
109