Skip to main content

Command Palette

Search for a command to run...

I Solved Claude Code's Biggest Flaw: Context Compaction Amnesia

Published
8 min read
I Solved Claude Code's Biggest Flaw: Context Compaction Amnesia

How a frustrating afternoon led to a breakthrough that changed how I use AI forever

The Breaking Point

It was 3 AM on a Tuesday. I'd been working with Claude Code for six hours straight, architecting a complex microservices system. The conversation was long, detailed, and productive.

Until it wasn't.

Me: "Let's use PostgreSQL for the user database since our team knows SQL well and we can't hire MongoDB experts."

Claude (6 hours later): "You know, for this user data use case, MongoDB might actually be better with its flexible schema..."

I stared at the screen, dumbfounded.

Six hours. Dozens of architectural decisions. And Claude had completely forgotten the most important constraint: our team only knows SQL.

This wasn't just annoying. It was actively harmful. All that context, all those decisions, and the AI was suggesting something that would require us to hire three new developers.

That's when I realized: Claude Code has a fundamental flaw.

The Hidden Flaw: Context Compaction Amnesia

Claude Code is incredible, but it has a dirty secret. As conversations get long, it performs "context compaction" - summarizing earlier parts to make room for new information.

The problem? Compaction strips away the WHY behind decisions.

It remembers the WHAT ("Use PostgreSQL") but forgets the CONSTRAINT ("team only knows SQL") and RATIONALE ("can't hire MongoDB experts").

Without the WHY, decisions become mere suggestions that can be overridden.

Here's how it plays out in real projects:

Turn 1: "Use React not Vue — our company standardized on React last year"
Turn 15: Claude suggests Vue for a new component
Turn 30: Claude recommends a Vue-specific library
Result: Architectural inconsistency, wasted time, confused team

This isn't just a technical issue. It's a project management nightmare.

The Lightbulb Moment

The next day, I was explaining this frustration to a colleague over coffee.

"The problem," I said, "is that Claude remembers WHAT we decided, but not WHY we decided it."

He looked at me and said: "What if you could weld the WHY to the WHAT so tightly that compaction could never separate them?"

That was it. That was the solution.

What if instead of storing flat facts, we stored causal triples?

CONSTRAINT ⛔ Company standardized on React last year
     ↓
RATIONALE 💡 Team consistency and reduced training costs
     ↓
DECISION ▸ Use React not Vue

These three would be welded together. Compaction couldn't drop one without dropping all. Claude would always see the WHY.

Building Crux: The Causal Memory Graph

I spent the next two weeks building Crux - a Claude Code plugin that implements this causal memory system.

The Architecture

Crux hooks directly into Claude Code's lifecycle:

Crux Architecture Diagram
  1. SessionStart: Sets up the causal graph

  2. UserPromptSubmit: Extracts decisions from your requests

  3. PreCompact: The magic layer - injects co-inclusion rules

  4. Stop: Extracts decisions from Claude's responses

  5. SessionEnd: Cleans up for next session

The PreCompact hook is where the magic happens. Right before Claude compacts context, Crux injects strict instructions:

"You MUST NOT separate any DECISION from its RATIONALE and CONSTRAINT. These are co-included and must travel together."

The Causal Triple System

Every decision in Crux becomes a causal triple:

{
  "decision": {
    "id": "decision_123",
    "content": "Use PostgreSQL for user database",
    "dependsOn": ["rationale_123", "constraint_123"],
    "source": "user",
    "turn": 15
  },
  "rationale": {
    "id": "rationale_123", 
    "content": "Team knows SQL well and can't hire MongoDB experts",
    "dependsOn": ["constraint_123"],
    "source": "user",
    "turn": 15
  },
  "constraint": {
    "id": "constraint_123",
    "content": "Team only knows SQL databases",
    "dependsOn": [],
    "source": "user", 
    "turn": 15
  }
}

These aren't just stored - they're actively injected back into Claude's context before every compaction.

The Transformation: Before vs After

Before Crux: The Amnesia Problem

You: "Use PostgreSQL because our team knows SQL well and we can't hire MongoDB experts"
Claude: "Got it, PostgreSQL for user database."

...40 turns of development later...

Claude: "For the user analytics feature, have you considered MongoDB? Its flexible schema would be great for user behavior tracking."
You: "But we can't hire MongoDB experts..."
Claude: "Right, but you could use a managed service or hire a consultant..."

Result: Wasted time, architectural inconsistency, frustrated team.

After Crux: Co-Inclusion Guarantee

You: "Use PostgreSQL because our team knows SQL well and we can't hire MongoDB experts"
Crux: [Stores causal triple automatically]

...40 turns of development later...

Claude: "For the user analytics feature, PostgreSQL remains the best choice given your constraint that team only knows SQL and you can't hire MongoDB experts. Here's how we can optimize the queries..."

Result: Consistent architecture, respected constraints, productive development.

Real-World Impact: A Case Study

Let me show you how this transformed a real project.

The Project: E-commerce Platform

Our team was building a complex e-commerce platform. Here's how the conversation evolved:

Week 1: Foundation Decisions

You: "We'll use Next.js for frontend because our team has React experience and we need good SEO."
Crux: [Stores: CONSTRAINT=team React experience, RATIONALE=SEO needs, DECISION=Next.js]

You: "Payment processing must use Stripe because our legal team approved it and we can't use PayPal due to compliance issues."
Crux: [Stores: CONSTRAINT=compliance issues, RATIONALE=legal approval, DECISION=Stripe]

Week 3: Architecture Challenge

Claude: "For the product recommendation engine, we could use TensorFlow.js for client-side processing..."
You: "But our team only knows Python for ML..."
Claude: "Right, given your constraint that team only knows Python, let's use a Python-based recommendation service with API endpoints."

Week 6: Vendor Pressure

Stakeholder: "PayPal is offering us better rates. Can we switch?"
Claude: "Based on your constraint that PayPal has compliance issues and legal team only approved Stripe, switching is not viable without legal review. However, we can negotiate better rates with Stripe or explore hybrid solutions."

The difference was night and day.

Without Crux: Claude might have suggested switching to PayPal, causing legal issues and wasted effort.

With Crux: Claude actively protected our constraints while still helping optimize within those boundaries.

The Technical Magic: How It Actually Works

Extraction Engine

Crux uses a sophisticated extraction engine that understands natural language:

// Simplified example of extraction logic
function extractDecision(text) {
  const constraints = findConstraints(text); // "team only knows SQL", "legal approved"
  const decisions = findDecisions(text);    // "use PostgreSQL", "use Stripe"  
  const rationales = findRationales(text);  // "SEO needs", "compliance issues"
  
  return createCausalTriples(constraints, decisions, rationales);
}

The Co-Inclusion Injection

Before every context compaction, Crux injects:

--- CRUX: Active Architectural Decisions ---

DECISION: Use Next.js for frontend
RATIONALE: Team has React experience and needs good SEO  
CONSTRAINT: ⛔ Team only knows React-based frameworks

DECISION: Use Stripe for payment processing
RATIONALE: Legal team approval and compliance requirements
CONSTRAINT: ⛔ Cannot use PayPal due to compliance issues

⚠️ Respect these decisions unless explicitly asked to revisit them. Do not separate decisions from their constraints and rationales.

This injection happens automatically, invisibly, every single time.

Smart Deduplication

Crux also prevents decision pollution:

// Same decision, different wording
"We'll use PostgreSQL" vs "Let's go with Postgres" vs "PostgreSQL is our choice"

// Crux recognizes these as semantically identical
// and updates existing decision instead of creating duplicates

Zero Configuration, Maximum Impact

The best part about Crux? It works completely transparently.

No special commands. No manual configuration. No "remember this decision" prompts.

It just understands from normal conversation and protects your architectural choices automatically.

Installation

# Add the marketplace
/plugin marketplace add akashp1712/claude-marketplace

# Install Crux
/plugin install crux@akashp1712

That's it. Start coding, and Crux will automatically protect your decisions.

This Changes Everything for Long-Term Projects

For anyone using Claude Code for serious development work, this is transformative:

Team Collaboration

Everyone on the team sees the same constraints and reasoning. No more "I thought we decided to use X" conversations.

Client Work

Maintain consistency across long engagements. Decisions made in month 1 are still respected in month 6.

Complex Architecture

Multiple interconnected decisions stay coherent. The payment system choice respects the legal constraints. The frontend choice respects the team skills.

Peace of Mind

No more waking up at 3 AM wondering if Claude is going to suggest something contradictory tomorrow.

The Future of AI Memory

Crux is just the beginning. As AI becomes more integrated into our development workflows, we need better memory systems:

Roadmap v0.2: Conflict Detection

When you say "Use PostgreSQL" and later "Use MongoDB", Crux will flag: "This contradicts your earlier decision about team skills."

Roadmap v0.3: Team Graphs

Git-committable decision graphs for team sharing. Everyone sees the same architectural constraints.

Roadmap v1.0: The Proxy

Protocol-level interception for exact control over context compaction.

Try It Yourself

I've open-sourced Crux under MIT license. It's production-ready, zero-dependency, and works with Claude Code immediately.

Get started: https://github.com/akashp1712/claude-crux

Full marketplace: https://github.com/akashp1712/claude-marketplace

Join the Movement

Context compaction amnesia is a problem every serious Claude Code user faces. We don't have to accept it.

If you've ever been frustrated by your AI forgetting important constraints, try Crux. If you're building AI tools, think about causal memory, not just flat facts.

Share your experiences: Let me know how Crux changes your workflow.

Contribute: The project is open for contributions - new extraction patterns, better UI, conflict detection.


Because your AI should remember WHY, not just WHAT.