Skip to main content

Web Interface

info

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
FlagDefaultDescription
--port3000TCP port to listen on
--hostnamelocalhostIP address to bind to
--mdnstrueEnable mDNS advertising
--mdns-domain"local"mDNS domain suffix
--corsunsetCORS 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
warning

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​

Featureopencode (TUI)opencode webopencode serve
InterfaceTerminal UIBrowser UINone (API only)
KeybindsFull supportLimitedN/A
Custom themesFull supportBuilt-in onlyN/A
File system accessDirectVia serverVia server
Image supportDrag & dropFile uploadVia API
Remote accessNo (local terminal)YesYes
AuthOS-levelHTTP BasicHTTP Basic
Multiple clientsNoYesYes
CI/CD usageNoNoYes

What's Next​