# How to Stop AI Agents From Force-Pushing to Main

2 min read · Works with Claude Code, Cursor, Codex, and any MCP agent

TL;DR: Your AI agent will force-push to main unless you physically prevent it. One PreToolUse hook + two minutes = impossible.

## The problem

You write `never force-push to main` in your CLAUDE.md. Your agent reads it. Then it force-pushes to main anyway. Prompt rules are suggestions. Agents can and do ignore them when the context window fills up or when a chain of reasoning overrides the instruction.

Real example: A developer lost 14 commits when their Claude Code agent ran `git push --force origin main` during a rebase. The CLAUDE.md said "never force-push." The agent did it anyway.

## Why prompt rules fail

- Context overflow — as the conversation grows, early instructions get compressed or dropped
- Reasoning override — the agent decides force-push is the "correct" solution to a merge conflict
- No enforcement layer — nothing physically stops the tool call from executing

## The fix: a pre-action check

A pre-action check intercepts the tool call before it executes. It pattern-matches the command against known-bad actions and blocks them. The agent cannot bypass it because the check runs outside the agent's control, at the MCP hook layer.

### Step 1: Install ThumbGate

    npx thumbgate init

This auto-detects your agent (Claude Code, Cursor, etc.) and configures the PreToolUse hook.

### Step 2: Give feedback

The next time your agent tries a force-push (or anything dangerous), give it a thumbs-down with context:

    👎 "Never force-push to main. This destroyed 14 commits last time."

### Step 3: Check auto-generates

ThumbGate captures the feedback, matches it against the tool call pattern, and auto-generates a prevention rule. After repeated failures (configurable), it promotes to a hard check:

    # Auto-generated prevention rule
    pattern: "git push --force"
    target_branch: "main"
    action: BLOCK
    reason: "Force-push to main blocked — destroyed 14 commits (2026-03-15)"

### Step 4: Check fires on every future attempt

The PreToolUse hook checks every `Bash` tool call. If it matches `git push --force` targeting `main`, the action is blocked before execution. The agent receives a rejection with the reason and adapts.

Key difference: Prompt rules ask nicely. Pre-action checks physically block. The check runs at the hook layer, outside the agent's reasoning chain, so it cannot be overridden by context or chain-of-thought.

## What about other dangerous actions?

The same pattern works for any tool call you want to prevent:

- `DROP TABLE` on production databases
- `rm -rf` on project directories
- Committing `.env` files with secrets
- Running untested migrations on prod
- Skipping test suites before deploy

Every thumbs-down teaches the system. Thompson Sampling adapts check sensitivity: high-risk patterns get strict enforcement, low-risk ones stay relaxed.

## Try it now

One command. Your agent stops repeating mistakes today.

$ npx thumbgate init

### Related guides

The Vibe Coding Safety Net You Are Missing → MCP Pre-Action Checks Explained → Full Setup Guide →
Try it now: `npx thumbgate init` GitHub →