If you've spent real time with Claude Code, you already know the frustration: spend twenty minutes explaining your project structure, coding conventions, and why you're using specific libraries—only to watch it all vanish when you start a new session. The AI isn't broken in the traditional sense; it's just hitting the hard limits of how context windows work. But a clever open-source tool called Memory Vault is turning this problem on its head by wiring Claude directly to a Postgres database, giving it genuine long-term memory that survives every /clear command and even machine switches.

Why Context Windows Aren't Real Memory

Claude Code operates on a context window—a working memory holding your current conversation, file reads, tool outputs, and instructions. Depending on your plan and model, that window spans anywhere from 200,000 tokens to a million. Sounds massive, but it fills up faster than you'd expect. Every file you open, every bash command Claude runs, every long back-and-forth eats into that budget. When the context gets close to full, Claude automatically starts compacting your chat—deleting older tool outputs first, then summarizing earlier conversation. The problem? Compaction is lossy. Detailed instructions or decisions from earlier in a session quietly disappear without warning.

Enter Postgres and MCP

For anything serious—a long-running project, a team environment, or a codebase where context drift can cost you hours and thousands of tokens—you need memory that lives completely outside Claude's context window. That's where Postgres comes in, connected via the Model Context Protocol (MCP)—an open standard letting AI tools connect to external services. Memory Vault combines Postgres with pgvector for hybrid search: semantic similarity and keyword matching combined, so Claude can find the right memory even when you don't remember the exact words. Setup takes about five minutes: git clone https://github.com/mihaibuilds/memory-vault.git, cd into it, run docker compose up -d, then configure your .claude.json with the MCP server details and Python 3.11+ dependencies.

Windows Users Beware

There's a gotcha if you're running Claude Code on Windows but hosting Postgres on a Linux server: Python's default async loop on Windows (ProactorEventLoop) is incompatible with psycopg3, the database driver Memory Vault uses. Even with the right path configured, it'll time out after 30 seconds without anything useful in the error message. The fix requires editing one line in src/mcp/__main__.py to set asyncio.WindowsSelectorEventLoopPolicy() for Windows platforms. Set DB_HOST to your Linux machine's local IP instead of localhost, and the connection should work cleanly.

The Simple Alternative

If database infrastructure feels like overkill, Claude Code has a built-in mechanism that handles most daily frustrations without leaving your terminal: CLAUDE.md. This plain text file reads automatically at every session start, or you can use /memory to open it directly in your system editor. You can also ask Claude to create project-specific files and read them on demand. The catch? Content from these files gets injected into the context window each time, consuming tokens. Keep CLAUDE.md focused and trim it regularly—or it'll eat into the same budget you're trying to protect.

Key Takeaways

  • Context windows fill up fast; lossy compaction silently kills important details
  • Memory Vault (Postgres + pgvector via MCP) gives Claude persistent memory that survives everything
  • Setup is three commands: git clone, cd, docker compose up -d
  • Windows users must switch to asyncio.WindowsSelectorEventLoopPolicy() for psycopg3 compatibility
  • CLAUDE.md works for basic cases but still consumes context tokens

The Bottom Line

The manual file approach gets you out of most daily frustrations fast—but it's not a real solution. Memory Vault is what you reach for when you need something that actually scales and starts feeling less like a workaround and more like Claude genuinely knowing your project.

> From The Wire