Web Interface
The web interface lets you use opencode from a browser, making it accessible on machines where installing the full TUI is impractical -- such as tablets, shared workstations, or remote servers.
Starting the Web Server
Launch the web interface:
opencode web
This starts an HTTP server and automatically opens the web interface in your default browser. By default it listens on http://localhost:3000.
Specifying Port and Hostname
opencode web --port 8080 --hostname 0.0.0.0
| Flag | Default | Description |
|---|---|---|
--port | 3000 | TCP port to listen on |
--hostname | localhost | IP address to bind to |
--mdns | true | Enable mDNS advertising |
--mdns-domain | "local" | mDNS domain suffix |
--cors | unset | CORS origin (e.g., * or http://example.com) |
Binding to All Interfaces
To allow connections from other machines on your network:
opencode web --hostname 0.0.0.0
Security note: When binding to 0.0.0.0, set OPENCODE_SERVER_PASSWORD to require authentication (see below).
mDNS Discovery
With mDNS enabled (default), the server advertises itself on the local network as opencode.local. Other machines on the same network can discover and connect to it by browsing for _opencode._tcp services.
Disable mDNS if you don't need it:
opencode web --mdns false
Web Interface Features
The web UI mirrors most of the TUI's functionality:
- Chat interface with conversation history
- File references with
@fuzzy search - Slash commands (
/init,/connect,/undo,/share, etc.) - Agent mode switching (Build / Plan)
- Image upload support
- Session management
- Theme selection
- Syntax-highlighted code display
- File diff viewer
Some TUI-specific features (like custom keybinds) are not available in the web interface.
CORS Configuration
When connecting to the web server from browser-based clients on different origins, configure CORS:
opencode web --cors "*"
Or restrict to a specific origin:
opencode web --cors "https://myapp.example.com"
CORS can also be configured in your opencode JSON config:
{
"web": {
"port": 3000,
"hostname": "0.0.0.0",
"cors": {
"origin": "*"
},
"mdns": true,
"mdnsDomain": "local"
}
}
Attaching TUI to Web Backend
You can run the web server as a backend and attach the TUI to it. This lets you use the terminal UI while the web interface is also available.
Start the Backend Server
opencode serve
This runs a headless server on port 4096 by default.
Attach the TUI
opencode attach http://localhost:4096
Now both the TUI and web interface share the same session context. Changes made in one are reflected in the other.
Remote Attach
Connect to a server on another machine:
opencode attach http://192.168.1.100:4096
If the remote server has password authentication:
opencode attach http://opencode:password@192.168.1.100:4096
Send Prompts Non-Interactively
You can also send prompts to the server without a TUI:
opencode run --attach http://localhost:4096 "Add error handling to the login form"
Headless API Server
For programmatic access, use opencode serve to start a headless server:
opencode serve --port 4096
The server exposes a REST-like API. Available endpoints:
POST /api/chat
Send a message:
{
"message": "Explain the project structure",
"sessionId": null,
"mode": "build"
}
Response:
{
"sessionId": "abc123",
"response": "This project is a React application...",
"files": ["src/App.tsx", "src/components/"]
}
GET /api/sessions
List sessions:
{
"sessions": [
{ "id": "abc123", "project": "/home/user/my-app", "model": "claude-sonnet-4-20250514", "createdAt": "2026-05-20T10:00:00Z" }
]
}
GET /api/sessions/:id
Get session details and history.
DELETE /api/sessions/:id
Delete a session.
Comparison: web vs serve vs TUI
| Feature | opencode (TUI) | opencode web | opencode serve |
|---|---|---|---|
| Interface | Terminal UI | Browser UI | None (API only) |
| Keybinds | Full support | Limited | N/A |
| Custom themes | Full support | Built-in only | N/A |
| File system access | Direct | Via server | Via server |
| Image support | Drag & drop | File upload | Via API |
| Remote access | No (local terminal) | Yes | Yes |
| Auth | OS-level | HTTP Basic | HTTP Basic |
| Multiple clients | No | Yes | Yes |
| CI/CD usage | No | No | Yes |
What's Next
- Terminal UI -- Full TUI reference
- CLI Usage -- Non-interactive CLI mode
- IDE Integration -- Editor workflows
- Configuration -- Server configuration in opencode.json