Skip to content

Conversation

@noah79
Copy link

@noah79 noah79 commented Dec 30, 2025

Summary

Screenshots pasted from clipboard can exceed Claude's 5MB API limit, causing upload failures. This PR adds automatic image compression using sharp.

Changes

  • New utility: packages/opencode/src/util/image.ts

    • optimizeForUpload() - main function that compresses images to <4MB
    • Smart format selection: preserves PNG/WebP for transparency, converts opaque images to JPEG
    • Progressive quality reduction with optional resizing as fallback
  • Integration: Modified clipboard handling in clipboard.ts and prompt/index.tsx to automatically compress pasted images

  • Tests: 23 unit tests covering compression, resizing, format detection, and edge cases

Testing

cd packages/opencode
bun test test/util/image.test.ts

All 23 tests pass.

Screenshots pasted from clipboard can exceed Claude's 5MB limit.
This adds automatic image compression using sharp:

- New Image utility with compress/resize/optimize functions
- Clipboard reads now auto-compress images >4MB
- File pastes also get optimized before upload
- Transparent images stay PNG/WebP, opaque convert to JPEG
- Quality reduced iteratively until under 4MB threshold
- Includes comprehensive test suite (23 tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants