[BUG] Dropping image triggers compact error — double-ESC revert loses context and code
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When dropping/pasting an image into the Claude Code CLI (especially during or after extended sessions), it frequently triggers a compact error (context limit or "Error compacting conversation"). The only recovery path is pressing ESC twice to revert, but this discards context and sometimes code that was generated in the session. This is a destructive data-loss scenario with no alternative recovery.
Steps to Reproduce
- Start a Claude Code session and work on tasks until context usage is moderate-to-high (40-70%+)
- Drop an image (screenshot, diagram, etc.) into the terminal via drag-and-drop or Cmd+V paste
- Observe: compact error / context limit error appears
- Press ESC twice to dismiss and revert
- Observe: previous context, including generated code and conversation history, may be lost
Expected Behavior
- Image size validation before adding to context — if the image would push context over the limit, warn the user before committing it, with options to resize, skip, or compact first
- Non-destructive recovery — if compaction fails after an image is added, the revert should restore to the state before the image was added, not lose prior context
- Auto-resize large images — images should be automatically resized/compressed to fit within API limits before being added to context
- Graceful degradation — instead of a hard error + destructive revert, offer options like "Remove this image and continue?" or "Compact conversation (excluding this image) and retry?"
Impact
This is particularly painful in long sessions where significant work has been done (code generation, multi-file edits, debugging). Losing that context means re-explaining the entire task or starting a new session and losing all progress.
Environment
- Claude Code version: 2.1.42
- OS: macOS (Darwin 25.1.0)
- Terminal: iTerm2
- Model: Opus 4.6
Related Issues
- #16649 — compaction fails on sessions with pasted screenshots (base64 images)
- #23989 — premature context limit at ~51% when submitting image during processing
- #24387 — corrupted image in context permanently breaks session
- #20021 — image base64 size exceeds API limit
This issue is distinct because the core problem is destructive context loss during the recovery flow, not just the compaction failure itself.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗