◉CLAUDE LABJP
●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…●2.1.301 — Adds the vim % motion, LaTeX math rendering in the VS Code panel, and a retry-watchdog limit for usage-limit waits (10/15)●2.1.299 — Conversations over 200K tokens left idle about 54 minutes get compacted; MCP allow rules now match only the server they name●SONNET 4.5 — Retires on the Claude API on 11/30, 45 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST MODE — Opus 5.5 fast mode is out of research preview and no longer needs the beta header (10/15)●NEW — I Put a Ten-Line Promise File at the To…
Articles/API & SDK
⬡ API & SDK/2026-06-14Advanced

Wiring Claude's Dreaming Into Memory Hygiene for Long-Running Agents

Managed Agents' Dreaming reviews past sessions and rewrites memory as a self-improvement loop. We unpack the published Harvey and Wisedocs numbers, build a complete self-hosted consolidation loop with the Anthropic SDK, and cover the production pitfalls.

managed-agents6memory9agent-sdk4production111

✦ Premium Article

When you let autonomous agents run four technical blogs as an indie developer, the memory files those agents write balloon to dozens of entries within a few months. At first it was a gift: the agent remembered "we tried this fix before and it failed." But as the count grew, old facts and new facts started colliding quietly. A note from six months ago said "this flag was disabled," while a newer note said "the same flag was re-enabled." The agent had no way to know which to trust, and its judgment dulled.

The Dreaming feature (research preview) for Managed Agents, announced at the June 2026 Code w/ Claude developer conference, tackles exactly this problem. It periodically reviews past sessions and memory, extracts patterns, and updates the agent itself. It folds the "memory inventory" I had been doing by hand into the agent's own operating loop. This article unpacks the thinking behind Dreaming, then shows a self-hosted consolidation loop you can build today with the Anthropic SDK, complete with working code.

Why agents with more memory often make worse decisions

Left alone, a long-running agent's memory grows monotonically. Append "what I learned" every session and you reach dozens of entries in half a year, sometimes past a hundred in a year.

The problem isn't the count itself; it's that facts of wildly different freshness sit side by side. In my case, three notes about the same setting existed across different points in time. Only the newest was correct; the other two were already wrong. The agent loaded all three as equally valid "past learnings" and got dragged back toward the old instructions, re-introducing a bug I had already fixed.

A human team periodically reviews its docs and deletes outdated lines. An agent's memory, however, tends to become an append-only log that nobody prunes. Dreaming makes more sense once you see it as a mechanism for handing that pruning to the agent itself.

Dreaming folds session records into knowledge you can use

The core of Dreaming is that it does not hoard raw session history. Instead it extracts recurring patterns and folds them into more general knowledge.

Suppose several sessions in a row read "the API timed out, so I retried with exponential backoff." A naive memory adds one record each time: "On date X, resolved a timeout with a retry." Dreaming looks across them and rewrites them into one level-up policy: "This workload sees intermittent timeouts, so exponential backoff should be the default from the start."

This is the same thing I was attempting by hand: delete the individual events, keep only the judgment they taught. The difference is that Dreaming runs that loop autonomously on a schedule.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦How Dreaming folds past sessions into reusable knowledge, and how to read the published Harvey (~6x task completion) and Wisedocs (50% review-time cut) numbers
✦A complete Python consolidation loop built on the Anthropic SDK: duplicate detection, staleness flags, and index regeneration
✦Which workloads Dreaming helps versus hurts, plus three production pitfalls and their fixes
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⬡ API & SDK2026-09-08
Writing 25 as your session budget caps it at twenty-five cents
Managed Agents session budgets are expressed in minor units as a string. Here is how I mixed up the unit, hit budget_reached in minutes, and what raising versus clearing a budget actually does.
⬡ API & SDK2026-07-28
The Line That Disappears at 100K: Measuring What Tool-Output Spill Actually Keeps
When agent tool output passes 100,000 characters, the full text spills to a file and the model sees only a head-truncated preview. Here are measured survival rates from a real repository, and the output envelope I built to push decision-relevant lines to the front.
⬡ API & SDK2026-05-26
Stabilizing Claude API Structured Responses in Production — Notes on tool_use, JSON Schema, and Layered Validation
Getting Claude to return JSON takes a few lines. Keeping that JSON usable in production is a different problem. Here is the layered design I landed on after running a wallpaper classification pipeline through Claude API, built around tool_use, JSON Schema, and domain validation.