Memory: Why Long Conversations Don't Break It
Background
Claude has a token limit (~200k). On complex tasks that run long, conversation history can overflow the context window. Three strategies address this problem.
Threshold System
Context window (e.g. 200k)
└── Minus output reservation (20k) = effective window (180k)
├── Minus buffer (13k) = auto-compact trigger threshold (167k)
├── Minus (20k) = warning threshold (shows token remaining warning)
└── Near limit = blocking threshold (stops accepting new input)
Three Strategies
1. autoCompact — Automatic Compression (primary strategy)
- Trigger: Token usage reaches the auto-compact threshold
- What it does: Uses a separate Claude API call to summarize conversation history into a digest, replacing the old records
- Abuse prevention: Stops after 3 consecutive failures (circuit breaker)
- Reason: Stats show 1,279 sessions failed consecutively 50+ times, wasting ~250,000 API calls per day
- User-controlled: Can be disabled via settings or
DISABLE_AUTO_COMPACTenv variable
2. reactiveCompact — Reactive Compression (error recovery)
- Trigger: Specific API errors (
max_output_tokenstruncation,prompt_too_longoverflow) - What it does: On error, compresses context silently before retrying — invisible to the user
- Status: Feature Flag
REACTIVE_COMPACT, supplements autoCompact
3. contextCollapse — Context Collapse (experimental, aggressive)
- Trigger: Feature Flag
CONTEXT_COLLAPSEenabled - What it does: More aggressive than compression — lets Claude actively decide via
CtxInspectToolwhich content can be folded and discarded - Design philosophy: Lets Claude actively manage its own memory, similar to humans "selectively forgetting unimportant details"
How They Relate
During normal operation
→ tokens gradually grow
→ approaching threshold → [autoCompact] summarizes history, continues running
On API error
→ max_tokens / prompt_too_long → [reactiveCompact] silently compresses then retries
Context too complex (experimental)
→ [contextCollapse] Claude autonomously decides what to fold away