The Error
Context compressed: earlier messages may be incomplete
The Fix
# After seeing this warning, re-read any files critical to your current task
# Tell Claude: "Read src/main.ts and src/config.ts again"
# Store important context that must survive compression:
cat >> CLAUDE.md << 'EOF'
# Current Task State
- Working on: refactoring auth module
- Key file: src/auth/provider.ts
- Approach: extract validateToken into separate utility
EOF
Why This Works
When a conversation exceeds the model’s context window, Claude Code compresses earlier messages to make room. This discards details from the beginning of the session — file contents read earlier, initial instructions, and intermediate decisions. Re-reading files restores that knowledge, and persisting state in CLAUDE.md ensures it survives any future compression cycles.
If That Doesn’t Work
# Start a fresh session with explicit context
claude "Read CLAUDE.md, then continue the auth refactoring task"
# Or use the /compact command proactively before hitting limits
# This gives you control over what gets summarized
# Check conversation length:
# If you've been in one session for 30+ exchanges, start fresh
Long sessions degrade quality progressively. Fresh sessions with good CLAUDE.md context perform better than compressed continuations.
Prevention
Add to your CLAUDE.md:
For multi-step tasks, record current progress and key decisions in CLAUDE.md after each major step. Keep sessions focused on single objectives. Start new sessions rather than extending conversations beyond 25-30 exchanges.