[PR #6455] feat: auto-compress clipboard images to avoid API size limits #11912

Open
opened 2026-02-16 18:16:51 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6455

State: open
Merged: No


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.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6455 **State:** open **Merged:** No --- ## 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 ```bash cd packages/opencode bun test test/util/image.test.ts ``` All 23 tests pass.
yindo added the pull-request label 2026-02-16 18:16:51 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11912