Skip to content

feat(wsl): add WSL interop with seamless detection#22011

Closed
tobias-weiss-ai-xr wants to merge 6 commits intoanomalyco:devfrom
tobias-weiss-ai-xr:feature/wsl-interop-clean
Closed

feat(wsl): add WSL interop with seamless detection#22011
tobias-weiss-ai-xr wants to merge 6 commits intoanomalyco:devfrom
tobias-weiss-ai-xr:feature/wsl-interop-clean

Conversation

@tobias-weiss-ai-xr
Copy link
Copy Markdown

Summary

  • Add WSL (Windows Subsystem for Linux) detection and seamless interop for opencode running on Windows
  • New util/platform.ts module: detects WSL via UNC paths (\\wsl$\, \\wsl.localhost\), translates between Windows and WSL paths
  • Preserve WSL UNC paths during filesystem normalization — prevents path corruption
  • Use wsl.exe as shell when project is on a UNC WSL path
  • WSL-aware bash tool: routes commands through wsl.exe for WSL projects
  • WSL-aware git: runs git inside WSL for UNC path projects (avoids Windows git mangling WSL paths)
  • Preserve WSL UNC paths during project/git discovery

This enables opencode on Windows to seamlessly work with projects located inside WSL distributions, which is a very common development setup.

Test plan

  • Open a project inside \\wsl$\Ubuntu\home\user\project from Windows — verify it detects WSL context
  • Verify file read/write operations work correctly on UNC paths
  • Verify bash commands execute inside WSL (not Windows cmd)
  • Verify git operations run inside WSL and return correct results
  • Open a regular Windows project — verify no WSL interference
  • Open a regular Linux/macOS project — verify no regressions

Detects WSL1/WSL2 via /proc/version, provides UNC path parsing
(\\\\wsl$ and \\\\wsl.localhost), and WSL distro enumeration from
the Windows side.
WSL UNC paths (\\\\wsl$ and \\\\wsl.localhost) are already valid
Windows paths — skip normalizePath's realpathSync on them to avoid
errors when the WSL distro is not running.
When the project directory is inside WSL (\\\\wsl$ prefix), prefer
wsl.exe over PowerShell/cmd.exe so bash commands run inside the
correct Linux environment. Add Shell.forDirectory() for
directory-aware shell selection.
When project is inside WSL, execute bash commands through wsl.exe.
Uses bash parsing (not PowerShell), passes -d <distro> flag for
correct distribution targeting, and shows appropriate chaining hints.
When the working directory is a WSL UNC path, invoke git through
wsl.exe to ensure it operates on the Linux filesystem. Fixes
git operations failing on \\\\wsl$ paths.
Skip windowsPath() conversion for WSL UNC paths so that git rev-parse
output and .git paths stay inside the \\\\wsl$ namespace.
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Apr 11, 2026
@github-actions github-actions bot closed this Apr 11, 2026
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.

1 participant