claude-mem: Curing Agent Amnesia with an Autonomous Flight Recorder

How a passive background daemon transforms ephemeral CLI sessions into a permanent, searchable memory bank for Claude Code.

• View on GitHub • More from thedotmack

A large ornate library where a small mechanical bird is flying while a translucent ghost figure catches dropped feathers and files them into glowing cabinets, representing passive background recording.
The Worker Service acts as a silent observer, cataloging terminal output without interrupting the developer's flow.

Claude-Mem seamlessly preserves context across sessions by automatically capturing tool usage observations, generating semantic summaries, and making them available to future sessions.

thedotmack, Author · GitHub - thedotmack/claude-mem

Key Takeaways

The High Cost of Starting Over

Every new terminal session with an AI coding assistant begins with a blank slate. Developers must repeatedly explain the project architecture, coding standards, and past decisions. This repetitive onboarding is the token tax of stateless chat. It creates a cognitive burden that limits how deeply an AI can integrate into a long-term project.

This phenomenon is known as agent amnesia. While large language models possess vast general knowledge, they lack the specific, evolving context of your local codebase. The solution is not just a larger context window. It is a persistent, stateful memory system.

The Background Chronicler

The standard approach to AI memory requires manual indexing or explicit save commands. The claude-mem project takes a different path. It operates as a passive flight recorder for the terminal. By intercepting lifecycle hooks within Claude Code, it watches every command executed and every file read.

A dedicated Worker Service runs in the background. It listens on a local port and catalogs these interactions. The primary AI agent focuses entirely on writing code. The secondary background process handles the bookkeeping.

The lifecycle of an observation, moving from raw terminal output to structured semantic storage.

Portrait of Alex Newman (thedotmack), creator of claude-mem.

From Raw Logs to Semantic Gold

Storing raw terminal logs is inefficient. Feeding thousands of lines of verbose build output back into an LLM wastes tokens and degrades reasoning. The system solves this through automated memory compression.

The Worker Service uses a secondary AI model to analyze raw observations. It distills fifty lines of error logs into a single, structured concept. This semantic summary is what gets stored and eventually injected back into future sessions.

A split composition. On the left, a giant tangled pile of film strips representing raw terminal logs. On the right, a single polished diamond on a pedestal representing a semantic summary.
Raw terminal output is compressed into high-density semantic facts before storage.

The Retrieval Hierarchy

When Claude needs to remember something, it does not load the entire database. It uses a progressive disclosure model mediated by the Model Context Protocol (MCP). The search operates in three distinct layers to optimize token usage.

First, it queries SQLite for high-level session metadata. If more context is needed, it queries ChromaDB for semantic matches. Only when absolute detail is required does it fetch the raw, uncompressed tool logs.

Featureclaude-memStandard RAGMem0
IntegrationHook-based (Passive)API (Manual)API (Manual)
FocusTool-use & CLI outputDocument chunksGeneral chat history
Data StoreSQLite + ChromaDBVector DB onlyCloud / Local Vector DB
Token EfficiencyHigh (AI Compression)Low (Raw chunks)Medium

Beyond the CLI

What started as a plugin for a specific CLI tool is evolving into a broader standard for AI memory. With integrations for the Cursor editor and the OpenClaw gateway, the underlying architecture proves that stateful collaboration is the future of AI-assisted development. Developers no longer need to start from scratch. The flight recorder is always running.