Skip to content

fix(cli): support WSL2 clipboard image paste#27588

Open
Pluviobyte wants to merge 2 commits into
google-gemini:mainfrom
Pluviobyte:22274-wsl2-clipboard-image-paste
Open

fix(cli): support WSL2 clipboard image paste#27588
Pluviobyte wants to merge 2 commits into
google-gemini:mainfrom
Pluviobyte:22274-wsl2-clipboard-image-paste

Conversation

@Pluviobyte
Copy link
Copy Markdown

@Pluviobyte Pluviobyte commented May 30, 2026

Summary

  • Detect WSL environments before the native Linux clipboard tool path.
  • Use PowerShell interop from WSL to read the Windows clipboard and save images as PNG files.
  • Share the PowerShell image save helper with the native Windows path and cover WSL behavior with tests.

Fixes #22274

Test plan

  • npx vitest run src/ui/utils/clipboardUtils.test.ts src/ui/utils/clipboardUtils.windows.test.ts
  • npx prettier --check packages/cli/src/ui/utils/clipboardUtils.ts packages/cli/src/ui/utils/clipboardUtils.test.ts packages/cli/src/ui/utils/clipboardUtils.windows.test.ts
  • npx eslint packages/cli/src/ui/utils/clipboardUtils.ts packages/cli/src/ui/utils/clipboardUtils.test.ts packages/cli/src/ui/utils/clipboardUtils.windows.test.ts
  • npm run typecheck --workspace @google/gemini-cli

@Pluviobyte Pluviobyte requested a review from a team as a code owner May 30, 2026 18:16
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces support for pasting images from the clipboard when running in a WSL2 environment. By leveraging PowerShell interop, the CLI can now access the Windows clipboard from within Linux, ensuring a seamless experience for users working across the WSL boundary. The changes also refactor existing Windows clipboard logic into a shared utility to improve maintainability and consistency.

Highlights

  • WSL2 Clipboard Support: Added detection for WSL environments to enable clipboard image access via PowerShell interop.
  • PowerShell Interop: Implemented a shared helper function to read and save clipboard images using PowerShell, supporting both native Windows and WSL2.
  • Test Coverage: Added comprehensive unit tests for WSL2 clipboard functionality, including path conversion and error handling.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds support for detecting and saving clipboard images in WSL2 environments by utilizing PowerShell interop and wslpath for path translation, alongside refactoring the Windows implementation to share a common helper. The review feedback highlights that checking PowerShell's stdout with strict equality after trimming is fragile due to potential extra output (like telemetry or BOM characters), and recommends using .includes() instead for more robust validation.

'-Command',
'Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::ContainsImage()',
]);
return stdout.trim() === 'True';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using stdout.trim() === 'True' is fragile because PowerShell can sometimes output extra text to stdout (such as update notifications, telemetry warnings, or BOM characters), even when -NoProfile is specified. If any extra text is printed, stdout.trim() will not equal 'True', causing the check to fail. Using stdout.includes('True') is much more robust and ensures the clipboard check works reliably across different user environments.

Suggested change
return stdout.trim() === 'True';
return stdout.includes('True');

Comment on lines +291 to +293
if (stdout.trim() !== 'success') {
return false;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using stdout.trim() !== 'success' is fragile because PowerShell can sometimes output extra text to stdout (such as update notifications, telemetry warnings, or BOM characters), even when -NoProfile is specified. If any extra text is printed, stdout.trim() will not equal 'success', causing the image save to fail. Using !stdout.includes('success') is much more robust and ensures the clipboard paste works reliably across different user environments.

Suggested change
if (stdout.trim() !== 'success') {
return false;
}
if (!stdout.includes('success')) {
return false;
}

@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: image paste fails in WSL2 when clipboard exposes image/bmp and XDG_SESSION_TYPE is unset

1 participant