As The Geek Learns
As The Geek Learns
Cortex: An Event-Sourced Memory Architecture for AI Coding Assistants
0:00
-18:02

Cortex: An Event-Sourced Memory Architecture for AI Coding Assistants

As The Geek Learns | Technical Deep Dive Author: James Cruce Date: February 2026

Cortex: Event-Sourced Memory for AI Coding Assistants

Episode Summary

Every time you close a session with an AI coding assistant, it forgets everything—the architecture it mapped out, the approaches it rejected, and the plan it was halfway through executing. You become the memory system. Cortex is an event-sourced memory architecture designed to fix that. In this episode, we walk through the problem, the research process that led to the solution, how the system works across four progressive tiers, and real-world A/B testing results that show an 84% reduction in cold start time and 80% fewer decision regressions.

Suggested Episode Segments

  • 00:00—Intro: The amnesia problem with AI coding assistants

  • 01:22—What actually gets lost between sessions (five categories)

  • 03:26—Why event sourcing is the right foundation

  • 05:32—Three-layer extraction: structural, semantic, and self-reporting

  • 07:24—Projected briefings and decision immortality

  • 08:59—Progressive tiers: from 30-second setup to full MCP server

  • 12:13—A/B testing results and what surprised us

  • 12:43—Implementation war stories and gotchas

  • 13:03—The meta-irony of building this with a forgetful AI

  • 13:40—Tier 3: MCP server, git-tracked projections, branch alignment

  • 14:59—Getting started and what’s next

The Problem

AI coding assistants like Claude lose five categories of context at session boundaries: architectural understanding built through exploration (10-30 minutes of re-exploration per session), decision history including rejected approaches and reasoning, work state like multi-step plans and progress, tool and environment state, and conversational nuance—your preferences, priorities, and communication style. The cruelest part is that the better the AI performs within a session, the more painful the loss when that session ends.

The Solution

Cortex applies event sourcing—an immutable, append-only pattern borrowed from distributed systems—to capture and preserve context automatically. Three innovations make it work.

First, three-layer event extraction. Layer 1 parses Claude Code hook payloads for objective structural data like file reads, commands, and code modifications—100% accuracy within its scope. Layer 2 pattern-matches response text for decision markers with confidence scoring. Layer 3 lets Claude self-report important context using [MEMORY:] tags, offering the highest accuracy through deliberate intent. These independent extractors compose through aggregation rather than requiring one monolithic system.

Second, projected briefings. Raw event replay would blow through token budgets, so Cortex generates compressed, token-aware briefings that default to about 2,000 tokens—roughly 0.1% of the context window. Active decisions are immortal and never decay. Current plans show progress with step status. Recent knowledge fades over sessions based on tactical relevance. This separates retention (store everything) from representation (surface what matters).

Third, progressive tiers. Tier 0 gives you basic context capture in 30 seconds. Tier 1 adds SQLite with full-text search. Tier 2 brings vector embeddings and anticipatory retrieval. Tier 3 enables an MCP server for mid-session queries, git-tracked projections, and branch-level context isolation.

Results

A/B testing across 18 Cortex sessions versus 11 baseline sessions showed measurable gains: an 84% reduction in cold start file re-reading, 80% fewer decision regressions where the AI re-suggested previously rejected approaches, and only 0.2% token overhead for the entire memory system. The system ships with 713 passing tests.

Implementation Gotchas

A few hard-won lessons from the build: every .get() call needs a default value, and every JSON parse needs a try/except because Claude Code hooks cannot afford to crash. Content-hash deduplication scopes to session ID to prevent over-deduplication. And the gitleaks GitHub Action requires paid licenses for org accounts, while the CLI stays free—a distinction that cost some debugging time.

The Meta-Irony

The entire project was designed and built using Claude Code—an AI assistant suffering from the exact problem being solved. Every session boundary during development was a visceral reminder of why this system needed to exist.

Key Quotes

  • “The cruelest aspect: the better the AI performs within a session, the more painful the loss when the session ends. Excellence within a session amplifies the frustration at its boundary.”

  • “You can always trace back to ‘Why did the system think X?’ — that’s the power of event sourcing over CRUD.”

  • “Confidence as a first-class field enables downstream flexibility—briefing sorting, decay functions, user-tunable thresholds.”

Links

Discussion about this episode

User's avatar

Ready for more?