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
- In WSL environments,
powershell.exe and clip.exe are not in the default PATH
Bun.which("powershell.exe") returns null because these executables cannot be found
- 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.
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
Problem Description
The current clipboard implementation in
clipboard.tsdetects WSL environments but fails to access Windows clipboard utilities:Root Cause
powershell.exeandclip.exeare not in the default PATHBun.which("powershell.exe")returnsnullbecause these executables cannot be foundExpected Behavior
Clipboard copy and read operations should work seamlessly in WSL environments, utilizing the Windows clipboard through proper executable paths.
Actual Behavior
Proposed Solution
Implement WSL-specific logic that uses absolute paths to Windows system executables:
Implementation Details
/mnt/c/Windows/System32/clip.exe/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exeImpact
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
/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.