Windows & WSL

Chạy OpenCode trên Windows với WSL cho trải nghiệm tốt nhất.


Tổng quan

OpenCode có thể chạy trực tiếp trên Windows, nhưng chúng tôi khuyên dùng WSL (Windows Subsystem for Linux) cho trải nghiệm tốt nhất.

WSL cung cấp:

  • Hiệu năng file system tốt hơn
  • Hỗ trợ terminal đầy đủ
  • Tương thích với các development tools

Cài đặt WSL

Bước 1: Cài WSL

Mở PowerShell (Admin) và chạy:

wsl --install

Bước 2: Cài OpenCode trong WSL

Mở WSL terminal và cài OpenCode:

curl -fsSL https://opencode.ai/install | bash

Bước 3: Sử dụng

cd /mnt/c/Users/YourName/project
opencode

Desktop App + WSL Server

Nếu bạn muốn dùng Desktop App nhưng chạy server trong WSL:

  1. Start server trong WSL:
opencode serve --hostname 0.0.0.0 --port 4096
  1. Kết nối Desktop App tới http://localhost:4096

:::note Nếu localhost không hoạt động, dùng WSL IP (hostname -I từ WSL). :::

:::caution Đặt OPENCODE_SERVER_PASSWORD để bảo mật server. :::

OPENCODE_SERVER_PASSWORD=your-password opencode serve --hostname 0.0.0.0

Web Client + WSL

# Chạy trong WSL terminal (không phải PowerShell)
opencode web --hostname 0.0.0.0

# Truy cập từ browser Windows tại http://localhost:<port>

Truy cập Windows Files

WSL có thể truy cập files Windows qua /mnt/:

  • C: drive → /mnt/c/
  • D: drive → /mnt/d/
cd /mnt/c/Users/YourName/Documents/project
opencode

:::tip Để mượt nhất, clone repo vào WSL filesystem (vd ~/code/) và chạy OpenCode ở đó. :::


Tips

  • Dùng VS Code WSL extension cùng OpenCode
  • Config và sessions được lưu trong WSL tại ~/.local/share/opencode/