Memory management in Claude Code: Session Memory and Safe Compaction

Dev.to AI
Generative AI

This is Part 2 of the series. If you have not read the first post yet, start with Part 1. In Part 1, I looked at the first half of the memory pipeline: slicing history after the last compact boundary budgeting large tool results using microcompact for cheap cleanup triggering auto-compact with a policy instead of a last-second token check That already solves a big part of the problem. But once those cheaper layers are no longer enough, the system needs to do something expensive without losing important working context, breaking message structure, or getting stuck in recovery loops.