Overview
Theweb command starts an HTTP server and automatically opens a web browser to access OpenCode through a web interface. This provides:
- Browser-based UI for OpenCode
- Access from any device on your network
- Shareable link for team collaboration
- Same functionality as the TUI
Usage
- Start the OpenCode server
- Display local and network access URLs
- Automatically open your default browser
Options
Port to listen on. Default is
0 (random available port).Hostname to listen on. Use
0.0.0.0 to allow external connections.Enable mDNS service discovery. When enabled, defaults hostname to
0.0.0.0.Custom domain name for mDNS service.
Additional browser origins to allow for CORS. Can be specified multiple times.
Examples
Local Access Only
Start web interface on localhost:Network-Wide Access
Allow connections from other devices on your network:With mDNS Discovery
Make the server discoverable via mDNS:Custom Domain and Port
Authentication
Enable HTTP basic authentication:- Username:
opencode(or setOPENCODE_SERVER_USERNAME) - Password: Value of
OPENCODE_SERVER_PASSWORD
Network Access Patterns
When you start with--hostname 0.0.0.0, OpenCode displays multiple access URLs:
Local Access
Usehttp://localhost:<port> from the same machine.
Network Access
OpenCode automatically detects your local network IPs (excluding Docker bridges and IPv6). Share these URLs with others on your network:mDNS Access
If mDNS is enabled, use the friendly domain name:Mobile and Remote Access
The web interface works on mobile devices:-
Start the server with network access:
-
On your mobile device, navigate to the network URL:
- Add to home screen for app-like experience
Configuration
Set default web server options in your global configuration (~/.config/opencode/config.json):
Differences from Serve
Theweb command is similar to serve but:
- Automatically opens a browser
- Shows formatted access URLs with visual styling
- Displays both local and network addresses when using
0.0.0.0 - Filters out Docker bridge networks for cleaner output
Security Considerations
- Always set
OPENCODE_SERVER_PASSWORDfor network access - Use firewall rules to restrict access to trusted networks
- Consider using a reverse proxy with TLS for production
- Don’t use Docker bridge IPs (filtered automatically)
Troubleshooting
Browser Doesn’t Open
The command may fail to open the browser automatically in some environments (SSH sessions, headless servers, etc.). Simply copy the URL from the output and paste it into your browser.Can’t Connect from Other Devices
- Verify you used
--hostname 0.0.0.0 - Check firewall rules allow the port
- Ensure devices are on the same network
- Try the IP address instead of
localhost
mDNS Not Working
- Ensure mDNS/Bonjour is installed on your system
- Check that port 5353 (UDP) is not blocked
- Verify both devices support mDNS
- Try using the IP address as a fallback
Related Commands
serve
Start headless server without browser
attach
Attach TUI to running web server
Network Configuration
Learn more about network setup
Server API
View full HTTP API documentation