feat: Add clipboard image pasting with cross-platform support
Summary
Enables users to paste images directly from their clipboard into the Gemini CLI using Ctrl+V or
Shift+Insert. Images are automatically saved to .gemini-clipboard/ directory with sequential
numbering and displayed with clean [image #N] labels that convert to file references when submitted.
This feature provides seamless image sharing across all platforms including macOS, Windows, Linux, and WSL environments.
Details
Key Features:
- Cross-platform clipboard support: Works on macOS, Windows, Linux, and WSL
- WSL PowerShell integration: Detects WSL environments and uses PowerShell for clipboard access
- Sequential image numbering: Automatically names images as
image-1.png,image-2.png, etc. - Clean UI display: Shows
[image #1]in the input, converts to@.gemini-clipboard/image-1.pngon submit - Multiple keyboard shortcuts: Supports both
Ctrl+VandShift+Insert - Format detection: Automatically detects and preserves image formats (PNG, JPG, GIF, BMP, WebP, TIFF)
- Auto-cleanup: Removes clipboard images older than 1 hour
- Comprehensive testing: Full test coverage for all clipboard utilities
Implementation:
- New
clipboardUtils.tswith clipboard detection and image saving logic - WSL detection and PowerShell integration for Windows clipboard access
- Enhanced
InputPromptcomponent to handle clipboard paste events - Added
@crosscopy/clipboardpackage for cross-platform clipboard support - Image format detection via magic byte analysis
Files Changed:
packages/cli/src/ui/utils/clipboardUtils.ts- Core clipboard functionalitypackages/cli/src/ui/components/InputPrompt.tsx- UI integration and display formatpackages/cli/src/config/keyBindings.ts- Added Shift+Insert bindingpackages/cli/src/ui/utils/screenshotUtils.ts- Screenshot utilities- Test files with comprehensive coverage
Related Issues
How to Validate
On macOS/Linux:
- Copy an image to clipboard (screenshot, browser image, etc.)
- Run
npm run devornpx @google/generative-ai-cli - Press
Ctrl+VorShift+Insertin the input prompt - Verify
[image #1]appears in the input - Submit the prompt and verify the image is sent to Gemini
- Check
.gemini-clipboard/image-1.pngexists
On Windows (native):
- Copy an image to clipboard
- Run the CLI via
npm run devornpx - Press
Ctrl+Vand verify image paste works - Verify sequential numbering with multiple images
On WSL:
- Copy image in Windows (e.g., Snipping Tool, browser)
- Open WSL terminal and run the CLI
- Press
Ctrl+Vin the CLI - Verify PowerShell bridge correctly retrieves Windows clipboard image
- Check that
.gemini-clipboard/image-N.pngis created in WSL filesystem
Test sequential numbering:
- Paste multiple images one after another
- Verify they're numbered
[image #1],[image #2],[image #3], etc. - Delete one and paste again - should use next sequential number
Test cleanup:
- Create old test images with past timestamps in
.gemini-clipboard/ - Paste a new image (triggers cleanup)
- Verify old images are removed
Pre-Merge Checklist
- [x] Updated relevant documentation and README (if needed)
- [x] Added/updated tests (comprehensive test coverage added)
- [ ] Noted breaking changes (if any) - No breaking changes
- [ ] Validated on required platforms/methods:
- [ ] MacOS
- [ ] npm run
- [ ] npx
- [ ] Docker
- [ ] Podman
- [ ] Seatbelt
- [x] Windows
- [x] npm run
- [ ] npx
- [ ] Docker
- [x] Linux
- [x] npm run
- [ ] npx
- [ ] Docker\
- [ ] MacOS
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
View this failed invocation of the CLA check for more information.
For the most up to date status, view the checks section at the bottom of the pull request.
Hey tests are failing, could you take a look and fix them?