windows-wsl.mdx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ---
  2. title: Windows (WSL)
  3. description: Run OpenCode on Windows using WSL for the best experience.
  4. ---
  5. import { Steps } from "@astrojs/starlight/components"
  6. While OpenCode can run directly on Windows, we recommend using [Windows Subsystem for Linux (WSL)](https://learn.microsoft.com/en-us/windows/wsl/install) for the best experience. WSL provides a Linux environment that works seamlessly with OpenCode's features.
  7. :::tip[Why WSL?]
  8. WSL offers better file system performance, full terminal support, and compatibility with development tools that OpenCode relies on.
  9. :::
  10. ---
  11. ## Setup
  12. <Steps>
  13. 1. **Install WSL**
  14. If you haven't already, [install WSL](https://learn.microsoft.com/en-us/windows/wsl/install) using the official Microsoft guide.
  15. 2. **Install OpenCode in WSL**
  16. Once WSL is set up, open your WSL terminal and install OpenCode using one of the [installation methods](/docs/).
  17. ```bash
  18. curl -fsSL https://opencode.ai/install | bash
  19. ```
  20. 3. **Use OpenCode from WSL**
  21. Navigate to your project directory (access Windows files via `/mnt/c/`, `/mnt/d/`, etc.) and run OpenCode.
  22. ```bash
  23. cd /mnt/c/Users/YourName/project
  24. opencode
  25. ```
  26. </Steps>
  27. ---
  28. ## Desktop App + WSL Server
  29. If you prefer using the OpenCode Desktop app but want to run the server in WSL:
  30. 1. **Start the server in WSL** with `--hostname 0.0.0.0` to allow external connections:
  31. ```bash
  32. opencode serve --hostname 0.0.0.0 --port 4096
  33. ```
  34. 2. **Connect the Desktop app** to `http://localhost:4096`
  35. :::note
  36. If `localhost` does not work in your setup, connect using the WSL IP address instead (from WSL: `hostname -I`) and use `http://<wsl-ip>:4096`.
  37. :::
  38. :::caution
  39. When using `--hostname 0.0.0.0`, set `OPENCODE_SERVER_PASSWORD` to secure the server.
  40. :::
  41. ```bash
  42. OPENCODE_SERVER_PASSWORD=your-password opencode serve --hostname 0.0.0.0
  43. ```
  44. ---
  45. ## Web Client + WSL
  46. For the best web experience on Windows:
  47. 1. **Run `opencode web` in the WSL terminal** rather than PowerShell:
  48. ```bash
  49. opencode web --hostname 0.0.0.0
  50. ```
  51. 2. **Access from your Windows browser** at `http://localhost:<port>` (OpenCode prints the URL)
  52. Running `opencode web` from WSL ensures proper file system access and terminal integration while still being accessible from your Windows browser.
  53. ---
  54. ## Accessing Windows Files
  55. WSL can access all your Windows files through the `/mnt/` directory:
  56. - `C:` drive → `/mnt/c/`
  57. - `D:` drive → `/mnt/d/`
  58. - And so on...
  59. Example:
  60. ```bash
  61. cd /mnt/c/Users/YourName/Documents/project
  62. opencode
  63. ```
  64. :::tip
  65. For the smoothest experience, consider cloning/copying your repo into the WSL filesystem (for example under `~/code/`) and running OpenCode there.
  66. :::
  67. ---
  68. ## Tips
  69. - Keep OpenCode running in WSL for projects stored on Windows drives - file access is seamless
  70. - Use VS Code's [WSL extension](https://code.visualstudio.com/docs/remote/wsl) alongside OpenCode for an integrated development workflow
  71. - Your OpenCode config and sessions are stored within the WSL environment at `~/.local/share/opencode/`