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 flagged and logged — and hard-blocked by default for catastrophic commands (force-push, git reset --hard, rm -rf on home or root, DROP TABLE, cloud wipes), secret exfiltration and guardrail-tampering. Everything else, supply-chain risks included, warns by default and hard-blocks when strict enforcement (THUMBGATE_STRICT_ENFORCEMENT=1) is on.

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] Warn: no-force-push (confidence: 0.94) — hard-blocked under strict mode
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

First run: a thumbs-down typed right after the agent ran a command makes a learned rule that denies that command the next time the agent tries it, with your reason (since 1.64.0). By default ThumbGate also denies catastrophic commands, secret leaks and attempts to switch it off; other built-in checks warn. A thumbs-down that is only a sentence, with no command attached, is saved as a lesson. To gate one command without a thumbs-down, run thumbgate force-gate "<command>". That gate denies only when strict enforcement is on (THUMBGATE_STRICT_ENFORCEMENT=1); in default mode it warns. Measured 24 Nov 2026 on a throwaway directory: warn in default mode, deny in strict mode, including bash -c "<command>".

Install scope: machine-wide vs per-project

ScopeCommandClaude Code hooksLessons and dashboard data
Machine-wide (default) npx thumbgate init ~/.claude/settings.json, so they run in every repo on this machine <repo>/.thumbgate/
Per-project npx thumbgate init --project (run inside the repo) <repo>/.claude/settings.json, so they run only in this repo <repo>/.thumbgate/

Both scopes also write the MCP entry to <repo>/.mcp.json. Lessons stay per repo either way: a thumbs-down in repo-A does not flag anything in repo-B. Keep .thumbgate/ gitignored. For an MCP-only install, npx thumbgate install-mcp adds the server to ~/.claude/settings.json, and npx thumbgate install-mcp --project adds it to <repo>/.claude/settings.json. Neither writes hooks.

Signs you need this

If none of these fit, you may not need it yet. ThumbGate checks tool calls before they run; it is not a sandbox.

Your first week

Day 1: install and pick one repeated mistake

npx thumbgate init
npx thumbgate doctor    # look for: Overall: READY

Pick one command your agent has run when it should not have.

Day 2: gate it and trigger it once

Right after the agent runs that command, type thumbs down: and the reason. Ask it to run the command again: it is denied, with your reason, because the thumbs-down made a learned rule for that command (since 1.64.0). The command is also held until you say "go ahead", but the learned rule keeps refusing it after that (thumbgate unblock <gate> turns it into a timed, logged warning). To have holds refuse the command instead of warning, set THUMBGATE_HARD_BLOCK_GATES=thumbs-down-hold, or THUMBGATE_STRICT_ENFORCEMENT=1 to make every warning a deny.

Days 3 to 7: count real blocks and false blocks

npx thumbgate gate-stats    # Actions blocked, Actions warned, Top blocked gate
npx thumbgate gate-audit    # replays learned gates on past allowed actions: false-fire rate

The counts include the test you ran on day 2. ThumbGate cannot know that a block was wrong, so when one stops something you wanted, write it down. With few past actions, gate-audit has no rate to show yet.

Day 7: keep, tune or remove

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.

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.

Pre-Action Checks vs Prompt Rules

FeaturePrompt RulesPre-Action Checks
Where they liveCLAUDE.md, .cursorrulesPreToolUse hooks
EnforcementSuggestion (can be ignored)Flags + logs; hard-blocks critical / strict mode
When they fireAt prompt loadBefore a tool runs
Auto-generatedNo — hand-writtenYes — from feedback
AdaptiveNoYes — Thompson Sampling
Persist across sessionsOnly if in a fileSQLite + JSONL

ThumbGate vs Alternatives

FeatureThumbGateSpecLockMem0
Flags mistakes before executionYes — PreToolUse checks (built-in rules deny a short list; other matches warn)Yes — Patch FirewallNo
Turns feedback into rulesYes — thumbs up/downNot stated in its README; it reads existing rule filesYes — auto-capture
Auto-generates rulesAuto-promotes a warning rule from repeated thumbs-downsNot comparedNo
Agent supportClaude Code, Codex, Gemini, Amp, Cursor, OpenCodeClaude Code, Cursor, Windsurf, ClineClaude, Cursor
Installnpx thumbgate initnpx speclock setupCloud signup
CostFree local CLI; Pro $19/monthFreeFree tier + paid

Common Scenarios

Agent keeps deleting files

Give a thumbs-down: "deleted production config file." ThumbGate saves your reason and shows it back as a warning when a similar command comes up. It does not block on a thumbs-down alone.

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 flags and logs tool calls that reference staging URLs in production contexts (and hard-blocks them under strict mode).

What it denies, and what it only warns about

ThumbGate uses four words for what happens to a command. They mean the same thing on every ThumbGate page.

Warning
The agent sees the check and your reason. The command can still run.
Denied
The hook stops the command before it runs.
Strict mode
THUMBGATE_STRICT_ENFORCEMENT=1. Checks that only warn by default deny instead, except a rule learned from a single thumbs-down.
Advisory
The agent is asked to run the check itself, so nothing stops a command it skips.
What ThumbGate does in Claude Code. Checked through the real PreToolUse hook on 2026-12-01; published npm version 1.64.0.
SituationDefault installStrict mode
git push --force, git reset --hard, git clean -fdx, rm -rf on home or root, find / -delete, DROP TABLEDeniedDenied
terraform destroy, kubectl delete, aws s3 rm and other cloud or cluster wipesDeniedDenied
Sending a secret out, for example curl -d @.envDeniedDenied
Switching ThumbGate off, for example pkill -f thumbgate or uninstalling it from inside the agentDeniedDenied
git push origin main (a push to the default branch)Denied (lift it for an hour with npx thumbgate unblock protected-branch-push --reason "why you need it")Denied
A command you gave a thumbs-down, right after and each time it runs again (a rule that would have blocked your past safe calls stays a Warning)DeniedDenied
A learned check that passed its 30-day replay (under 2% of 50+ matching calls were ones you let through)DeniedDenied
Other flagged actions, for example npm publish or git commit --no-verifyWarningDenied
Claude Code says "deployed" or "live" with no production output in the reply (Stop hook)Reply sent back once to add proof. It checks that proof is present, not that it is true.Same as default
The same action, reworded (for example python3 -c "shutil.rmtree(...)" after a thumbs-down on rm -rf)Not caught. A learned rule matches the command, not its purpose.Not caught
Damage from a command ThumbGate allowsNot contained. ThumbGate is not a sandbox.Not contained

What the CLI sends

The CLI sends anonymous usage events: a random install id, the ThumbGate, Node and OS versions, the event name, and which built-in check fired (any rule learned from your thumbs-downs is sent only as "learned", never its words). Releases before 1.62.0 could send words from a learned rule's command; update to stop that. THUMBGATE_NO_TELEMETRY=1 or DO_NOT_TRACK=1 turns it off. Lessons and rules stay in .thumbgate/ in your repo.

Holds, and how to release or remove a gate

Stuck? Do this.

1. Say "go ahead" to your agent, or give a thumbs-up.
2. Or run npx thumbgate unblock to see what refused the call and how to clear it (details).
3. To stop holds for good, run npx thumbgate holds off. Your other gates stay on.

A hold is a pause. When you type a thumbs-down right after the agent ran something, ThumbGate warns the agent, with your reason, before that same action (the same tool; for a shell command, the same first three words) until you say to go on. In strict mode, or with THUMBGATE_HARD_BLOCK_GATES=thumbs-down-hold, the hold refuses it instead. A hold on inline code (python3 -c, a heredoc, a pipe into Python) covers that script in any form, not every later python3 run. It stops the agent from repeating what you just marked wrong. A hold lasts up to 24 hours, and several thumbs-downs on the same action count as one hold.

Three ways out: start your message with "go ahead" (or "continue", "proceed", "resume", "unblock"), or give a thumbs-up; run npx thumbgate holds release in the project folder to clear it now; or run npx thumbgate holds off to turn the hold off, even in a session that is already running (npx thumbgate holds on brings it back).

Unblock a gate

Run npx thumbgate unblock to see which gate or hold refused a call and the exact command that clears it. npx thumbgate unblock holds releases thumbs-down holds. npx thumbgate unblock <gate> --reason "why" --ttl 1h grants a time-boxed, audited override for that one gate (24 hours at most; --revoke ends it early). The override turns that gate into a warning even in strict mode or under THUMBGATE_HARD_BLOCK_GATES. Catastrophic commands, secrets and attempts to switch off ThumbGate are never unblocked: change the command instead. From 1.61.0 the money and outbound-send gates (financial-control, outbound-email-send) can't be unblocked either, if you've turned them into blocks. From 1.61.0 the local dashboard (npx thumbgate dashboard --open) has an Unblock panel that does the same with buttons.

Turning the hold off keeps every other gate on, including the commands denied by default and the chat send rules. THUMBGATE_SEND_GATE=0 turns off the whole chat send gate, holds included. npx thumbgate break-glass does not lift a hold. A reworded command is not held, and ThumbGate is not a sandbox.

When ThumbGate becomes a paid decision

Stay on the free plan while three learned rules cover the mistakes you correct. Pro starts to pay off when you correct your agent often enough to want every rule kept active, and to search what you taught it last month.

Three honest next steps

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.

Questions, answered from the product facts

What does ThumbGate deny on a fresh install?

git push --force, git reset --hard, git clean -fdx, rm -rf on home or root, find / -delete, DROP TABLE; terraform destroy, kubectl delete, aws s3 rm and other cloud or cluster wipes; Sending a secret out, for example curl -d @.env; Switching ThumbGate off, for example pkill -f thumbgate or uninstalling it from inside the agent; git push origin main (a push to the default branch); A command you gave a thumbs-down, right after and each time it runs again (a rule that would have blocked your past safe calls stays a Warning); A learned check that passed its 30-day replay (under 2% of 50+ matching calls were ones you let through). These are denied before they run, in every plan.

Does a thumbs-down block the command next time?

A command you gave a thumbs-down, right after and each time it runs again (a rule that would have blocked your past safe calls stays a Warning): Denied. A learned check that passed its 30-day replay (under 2% of 50+ matching calls were ones you let through): Denied. The same action, reworded (for example python3 -c "shutil.rmtree(...)" after a thumbs-down on rm -rf): Not caught. A learned rule matches the command, not its purpose.

What only warns?

Other flagged actions, for example npm publish or git commit --no-verify: a Warning by default. The agent sees the check and your reason. The command can still run. Strict mode denies these instead.

What does strict mode change?

THUMBGATE_STRICT_ENFORCEMENT=1. Checks that only warn by default deny instead, except a rule learned from a single thumbs-down. Built-in checks that warn by default, such as npm publish, are Denied.

Which agents does ThumbGate enforce in?

Claude Code: Denied and Warning, tested end to end. Cursor: Shell commands: Denied and Warning, tested end to end. Other tools: Advisory. Codex, Gemini CLI: Wired, not yet tested end to end with each agent's own payload. Pydantic AI Pax: Denied and Warning. Cline, OpenCode, Amp and other MCP-only clients: Advisory only.

What is free and what does Pro add?

Free keeps 3 active learned rules and records 2 thumbs a day after a 7-day full Pro trial. Pro is $19/month for one developer. Pro adds unlimited active learned rules (free keeps 3), unlimited thumbs-up and thumbs-down captures, recall and lesson search across everything you have taught it, DPO and training-data exports. Not shipped in any plan: team-shared rules, rules shared between teammates' machines, audit history for managers.

What leaves my machine?

The CLI sends anonymous usage events: a random install id, the ThumbGate, Node and OS versions, the event name, and which built-in check fired (any rule learned from your thumbs-downs is sent only as "learned", never its words). Releases before 1.62.0 could send words from a learned rule's command; update to stop that. THUMBGATE_NO_TELEMETRY=1 or DO_NOT_TRACK=1 turns it off. Lessons and rules stay in .thumbgate/ in your repo.

Can my team share rules?

Not yet. Not shipped in any plan: team-shared rules, rules shared between teammates' machines, audit history for managers. Teams can ask for a 30-day pilot at https://thumbgate.ai/pilot. It is request only, with no self-serve team checkout.

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.

Request a team pilot Send workflow first

Free: 2 captures/day, 3 active prevention rules, hook blocking. Pro: recall, lesson search, unlimited captures and rules, DPO export. The local dashboard is free. Enterprise service work is qualified and signed after intake; hosted team sync and a hosted org dashboard are not generally available.