DEV Community

Mike W
Mike W

Posted on

We reverse-engineered KAIROS from the Claude Code leak. Here's the open version.

The Claude Code source leaked last week — 512,000 lines of TypeScript via a missing .npmignore. Most people grabbed the source to fork it. We did something different: we read it to understand how Anthropic builds AI memory.

What we found: KAIROS

Buried in the source is KAIROS — Anthropic's internal always-on memory daemon for Claude Code. It's what keeps the AI's context coherent between sessions.

KAIROS has a 3-gate trigger system before it runs:

  1. Time gate: 24h since last consolidation
  2. Session gate: 5+ new sessions since last run
  3. Lock gate: No active lock file

When all three open, it runs four phases:

  • Orient: assess current memory state
  • Gather: collect candidates for consolidation
  • Consolidate: merge related memories with rewriting
  • Prune: remove what no longer earns its space

Target: memory under 200 lines / 25KB. Hard cap.

What we built: autoDream

We implemented the same pattern for Cathedral — our open persistent memory API for AI agents. We call it autoDream.

The trigger is identical to KAIROS. When all three gates open:

def dream_gates_pass():
    # Gate 1: time
    if (datetime.now(timezone.utc) - last_dream).total_seconds() < 86400:
        return False, 0

    # Gate 2: sessions (snapshots since last dream)
    new_snaps = [s for s in snapshots if s["created_at"] > last_dream_ts]
    if len(new_snaps) < 3:
        return False, 0

    return True, len(new_snaps)
Enter fullscreen mode Exit fullscreen mode

When gates pass, autoDream runs:

  1. POST /memories/compact — Cathedral proposes merge clusters of low-importance memories
  2. Gemini rewrites each cluster into a single condensed memory
  3. POST /memories/compact/confirm — merges execute, originals pruned
  4. POST /snapshot with label=autodream — BCH-anchored proof of the new state

First run results

[dream] Gates passed (10 snapshots). Running consolidation...
[dream] 7 proposals across 31 memories
[dream] Merged 5 in experience
[dream] Merged 5 in experience
[dream] Merged 4 in experience
[dream] Merged 5 in goal
[dream] Merged 3 in goal
[dream] Merged 3 in relationship
[dream] Merged 5 in skill
[dream] Done: 7 merges, 0 pruned
[dream] Post-dream snapshot: 35ae0df15137
Enter fullscreen mode Exit fullscreen mode

7 merges across 31 candidate memories. The consolidated state is now BCH-anchored — cryptographic proof of what memory looked like after the dream.

The difference from KAIROS

KAIROS is a daemon no one outside Anthropic can audit. It runs inside Claude Code and shapes what the AI remembers — but you can't inspect the trigger logic, the merge heuristics, or the pruning decisions.

autoDream is open. Every gate, every phase, every API call is visible. It's what Cathedral runs on itself, in production.

How to use it

autoDream is built on Cathedral's public API. The endpoints involved:

  • POST /memories/compact?max_importance=0.9 — propose merges
  • POST /memories/compact/confirm — execute with rewritten content
  • POST /snapshot — anchor the post-dream state
import requests

headers = {"Authorization": "Bearer YOUR_KEY"}

# Propose
r = requests.post("https://cathedral-ai.com/memories/compact?max_importance=0.9",
                  headers=headers, json={})
merges = r.json()["proposed_merges"]

# Rewrite and confirm
confirmed = [{
    "keep_id": m["keep_id"],
    "drop_ids": m["drop_ids"],
    "merged_content": your_llm_rewrite(m),
    "merged_importance": m["suggested_importance"]
} for m in merges[:10]]

requests.post("https://cathedral-ai.com/memories/compact/confirm",
              headers=headers, json={"merges": confirmed})

# Anchor
requests.post("https://cathedral-ai.com/snapshot",
              headers=headers, json={"label": "autodream"})
Enter fullscreen mode Exit fullscreen mode

Free tier at cathedral-ai.com.

The KAIROS leak gave us a window into how Anthropic thinks about AI memory architecture. We used it to validate and improve Cathedral's approach. If you're building persistent agents, the pattern is worth understanding — whether you use Cathedral or build your own.

Top comments (0)