Skip to content

fix: compact session after memory flush to prevent repeated flush loops - #3

Merged
eddmann merged 2 commits into
mainfrom
claude/fix-memory-compaction-PxSWv
Feb 25, 2026
Merged

fix: compact session after memory flush to prevent repeated flush loops#3
eddmann merged 2 commits into
mainfrom
claude/fix-memory-compaction-PxSWv

Conversation

@eddmann

@eddmann eddmann commented Feb 25, 2026

Copy link
Copy Markdown
Owner

After the flush prompt triggers and Claude saves to memory, the session
wasn't being compacted. On the next agent run, totalTokens would still
be in the flush zone, re-triggering the flush prompt. Claude would
respond "already saved" repeatedly until enough tokens accumulated to
hit the hard compaction threshold.

Now the agent compacts immediately after flush completes at end_turn,
keeping the context within budget for subsequent runs.

https://claude.ai/code/session_01NBsR2zaf5D3k63CU9bfQia

After the flush prompt triggers and Claude saves to memory, the session
wasn't being compacted. On the next agent run, totalTokens would still
be in the flush zone, re-triggering the flush prompt. Claude would
respond "already saved" repeatedly until enough tokens accumulated to
hit the hard compaction threshold.

Now the agent compacts immediately after flush completes at end_turn,
keeping the context within budget for subsequent runs.

https://claude.ai/code/session_01NBsR2zaf5D3k63CU9bfQia
If a session was already bloated past 200K tokens (e.g. from the
repeated flush loop), the LLM call would fail with a 400 error before
the agent loop could reach any compaction logic. Now the agent estimates
history tokens before entering the loop and compacts upfront if needed,
self-healing the session on the next message.

https://claude.ai/code/session_01NBsR2zaf5D3k63CU9bfQia
@eddmann
eddmann merged commit c203d20 into main Feb 25, 2026
2 checks passed
@eddmann
eddmann deleted the claude/fix-memory-compaction-PxSWv branch March 27, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants