惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Apple Machine Learning Research
Apple Machine Learning Research
Jina AI
Jina AI
博客园_首页
WordPress大学
WordPress大学
罗磊的独立博客
小众软件
小众软件
Last Week in AI
Last Week in AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The Cloudflare Blog
GbyAI
GbyAI
C
Check Point Blog
腾讯CDC
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
博客园 - 聂微东
IT之家
IT之家
雷峰网
雷峰网
H
Help Net Security
博客园 - 叶小钗
美团技术团队
D
DataBreaches.Net

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Claude Code Forgets Everything. So I Built It a Memory Se...
Tom Tokita · 2026-05-19 · via DEV Community

Everyone's building AI agents. Almost nobody is building memory for them.

The default Claude Code experience is this: you open a session, you do great work, you close the session, and it's gone. No Claude Code MCP server ships with the product to fix this. Next morning, you open a new session and explain the same project structure, the same deployment rules, the same "don't push to production without checking the allowlist" that you've explained every day this week. Claude is brilliant. Claude is also an amnesiac.

At one project, that's annoying. Across a live client portfolio, it's a wall. I was burning the first ten minutes of every session on logistics that the system already knew and forgot. Same overview. Same rules. Same warnings. The AI equivalent of training a new hire every morning.

So I stopped accepting the default and built a custom Claude Code MCP server with persistent memory. What started as a quick fix turned into the core of how I work.

What MCP Is (And What It Isn't)

MCP (Model Context Protocol) lets you give Claude tools it doesn't ship with. You run a server, Claude connects to it, your server exposes capabilities that Claude calls during a session. Anthropic's docs cover setup.

This post isn't about the plumbing. It's about what you build once the plumbing works, and why the interesting problems start after "hello world."

What a Claude Code MCP Server Actually Needs (And Why)

My server gives Claude four things it doesn't have by default: persistent memory, context condensation, delegated file reading, and compliance checking. I didn't design any of this upfront. Something broke, I fixed it, and the fix became a feature.

Memory That Survives Between Sessions

This came first, because the pain was loudest. I needed Claude to remember things across sessions: project configurations, platform quirks I'd spent hours debugging, deployment rules that came from three broken deploys and a near-miss on a production org.

The server indexes all of that into a vector database. Thousands of knowledge chunks, searchable by meaning and by keyword. When Claude starts a session, the first thing it does is search the memory server. The rule is simple: check what you already know before guessing.

I use hybrid search. Vector similarity finds conceptually related content. Keyword search catches exact terms. Neither alone is reliable, and I learned that the hard way. Semantic-only search kept returning adjacent results that missed the specific command or config value I needed. Adding keyword matching fixed the retrieval quality problems, but only after weeks of wondering why search felt "close but wrong."

Condensation (The Problem Nobody Warns You About)

When your memory server works too well, it returns too much.

One operation was returning over 200,000 characters of raw project context. That payload literally couldn't fit in the tool response. Claude would choke before reading a single result. Your memory server becomes a liability the moment it knows more than the context window can hold.

The fix was a condenser. Results pass through a lighter model before reaching Claude. That model reads the full output and returns a distilled summary. Two hundred thousand characters compress down to a few thousand. Claude gets the answer without the bloat.

If you're building an MCP server and you don't have a condensation layer, you'll hit this wall the moment your knowledge base grows past a few hundred entries. I know because I ran without one for weeks and couldn't figure out why sessions were getting slower and dumber. The condenser was the fourth thing I built. It should have been the first.

Delegated Reading (Keep the Context Window Clean)

Claude's context window is finite. Every file it reads directly consumes capacity that could be used for reasoning. Big file loads are expensive, and the cost isn't dollars. It's degraded output quality three tool calls later, because the window is stuffed with a 2,000-line config file that Claude only needed two lines from.

So I built a reader. A lighter model scans the file and answers specific questions, returning cited answers with line numbers. Claude asks "what are the deployment rules for this project?" and gets back a sourced answer without loading the entire document.

Same principle for writing. Mechanical work (session logs, documentation updates, structured captures) gets delegated to a cheaper model. Claude focuses on reasoning. The formatting happens elsewhere. You don't pay senior rates for data entry.

Compliance Checking (Because Prompts Drift)

This one came from the most painful failure. I needed Claude to validate proposed actions against rules before executing. Not a prompt instruction. Not "please remember to check the allowlist." Prompts get compressed. Prompts get forgotten. A prompt is a suggestion. A gate is a wall.

The server accepts a proposed action, checks it against predefined rules, and returns pass or fail. The difference between asking someone to remember a checklist and bolting that checklist to the door so they can't walk through without completing it.

If you've ever told an AI "don't do X" and then watched it do X forty-five minutes later after a long conversation, you understand why mechanical enforcement exists. The model didn't disobey. It forgot. Forgetting and disobeying look identical from the outside, but only one of them is fixable with infrastructure.

Session Loading: How Much Context Is Too Much?

Once you have persistent memory, you face a new question. How much do you load at session start?

Load everything, and you burn half the context window on background knowledge before the session begins. Load nothing, and you're back to square one.

I built a tiered loader. One call returns exactly what Claude needs. First tier: core rules, security protocols, workflow constraints. Always loaded, always lean. Second tier: project-specific context. Only loaded when relevant. Both tiers pass through the condenser before returning, so the loaded context is measured in thousands of characters, not hundreds of thousands.

Claude starts every session knowing the rules, the recent project activity, and what happened yesterday. One call. Under a second. No re-explaining.

How Claude Code Loses Memory Mid-Session (And How to Fix It)

This is the problem nobody talks about, and it's the one that will cost you the most debugging time.

Claude Code compresses your conversation when the context window fills up. Older messages get summarized. In theory, this is efficient. What that means in practice: the deployment rules you loaded at session start can silently vanish mid-session. The behavioral constraints? Gone. The project state? Compressed into a summary that may or may not preserve what matters.

My server detects this. When Claude calls the session loader a second time in the same session, the server includes a recovery hint: the most recently active project. Claude reloads the relevant context surgically. Not the full knowledge base. Just what the current task needs.

Before this existed, long sessions would silently lose their constraints around the two-hour mark. I wouldn't notice until Claude deployed a metadata package to the wrong org because the deploy rules from session start had been compressed away. The failures were quiet. That's what made them expensive.

What Persistent Memory Changes for Claude Code Workflows

Before the memory server, every session started with ten minutes of setup. Reading project files, re-establishing context, reminding Claude which org belongs to which project. Creative time wasted on logistics.

After: one call. Rules load, project context loads, recent activity loads. I start working immediately.

But the real win is compounding. Every session generates learnings. Deployment patterns that worked. API gotchas that burned an hour. Platform quirks that only surface in production. Those learnings get indexed automatically. The next session starts with that knowledge already searchable. The session after that starts with even more.

I co-founded Aether Global Technology, a Salesforce consulting partner in Manila. The memory server runs alongside that work as a personal R&D system. It doesn't touch client data. What it does is compound operational knowledge across projects and platforms, so Claude rarely encounters a problem it hasn't seen a version of before.

Mistakes get encoded so they don't repeat. The memory server doesn't make Claude smarter. It makes Claude less likely to be stupid in the same way twice.

What I'd Build Differently

I over-indexed on features and under-indexed on condensation. The memory server had rich search, tiered loading, and compliance checking before it had a condenser. That meant every search returned massive payloads that burned through the context window. If I were starting over, condensation would be the first thing I built, not the fourth.

I'd also start with a smaller embedding model. My instinct was to use the most capable sentence transformer I could find. The difference in search quality between models was marginal. The difference in startup time and memory footprint was not. A lighter model that loads in seconds would have saved weeks of debugging cold-start problems on a machine that was already running six other services.

And I'd design for compression survival from day one, not bolt it on after losing context mid-session three times. That pattern is now the part of the system I trust most, but it didn't need to take three incidents to build.

Frequently Asked Questions

What is a Claude Code MCP server?

An MCP (Model Context Protocol) server is a custom backend that gives Claude Code capabilities it doesn't have out of the box. You run the server, Claude connects to it, and your server exposes tools that Claude can call during a session. A memory-focused MCP server specifically solves the problem of Claude forgetting everything between sessions by providing persistent, searchable knowledge storage.

Does Claude Code remember between sessions?

Not by default. Claude Code starts every session fresh. CLAUDE.md files provide some static context, but they don't scale past a single project. A custom MCP server with a vector database and session loading gives Claude persistent memory across sessions, so it knows your project rules, past learnings, and recent activity without you re-explaining every time.

What is context compression in Claude Code?

When your conversation with Claude Code fills the context window, older messages get summarized to make room. This is called context compression. The problem is that rules, constraints, and project state loaded at session start can silently disappear during compression. Without a recovery mechanism, Claude forgets its guardrails mid-session.

How do I add persistent memory to Claude Code?

Build an MCP server that indexes your knowledge into a vector database, then expose search and retrieval as MCP tools. Claude calls these tools at session start to load context. Add a condensation layer so large results don't overflow the context window. The key insight is that memory alone isn't enough. You need condensation, tiered loading, and compression recovery to make it work at scale.

Try It Yourself

I'm working on a lightweight version of this memory server. Stripped to the core: vector search, session loading, and basic condensation. Enough to give Claude Code persistent memory without the full production infrastructure. Follow my GitHub for updates.

If you want something you can use today, I open-sourced the pre-action gate pattern. Mechanical enforcement that blocks your AI agent from executing before checking the rules. Zero dependencies. Works with Claude and Gemini.

github.com/tomtokitajr/ai-agent-gates


Tom Tokita is co-founder of Aether Global Technology and builds AI operations systems in Manila. He writes about what works in production.