CCAPrep
← All labs
D5·Fix the code

Compaction state thrown away

A long-running assistant enables compaction so conversations can outlive the context window. It works for a while, then starts losing earlier context entirely — as if compaction never ran.

response = client.beta.messages.create(
    betas=["compact-2026-01-12"],
    model="claude-opus-5",
    max_tokens=16000,
    context_management={"edits": [{"type": "compact_20260112"}]},
    messages=messages,
)

reply = next(b.text for b in response.content if b.type == "text")
messages.append({"role": "assistant", "content": reply})

1.What is being lost?

2.What should be appended to the history?