# How to Stop AI Coding Agents From Repeating Mistakes

The complete guide to pre-action checks, feedback capture, history-aware lesson distillation, 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 Checks

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 check, 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
    [check] Blocked: no-force-push (confidence: 0.94)
    Agent: git push origin feature-branch
    [check] Passed

## Install (One Command)

    # Auto-detect your agent and configure hooks
    npx thumbgate init

    # Or specify your agent directly
    npx thumbgate init --agent claude-code
    npx thumbgate init --agent codex
    npx thumbgate init --agent cursor
    npx thumbgate init --agent gemini

### Install scope: machine-wide vs per-project

ThumbGate supports two install scopes. Pick once when you install — you can switch later by re-running with the other flag.

Scope | Command | Where lessons + dashboard live | When to use
--- | --- | --- | ---
Machine-wide (default) | `npx thumbgate init` | `~/.claude/memory/feedback/` — one shared dashboard across every repo on the machine | Solo developer. A lesson learned in `repo-A` automatically blocks the same mistake in `repo-B`.
Per-project | `npx thumbgate init --project` (run inside the repo) | `<repo>/.claude/memory/feedback/` — separate dashboard per repo | Client work, compliance, or multi-tenant. Lessons stay isolated; the audit trail belongs to the repo.

Both scopes wire the same MCP server and PreToolUse / UserPromptSubmit / PostToolUse / SessionStart hooks — only the storage location differs. Machine-wide is the right default for most developers. Per-project lesson DBs live under each repo's `.claude/memory/feedback/` and must stay gitignored; ThumbGate's bundled `.gitignore` handles that.

## 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. In the current Claude auto-capture path, if the thumbs-down is vague, it can reuse up to 8 prior recorded entries and the failed tool call to propose a better lesson instead of discarding the feedback.

    # 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 checks

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

### 4. Checks adapt via Thompson Sampling

Checks that block too aggressively (high false-positive rate) get their confidence reduced automatically. Checks 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.

- `recall` — injects relevant context at session start
- `search_lessons` — finds promoted lessons with corrective actions
- `retrieve_lessons` — surfaces lessons for the tool or action you are about to run
- `session_handoff` — preserves continuity across sessions

## History-Aware Feedback Sessions

ThumbGate supports linked feedback sessions for the messy reality of AI debugging. In the current Claude flow, accepted feedback opens a 60-second follow-up session. You can append more context, reset the timer, and finalize once the lesson is clear.

- `open_feedback_session` starts a linked correction thread.
- `append_feedback_context` adds later notes, failed tool output, or user corrections to the same thread.
- `finalize_feedback_session` promotes the combined evidence into one reusable lesson.
- `reflect_on_feedback` proposes a reusable rule from the same transcript when the failure pattern is obvious.

## Pre-Action Checks vs Prompt Rules

Feature | Prompt Rules | Pre-Action Checks
--- | --- | ---
Where they live | CLAUDE.md, .cursorrules | PreToolUse hooks
Enforcement | Suggestion (can be ignored) | Blocks execution
When they fire | At prompt load | Before every tool call
Auto-generated | No — hand-written | Yes — from feedback
Adaptive | No | Yes — Thompson Sampling
Persist across sessions | Only if in a file | SQLite + JSONL

## ThumbGate vs Alternatives

Feature | ThumbGate | SpecLock | Mem0
--- | --- | --- | ---
Blocks mistakes before execution | Yes — PreToolUse checks | Yes — Patch Firewall | No
Learns from feedback | Yes — thumbs up/down | No — manual specs | Yes — auto-capture
Auto-generates rules | Yes — from repeated failures | No | No
Agent support | Claude Code, Codex, Gemini, Amp, Cursor, OpenCode | Claude Code, Cursor, Windsurf, Cline | Claude, Cursor
Install | `npx thumbgate init` | `npx speclock setup` | Cloud signup
Cost | Free (Pro $19/mo or $149/yr, Team rollout $49/seat/mo) | Free | Free tier + paid

## Common Scenarios

### Agent keeps deleting files

Give a thumbs-down: "deleted production config file." After 2-3 occurrences, ThumbGate generates a check 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 checks future commits when test results show failures.

### Agent uses wrong API endpoint

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

## When ThumbGate becomes a paid decision

Stay on the free install path while one operator is proving the workflow locally. The paid motion starts when a workflow owner asks for proof, shared enforcement, or a safer rollout path.

### Three honest next steps

- Free: use `npx thumbgate init` to prove one workflow on one machine.
- Pro: buy the self-serve lane only when you want a personal local dashboard, DPO export, and proof-ready workflow review for the next risky flow.
- Workflow Hardening Sprint: use the team intake path once one workflow, one owner, and one repeated failure are already clear.

## Proof before a buyer says yes

The repo sales plan is proof-led, not hype-led. Commercial claims stay anchored to the current truth file, and engineering claims stay anchored to verification evidence and machine-readable proof reports.

Commercial Truth Current pricing, traction guardrails, and what the product can honestly claim today. Verification Evidence Human-readable proof log for the engineering and workflow claims used across the site. Automation Proof Machine-readable report for the feedback, enforcement, and automation surfaces behind ThumbGate.

## Get Started

    npx thumbgate init

One command. Works with Claude Code, Cursor, Codex, Gemini, Amp, and OpenCode. Claude Code can also call Codex for review, adversarial review, and second-pass handoffs through the repo-local bridge plugin.

Get Pro — $19/mo or $149/yr Pay $499 diagnostic Pay $1500 sprint Send workflow first

Free: unlimited captures, 5 active prevention rules, hook blocking. Pro: dashboard, recall, lesson search, unlimited rules, DPO export. Team: intake first, then $49/seat/mo with a 3-seat minimum.