Skip to content

Conversation

@prajwalr308
Copy link

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.png
    on submit
  • Multiple keyboard shortcuts: Supports both Ctrl+V and Shift+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.ts with clipboard detection and image saving logic
  • WSL detection and PowerShell integration for Windows clipboard access
  • Enhanced InputPrompt component to handle clipboard paste events
  • Added @crosscopy/clipboard package for cross-platform clipboard support
  • Image format detection via magic byte analysis

Files Changed:

  • packages/cli/src/ui/utils/clipboardUtils.ts - Core clipboard functionality
  • packages/cli/src/ui/components/InputPrompt.tsx - UI integration and display format
  • packages/cli/src/config/keyBindings.ts - Added Shift+Insert binding
  • packages/cli/src/ui/utils/screenshotUtils.ts - Screenshot utilities
  • Test files with comprehensive coverage

Related Issues

How to Validate

On macOS/Linux:

  1. Copy an image to clipboard (screenshot, browser image, etc.)
  2. Run npm run dev or npx @google/generative-ai-cli
  3. Press Ctrl+V or Shift+Insert in the input prompt
  4. Verify [image #1] appears in the input
  5. Submit the prompt and verify the image is sent to Gemini
  6. Check .gemini-clipboard/image-1.png exists

On Windows (native):

  1. Copy an image to clipboard
  2. Run the CLI via npm run dev or npx
  3. Press Ctrl+V and verify image paste works
  4. Verify sequential numbering with multiple images

On WSL:

  1. Copy image in Windows (e.g., Snipping Tool, browser)
  2. Open WSL terminal and run the CLI
  3. Press Ctrl+V in the CLI
  4. Verify PowerShell bridge correctly retrieves Windows clipboard image
  5. Check that .gemini-clipboard/image-N.png is created in WSL filesystem

Test sequential numbering:

  1. Paste multiple images one after another
  2. Verify they're numbered [image #1], [image #2], [image #3], etc.
  3. Delete one and paste again - should use next sequential number

Test cleanup:

  1. Create old test images with past timestamps in .gemini-clipboard/
  2. Paste a new image (triggers cleanup)
  3. Verify old images are removed

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • 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
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker\

prajwalr308 and others added 30 commits November 21, 2025 09:48
- Remove debug logging from InputPrompt.tsx
- Remove test scripts (test-clipboard-wsl.sh, copy-test-image.ps1)
- Remove TEST-CLIPBOARD-PASTE.md
- Add .gemini-debug.log to .gitignore
- Remove test clipboard image artifacts
…support

- Changed image filenames from timestamp-based (clipboard-1234567890.png) to sequential numbering (image-1.png, image-2.png)
- Updated display format to show friendly labels: [image google-gemini#1] @path instead of just @path
- Added Shift+Insert as alternative paste key binding for PowerShell compatibility (PowerShell intercepts Ctrl+V)
- Updated cleanup function to handle both old and new filename formats

This addresses the PowerShell Ctrl+V limitation and improves UX with clearer image references.
Changed from "[image #N] @path" to just "@path" for cleaner display.
Users will see "@.gemini-clipboard/image-1.png" instead of the verbose format.
@google-cla
Copy link

google-cla bot commented Nov 22, 2025

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.

Users now see clean labels like [image google-gemini#1], [image google-gemini#2] instead of full paths.
The system automatically transforms these to @.gemini-clipboard/image-N.png when submitting.

Display: [image google-gemini#1] [image google-gemini#2]
Internal: @.gemini-clipboard/image-1.png @.gemini-clipboard/image-2.png
@prajwalr308 prajwalr308 marked this pull request as ready for review November 22, 2025 11:34
@prajwalr308 prajwalr308 requested review from a team as code owners November 22, 2025 11:34
@SandyTao520
Copy link
Collaborator

Hey tests are failing, could you take a look and fix them?

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.