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 and prompt rules won't stop it. A PreToolUse hook flags and logs the attempt by default, and hard-blocks it in strict mode (THUMBGATE_STRICT_ENFORCEMENT=1). Two minutes to wire up.

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

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. By default it flags and logs the attempt so you see it; in strict mode (THUMBGATE_STRICT_ENFORCEMENT=1) it hard-blocks the call at the MCP hook layer, outside the agent's reasoning chain.

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: WARN            # flags + logs by default; hard-blocks under THUMBGATE_STRICT_ENFORCEMENT=1
reason: "Force-push to main flagged — 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 attempt is flagged and logged before execution by default, and hard-blocked in strict mode. Either way the agent receives the reason and adapts.

Key difference: Prompt rules ask nicely and get compressed out of context. Pre-action checks run at the hook layer, outside the agent's reasoning chain — so the attempt is always caught and logged, and in strict mode it is hard-blocked rather than merely flagged.

What about other dangerous actions?

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

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 catches repeating mistakes today.

$ npx thumbgate init
Try it now: npx thumbgate init GitHub →