Context compaction drops media_type from base64 images, causing API 400 errors
Resolved 💬 2 comments Opened Mar 20, 2026 by saju01 Closed Apr 17, 2026
Bug
After context compaction in a long session, the API returns:
API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.106.content.2.image.source.base64.media_type: Field required"}}
Steps to Reproduce
- Start a long Claude Code session
- Paste/share a screenshot during the conversation (e.g. a Vercel error screenshot)
- Continue working until context compaction triggers
- After compaction, subsequent messages fail with the 400 error above
Expected Behavior
Context compaction should either:
- Preserve the
media_typefield when retaining image content - Or strip the entire image block (base64 + media_type) if it's being removed from context
Actual Behavior
Compaction appears to retain the base64 image data but drops the required media_type field (image/png, image/jpeg, etc.), causing all subsequent API calls to fail with invalid_request_error.
Workaround
Starting a fresh session (/clear or new terminal) resolves the issue since the corrupted image reference is discarded.
Environment
- Claude Code (latest)
- macOS Darwin 25.3.0 (ARM64)
- Model: claude-opus-4-6
- Long session with multiple screenshots shared earlier in conversation
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗