How to Stop AI Coding Agents From Repeating Mistakes

The complete guide to pre-action gates, feedback capture, and automatic prevention rules.

The Problem

Your AI coding agent force-pushes to main. You correct it. Next session, it force-pushes again. You add a rule to CLAUDE.md. It ignores it. You lose an afternoon reverting.

This happens because prompt rules are suggestions. The agent can read them, forget them, or override them. There is no enforcement at the tool-call level.

The Fix: Pre-Action Gates

ThumbGate adds an enforcement layer between your agent and its tools. When the agent tries to execute a tool call, a PreToolUse hook fires before the action runs. The hook checks the call against known failure patterns. If it matches a gate, the action is blocked.

Before ThumbGate

Agent: git push --force origin main
Result: Force-pushed. You lose 3 commits. Again.

After ThumbGate

Agent: git push --force origin main
[gate] Blocked: no-force-push (confidence: 0.94)
Agent: git push origin feature-branch
[gate] Passed

Install (One Command)

# Auto-detect your agent and configure hooks
npx mcp-memory-gateway init

# Or specify your agent directly
npx mcp-memory-gateway init --agent claude-code
npx mcp-memory-gateway init --agent codex
npx mcp-memory-gateway init --agent cursor
npx mcp-memory-gateway init --agent gemini

How It Works

1. You give feedback

When your agent makes a mistake, tell it. ThumbGate captures the feedback as structured data with context, tags, and domain.

# Your agent force-pushed. You say:
"thumbs down — force-pushed to main, lost commits"

# ThumbGate captures:
{
  signal: "negative",
  context: "force-pushed to main, lost commits",
  tags: ["git", "force-push", "destructive"],
  domain: "version-control"
}

2. Feedback auto-promotes to prevention rules

After repeated failures with the same pattern, ThumbGate generates a prevention rule automatically. No manual rule writing needed.

3. Rules become gates

Prevention rules are enforced as pre-action gates. The gate fires at the PreToolUse hook level — inside the agent's runtime, before the tool call executes.

4. Gates adapt via Thompson Sampling

Gates that block too aggressively (high false-positive rate) get their confidence reduced automatically. Gates that catch real mistakes get reinforced. This is Bayesian multi-armed bandit optimization, not static rules.

Memory That Persists Across Sessions

ThumbGate stores feedback in a local SQLite database with FTS5 full-text indexing. Lookups are sub-millisecond even at tens of thousands of entries. Old entries that contradict newer evidence are auto-pruned via Bayesian belief decay.

Pre-Action Gates vs Prompt Rules

FeaturePrompt RulesPre-Action Gates
Where they liveCLAUDE.md, .cursorrulesPreToolUse hooks
EnforcementSuggestion (can be ignored)Blocks execution
When they fireAt prompt loadBefore every tool call
Auto-generatedNo — hand-writtenYes — from feedback
AdaptiveNoYes — Thompson Sampling
Persist across sessionsOnly if in a fileSQLite + JSONL

ThumbGate vs Alternatives

FeatureThumbGateSpecLockMem0
Blocks mistakes before executionYes — PreToolUse gatesYes — Patch FirewallNo
Learns from feedbackYes — thumbs up/downNo — manual specsYes — auto-capture
Auto-generates rulesYes — from repeated failuresNoNo
Agent supportClaude Code, Codex, Gemini, Amp, Cursor, OpenCodeClaude Code, Cursor, Windsurf, ClineClaude, Cursor
Installnpx mcp-memory-gateway initnpx speclock setupCloud signup
CostFree (Pro $49 for teams)FreeFree tier + paid

Common Scenarios

Agent keeps deleting files

Give a thumbs-down: "deleted production config file." After 2-3 occurrences, ThumbGate generates a gate that blocks rm commands targeting config files.

Agent ignores test failures

Give a thumbs-down: "committed code with failing tests." ThumbGate learns the pattern and gates future commits when test results show failures.

Agent uses wrong API endpoint

Give a thumbs-down: "called staging API in production code." The gate blocks tool calls that reference staging URLs in production contexts.

Get Started

npx mcp-memory-gateway init

One command. Works with Claude Code, Cursor, Codex, Gemini, Amp, and OpenCode.

Get Pro — $49

Free is fully featured — unlimited captures, recalls, gates, and blocking. Pro adds a searchable dashboard to query, edit, and delete entries.