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

Open
opened 2026-02-16 18:06:24 -05:00 by yindo · 1 comment
Owner

Originally created by @HaD0Yun on GitHub (Jan 22, 2026).

Originally assigned to: @rekram1-node on GitHub.

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 implementation
if (os === "win32" || release().includes("WSL")) {
  // Attempts to call powershell.exe directly
  await $`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 paths
const findClipExe = (): string | null => {
  const paths = [
    "/mnt/c/Windows/System32/clip.exe",
    "/mnt/d/Windows/System32/clip.exe"
  ];
  for (const p of paths) {
    if (existsSync(p)) return p;
  }
  return null;
};

const findPowerShell = (): string | null => {
  const paths = [
    "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe",
    "/mnt/d/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
  ];
  for (const p of paths) {
    if (existsSync(p)) return p;
  }
  return null;
};

// WSL-specific clipboard handling
if (os === "linux" && isWSL()) {
  const clipExe = findClipExe();
  const powershell = findPowerShell();
  
  // Use clip.exe for copy operations
  // Use PowerShell Get-Clipboard for read operations
}

Implementation Details

Operation Recommended Tool Path
Copy clip.exe /mnt/c/Windows/System32/clip.exe
Read PowerShell 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.

Originally created by @HaD0Yun on GitHub (Jan 22, 2026). Originally assigned to: @rekram1-node on GitHub. ## 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: ```typescript // Current implementation if (os === "win32" || release().includes("WSL")) { // Attempts to call powershell.exe directly await $`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: ```typescript // Helper functions to locate Windows executables via WSL mount paths const findClipExe = (): string | null => { const paths = [ "/mnt/c/Windows/System32/clip.exe", "/mnt/d/Windows/System32/clip.exe" ]; for (const p of paths) { if (existsSync(p)) return p; } return null; }; const findPowerShell = (): string | null => { const paths = [ "/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe", "/mnt/d/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" ]; for (const p of paths) { if (existsSync(p)) return p; } return null; }; // WSL-specific clipboard handling if (os === "linux" && isWSL()) { const clipExe = findClipExe(); const powershell = findPowerShell(); // Use clip.exe for copy operations // Use PowerShell Get-Clipboard for read operations } ``` ### Implementation Details | Operation | Recommended Tool | Path | |-----------|-----------------|------| | Copy | clip.exe | `/mnt/c/Windows/System32/clip.exe` | | Read | PowerShell 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 - WSL interoperability documentation: https://docs.microsoft.com/en-us/windows/wsl/filesystems - Windows clipboard utilities are accessible from WSL via `/mnt/c/Windows/System32/` Thank you for considering this issue. I would be happy to provide additional information or submit a pull request if needed.
yindo added the windows label 2026-02-16 18:06:24 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 22, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #5879: Clipboard copy in WSL

Feel free to ignore if this doesn't address your specific case.

@github-actions[bot] commented on GitHub (Jan 22, 2026): This issue might be a duplicate of existing issues. Please check: - #5879: Clipboard copy in WSL Feel free to ignore if this doesn't address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7184