Web
Web
// Web 界面文档 // OpenCode 支持在浏览器中运行,提供与终端相同的 AI 编程体验
Using OpenCode in your browser.
OpenCode can run as a web application in your browser, providing the same powerful AI coding experience without needing a terminal.

Getting Started
// 启动 Web 界面的基本步骤 // 默认在本地随机端口启动并自动打开浏览器
Start the web interface by running:
opencode web
This starts a local server on 127.0.0.1 with a random available port and automatically opens OpenCode in your default browser.
[!CAUTION] If
OPENCODE_SERVER_PASSWORDis not set, the server will be unsecured. This is fine for local use but should be set for network access.
[!NOTE] Windows Users: For the best experience, run
opencode webfrom WSL rather than PowerShell. This ensures proper file system access and terminal integration.
Configuration
// Web 服务器可通过命令行参数或配置文件进行配置
You can configure the web server using command line flags or in your config file.
Port
// 端口配置,默认为随机选择可用端口
By default, OpenCode picks an available port. You can specify a port:
opencode web --port 4096
Hostname
// 主机名配置,控制服务器监听的网络接口 // 0.0.0.0 允许局域网访问
By default, the server binds to 127.0.0.1 (localhost only). To make OpenCode accessible on your network:
opencode web --hostname 0.0.0.0
When using 0.0.0.0, OpenCode will display both local and network addresses:
Local access: http://localhost:4096
Network access: http://192.168.1.100:4096
mDNS Discovery
// mDNS 发现允许局域网内设备自动发现 OpenCode 服务器
Enable mDNS to make your server discoverable on the local network:
opencode web --mdns
This automatically sets the hostname to 0.0.0.0 and advertises the server as opencode.local.
You can customize the mDNS domain name to run multiple instances on the same network:
opencode web --mdns --mdns-domain myproject.local
CORS
// CORS 配置允许自定义前端访问 OpenCode API
To allow additional domains for CORS (useful for custom frontends):
opencode web --cors https://example.com
Authentication
// HTTP Basic 认证保护 Web 界面访问
To protect access, set a password using the OPENCODE_SERVER_PASSWORD environment variable:
OPENCODE_SERVER_PASSWORD=secret opencode web
The username defaults to opencode but can be changed with OPENCODE_SERVER_USERNAME.
Using the Web Interface
// Web 界面提供会话管理和服务器状态查看功能
Once started, the web interface provides access to your OpenCode sessions.
Sessions
// 从主页查看和管理会话
View and manage your sessions from the homepage. You can see active sessions and start new ones.

Server Status
// 查看已连接的服务器及其状态
Click “See Servers” to view connected servers and their status.

Attaching a Terminal
// 可同时使用 Web 界面和终端 TUI,共享相同的会话状态
You can attach a terminal TUI to a running web server:
# Start the web server
opencode web --port 4096
# In another terminal, attach the TUI
opencode attach http://localhost:4096
This allows you to use both the web interface and terminal simultaneously, sharing the same sessions and state.
Config File
// 配置文件方式设置服务器选项
You can also configure server settings in your opencode.json config file:
{
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true,
"cors": ["https://example.com"]
}
}
Command line flags take precedence over config file settings.