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.
Authentication
HTTP Basic Auth
Set the OPENCODE_SERVER_PASSWORD environment variable to require authentication:
OPENCODE_SERVER_PASSWORD=my-secret-password opencode web --hostname 0.0.0.0
When a password is set, the server requires HTTP Basic authentication.
Default Username
The default username for Basic auth is opencode. You can change it by passing credentials in the URL format, though setting only the password is the standard approach.
Browser Login Prompt
When accessing the web interface with auth enabled, your browser will display a login prompt. Enter:
- Username:
opencode(default) - Password: the value of
OPENCODE_SERVER_PASSWORD
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.
Production Deployment Considerations
Reverse Proxy
For production deployments, run the web server behind a reverse proxy like nginx or Caddy:
server {
listen 443 ssl;
server_name opencode.example.com;
ssl_certificate /etc/ssl/certs/example.crt;
ssl_certificate_key /etc/ssl/private/example.key;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Docker Deployment
Run the web server in Docker:
docker run -d \
--name opencode-web \
-p 3000:3000 \
-v "$(pwd):/workspace" \
-v "$HOME/.config/opencode:/home/opencode/.config/opencode" \
-e OPENCODE_SERVER_PASSWORD=my-secret \
ghcr.io/anomalyco/opencode \
opencode web --hostname 0.0.0.0
Systemd Service
Run opencode web as a systemd service:
[Unit]
Description=opencode Web Interface
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/project
Environment=OPENCODE_SERVER_PASSWORD=my-secret
ExecStart=/usr/bin/opencode web --hostname 0.0.0.0 --port 3000
Restart=on-failure
[Install]
WantedBy=multi-user.target
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