← Blog

Engineering note

Andrej Karpathy Just Fixed Claude Code's Biggest Weakness: Letting AI "Dream"

Andrej Karpathy Just Fixed Claude Code's Biggest Weakness: Letting AI "Dream" AI Agent Practice Bloss0m Note 082

Nine months ago, Andrej Karpathy—one of the brightest minds in AI, now back at Anthropic—highlighted what he considered the most fundamental flaw in modern Large Language Models (LLMs) and AI Agents during an interview:

“I feel like when I’m awake, I’m building up a context window of stuff that’s happening during the day. But when I go to sleep, something magical happens… a process of distillation into the weights of my brain. We don’t have an equivalent of that in LLMs. When you boot them up, they have zero tokens in the window. They’re always restarting from scratch.”

To solve this biological missing link, Anthropic has officially introduced Dreaming into Claude Code. This global memory consolidation mechanism has fundamentally transformed how agents learn, yielding a staggering 6x increase in task completion rates for early enterprise adopters like Harvey and Rakuten.

1. The Three Fatal Flaws of In-Band Memory

Before the Dreaming feature, developers typically maintained a MEMORY.md file and instructed Claude Code via system prompts: “While completing your task, please write any new preferences or rules you learn into MEMORY.md.”

Anthropic identifies three severe problems with this “in-band memory” approach:

  1. Split Focus: The agent’s attention is forcibly divided. It is simultaneously trying to solve a complex coding problem and maintain a documentation file. This drains context capacity and dilutes performance.
  2. Patterns Obfuscated: An agent operating in a single session is like an NBA coach watching one game out of an 84-game season and trying to reconstruct the entire team’s roster based on that single performance. Without a cross-session perspective, the agent fails to recognize broader behavioral patterns.
  3. Memories Go Stale: Because individual agents write to memory independently, MEMORY.md quickly fills with duplicate or conflicting rules. It might also retain deprecated architectural decisions from six months ago. Relying on a stale memory file is as disastrous as Google Maps confidently navigating you based on 10-year-old road data.

2. What is Dreaming?

Anthropic’s solution to these flaws is exactly what Karpathy envisioned: Dreaming.

Dreaming is an asynchronous background process that scans all recent agent sessions and transcripts to identify recurring patterns, mistakes, and new preferences. It automatically distills this raw data into organized, up-to-date, and conflict-free memory content.

The ultimate goal of Dreaming is continuous self-learning and self-improvement—ensuring that tomorrow’s agent is automatically smarter and better aligned than today’s, entirely based on the learnings of the previous day.

3. Implementation: Building Your Own “Dream Gate”

While Anthropic’s official Dreaming feature is currently aimed at enterprise customers and continuously consumes API credits, you can perfectly replicate this logic locally using a Dream Routine.

By setting up an automated schedule (e.g., running every night at 3:00 AM), you can orchestrate Claude Code to execute a “Foresight Dream” skill:

The Core Logic of a Dream Routine

  1. Read Transcripts: The script ingests all conversation logs generated across different sessions over the past 24 hours.
  2. Compare & Reconcile: It cross-references these logs against the current state of MEMORY.md.
  3. Extract & Clean:
    • Identify new facts, developer preferences, and coding habits worth retaining.
    • Flag stale, deprecated, or confidently wrong memories for deletion.
    • Merge duplicate rules into a single source of truth.
  4. Generate Report: It outputs a numbered list of proposed changes—each backed by a direct quote from the transcript as evidence—into a DREAM_REPORT.md file.
  5. Auto-apply Safe Fixes: Extremely safe changes (like typo corrections) can be auto-applied. However, significant architectural memory updates are held at the Dream Gate for the developer to manually approve or reject over morning coffee.

This mechanism makes it feel like you have a highly observant technical co-founder working beside you—one who reviews every interaction while you sleep, continuously optimizing your team’s workflow.

When AI agents finally gain the ability to convert short-term context into long-term stable weights, we will have truly entered the era of continuous, time-aware AI Engineering.

For speaking invitations, internal engineering sessions, or architecture exchange, see the topics and public work I can bring into the conversation.

Speaking & contact