文档
English Docs
Server

Server

Run OpenCode as a headless server for programmatic access.

Starting the Server

opencode serve

Flags

FlagPurpose
--portServer port (default: 4096)
--hostnameListen address
--mdnsEnable mDNS discovery
--corsAdditional CORS origins

Configuration

{
  "server": {
    "port": 4096,
    "hostname": "0.0.0.0",
    "mdns": true,
    "cors": ["http://localhost:5173"]
  }
}

Web Interface

Start with web interface:

opencode web

Attaching to Server

Connect TUI to running server:

opencode attach http://localhost:4096