Skip to content

[Bug] Clipboard functionality fails in WSL environment due to missing Windows executable paths #9999

Description

@HaD0Yun

Summary

The clipboard functionality in OpenCode does not work correctly in Windows Subsystem for Linux (WSL) environments. The current implementation attempts to use Windows clipboard utilities but fails because the executables are not available in the default PATH within WSL.

This issue recurs with every OpenCode update, requiring users to manually patch the clipboard functionality each time a new version is released. This significantly impacts the user experience for WSL users.

Environment

  • OS: Windows Subsystem for Linux (WSL2)
  • Host OS: Windows 10/11
  • OpenCode Version: Latest (issue persists across multiple versions)

Problem Description

The current clipboard implementation in clipboard.ts detects WSL environments but fails to access Windows clipboard utilities:

// Current implementationif(os==="win32"||release().includes("WSL")){// Attempts to call powershell.exe directlyawait$`powershell.exe -NonInteractive ...`}

Root Cause

  1. In WSL environments, powershell.exe and clip.exe are not in the default PATH
  2. Bun.which("powershell.exe") returns null because these executables cannot be found
  3. The clipboard operations silently fail or throw errors

Expected Behavior

Clipboard copy and read operations should work seamlessly in WSL environments, utilizing the Windows clipboard through proper executable paths.

Actual Behavior

  • Clipboard operations fail because the Windows executables cannot be located
  • Users must manually patch the code after every update to restore clipboard functionality
  • This creates an ongoing maintenance burden for WSL users

Proposed Solution

Implement WSL-specific logic that uses absolute paths to Windows system executables:

// Helper functions to locate Windows executables via WSL mount pathsconstfindClipExe=(): string|null=>{constpaths=["/mnt/c/Windows/System32/clip.exe","/mnt/d/Windows/System32/clip.exe"];for(constpofpaths){if(existsSync(p))returnp;}returnnull;};constfindPowerShell=(): string|null=>{constpaths=["/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe","/mnt/d/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"];for(constpofpaths){if(existsSync(p))returnp;}returnnull;};// WSL-specific clipboard handlingif(os==="linux"&&isWSL()){constclipExe=findClipExe();constpowershell=findPowerShell();// Use clip.exe for copy operations// Use PowerShell Get-Clipboard for read operations}

Implementation Details

OperationRecommended ToolPath
Copyclip.exe/mnt/c/Windows/System32/clip.exe
ReadPowerShell Get-Clipboard/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe

Impact

  • Severity: Medium - Clipboard is a frequently used feature
  • Affected Users: All WSL users
  • Workaround Burden: Manual code patching required after every update

Additional Context

This issue affects all WSL users who rely on clipboard functionality for copying code snippets, file paths, or other content between OpenCode and Windows applications. The recurring nature of this problem after each update makes it particularly frustrating for users who depend on this functionality.

References

Thank you for considering this issue. I would be happy to provide additional information or submit a pull request if needed.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions