Context Cases: Surviving AI Context Compaction

AI coding agents lose context when their conversation window fills up. Claude Code handles this by compacting — summarizing the conversation to free space. But the summary loses critical details about your active work. We built Context Cases to solve this.

The Approach

Instead of stuffing everything into static CLAUDE.md files (which burn tokens on every message), CaseMgr stores knowledge in cases and loads it dynamically when needed.

Context Cases are regular CaseMgr cases that you link to your working case. After compaction, the system automatically loads your active tasks plus all notes and knowledge from linked context cases.

Example

You’re working on a feature case. You link two context cases:

  • System Knowledge — Server configs, SSH access, deployment procedures, architecture decisions
  • Client Requirements — Specs, constraints, billing preferences

When compaction happens, Claude automatically recovers all of this — no manual re-explanation needed.

Setting It Up

1. Create Your Context Cases

Create a case for each category of knowledge you want to persist. Add notes with the information Claude needs — environment configs, debugging procedures, test credentials, architecture facts.

2. Link Them

In the case detail view, expand the Context Cases section (below Worktrees), click + Link, and select the cases you want as context.

Or via MCP:

wa mcp graph-link from_id="#1:100" to_id="#1:200" link_type=context

3. Configure the Recovery Hook

Add a PostCompact hook to your project’s .claude/settings.json:

{
  "hooks": {
    "PostCompact": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"hookSpecificOutput\":{\"hookEventName\":\"PostCompact\",\"additionalContext\":\"CONTEXT COMPACTED. Call preferences-get to find current case, then cmmn-get_resume_context to reload work state.\"}}'",
            "timeout": 5
          }
        ]
      }
    ]
  }
}

4. Add Recovery to ~/.claude/CLAUDE.md

## Post-Compaction Recovery (MANDATORY)

After every context compaction, you MUST immediately:
1. Call `preferences-get` to find the current case ID
2. If a current case exists, call `cmmn-get_resume_context` with that case ID
3. Resume work from where you left off

The Principle

CLAUDE.md is the bootstrap. CaseMgr is the knowledge base.

Keep instruction files small and static. Put everything dynamic, detailed, or case-specific into CaseMgr cases and link them as context. The system loads what’s needed, when it’s needed.

Full setup guide: casemgr.systems/context-cases

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *