DEV Community

Igor Ganapolsky
Igor Ganapolsky

Posted on • Originally published at rlhf-feedback-loop-production.up.railway.app

How to Give Your AI Coding Agent Persistent Memory Across Sessions

Your AI coding agent forgets everything when the session ends. You spend twenty minutes explaining your codebase — the monorepo structure, the deployment conventions, the one branch it must never force-push to. Tomorrow it has no memory of any of it.

This is how context windows work. Every session starts blank. Claude Code, Cursor, Codex, Gemini — they all hit the same wall.

Context Windows Are Not Memory

A context window is RAM — fast, capacious, gone when the power cuts. Memory is disk — slower to query, but persistent. Right now, AI coding agents only ship with RAM.

An agent with no persistent memory will:

  • Repeat mistakes it made last week
  • Re-ask for project conventions it already learned
  • Ignore prevention rules from a prompt that is gone
  • Treat every session like day one

Three Types of Agent Memory

Memory Type What It Stores Example
Episodic Records of past events Agent force-pushed to main, you thumbs-downed it
Semantic Rules derived from episodes Force-pushing to main causes broken deploys
Procedural Gates that fire before actions PreToolUse hook blocks git push --force to main

Most memory proposals stop at episodic. That is insufficient. Episodes must promote to rules, rules must compile into gates.

ThumbGate: Three-Tier Memory for AI Agents

ThumbGate implements this full pipeline:

  1. Episodic layer — Every thumbs-up/down is logged with context, timestamps, and tags
  2. Semantic layer — SQLite+FTS5 lesson database. Retrieves relevant lessons by similarity, not recency
  3. Procedural layer — Prevention rules checked by PreToolUse hooks. The agent cannot reason around a gate

The promotion pipeline: Thumbs-down → feedback log → lesson in SQLite → prevention rule → PreToolUse gate active for every future session.

Thompson Sampling for Confidence

Not every rule has the same confidence. ThumbGate uses Thompson Sampling (multi-armed bandit) to handle uncertainty. High-confidence gates hard-block. Low-confidence gates warn. Feedback tightens the distribution over time.

Two-Minute Setup

npx mcp-memory-gateway init
Enter fullscreen mode Exit fullscreen mode

Works with Claude Code, Cursor, Codex, Gemini, Amp, OpenCode — any MCP-compatible agent.

That command provisions:

  • SQLite+FTS5 lesson database
  • Feedback log
  • Prevention rules
  • PreToolUse hook
  • MCP server adapter

By day 30, your agent starts each session informed by relevant past lessons. Fewer mistakes, no retraining required.


Read the full article on ThumbGate

Top comments (0)