# Safe Merge Loop: Cross-Model Code Review Gate

> Claude builds your change in an isolated git worktree; a different model (Antigravity or Gemini CLI) must answer exactly SAFE TO MERGE before anything reaches main. Fails closed, max 3 fix rounds, plain-English audit log. Windows + PowerShell 7.

Safe Merge Loop: Cross-Model Code Review Gate is a free AI agent skill on Agensi by ZAINSHAZ, in Code Quality & Review. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: Free
- Creator: [ZAINSHAZ](https://www.agensi.io/creators/zainshaz)
- Category: [Code Quality & Review](https://www.agensi.io/skills/code-quality-review)
- Version: 0.1.0
- Last updated: 2026-12-02
- Security: scan passed (2026-12-02); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/safe-merge-loop-cross-model-code-review-gate
- Tags: code-review, powershell, git, gemini, windows

## About this skill

A merge gate, not just a review. Claude Code builds your change in an isolated git worktree. A different model (Antigravity CLI or Gemini CLI) reviews the diff in read-only mode and must end with exactly `SAFE TO MERGE` or `NOT SAFE`. A PowerShell script reads that verdict, not the agent, and anything unclear counts as NOT SAFE.

### What you get
- **Main is never touched.** The skill shows you the merge commands; you run them.
- **Up to 3 fix rounds** (set 1–5), then it hands the problem to you.
- **A plain-English `REVIEW-LOG.md`** for every run, next to the exact diff, checker input and checker output.
- **Fails closed:** checker errors, timeouts, empty answers, edits by the checker, a changed reviewer prompt, or the gate phrase inside the diff all stop the run.
- **Built and tested on Windows** with PowerShell 7. No bash, no WSL.

### Why a second model
A model reviewing its own code shares its own blind spots. A reviewer from a different provider catches different bugs, and a gate it must pass beats advice you can ignore.

### Tested
Windows, Claude Code + Antigravity CLI 1.5.19. A normal run passed in 1 round; a round-cap run handed off correctly. Includes a made-up demo repo so you can try it in 2 minutes.

### Requirements
Windows, PowerShell 7 (`winget install --id Microsoft.PowerShell`), git, Claude Code, and one checker CLI installed and signed in: Antigravity CLI (`agy`, tested) or Gemini CLI (`gemini`, built from its documented flags, not yet tested with the real CLI).

### Network use
The helper script makes no network calls. The checker CLI you choose sends the reviewer prompt and the diff to its model provider (Google) under your own account. Claude Code sends your code to Anthropic as usual. Nothing asks for or stores API keys.

### Known limitations
Windows + PowerShell 7 only. One checker per run. The checker can be wrong, so disputed findings go to you. The Gemini CLI path is not yet tested with the real CLI.

Open source under the MIT license (repo: zain-zilla/safe-merge-loop on GitHub).

## Requires

- Runs on Windows only
- Git
- PowerShell 7
- Claude Code
- Antigravity CLI or Gemini CLI

Windows ships PowerShell 5.1; install 7 with: winget install --id Microsoft.PowerShell. Sign in to agy or gemini once before the first run. The checker CLI sends the diff to Google under your own account.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Safe Merge Loop: Cross-Model Code Review Gate skill from Agensi" and describe your task.
3. Your agent loads the skill from Agensi when it needs it. Nothing is downloaded.

## Frequently asked questions

### How does this skill keep AI changes away from my main branch?

The agent builds only inside a new git worktree on its own branch. A different model reviews the diff, and a PowerShell script (not the agent) reads its last line. Only the exact phrase SAFE TO MERGE passes. Even then, the skill only shows you the merge commands; you run them.

### What do I need installed?

Windows with PowerShell 7 (winget install --id Microsoft.PowerShell), git, Claude Code, and one checker CLI that you have signed in to once: Antigravity CLI (agy, tested) or Gemini CLI (gemini). No API keys are asked for or stored.

### What files and logs does a run create?

A worktree folder next to your repo (<repo>-sml-<slug>) and a run folder (sml-runs\<repo>-<slug>) outside every repo. The run folder holds REVIEW-LOG.md (plain English, one entry per round), the exact diff, the checker's input and output, the locked reviewer prompt and state.json.

### What happens if the checker keeps saying NOT SAFE?

The agent fixes only the listed reasons and checks again, up to the round cap (3 by default, 1–5 allowed). Then it stops and hands the problem to you with the open reasons, the log and the worktree kept. If the agent disagrees with a finding, it marks it disputed instead of changing code, and you decide.

### How do I start a run?

In Claude Code, inside your repo, say: "Use the safe-merge-loop skill. Checker: agy. Slug: fix-date-sort. Task: <what to build or fix>. <how to check it, e.g. the tests that must pass>." Optional: Max rounds, Base branch, Timeout. The repo must have no uncommitted changes when you start.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
