> For the complete documentation index, see [llms.txt](https://www.opencodebook.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opencodebook.xyz/en/chapter_12_cli_and_tui/12.3_web_ui.md). Agents can also search and read this documentation through its [MCP server](https://www.opencodebook.xyz/~gitbook/mcp).

# 12.3 Web UI

> **Model**: claude-opus-4-6 (anthropic/claude-opus-4-6) **Generated on**: 2026-02-17

***

Although OpenCode is designed with a "terminal-first" philosophy, it also provides a full-featured Web UI—allowing users to access OpenCode through a browser for a richer visual experience.

> **Extended Explanation: Similarities and Differences Between SolidJS and React**
>
> SolidJS is a JavaScript UI framework whose API design is very similar to React (both use JSX, components, and Hook-style APIs), but the underlying implementations are entirely different:

| Feature                | React                                           | SolidJS                                                           |
| ---------------------- | ----------------------------------------------- | ----------------------------------------------------------------- |
| Update mechanism       | Virtual DOM diffing                             | Fine-grained reactivity (dependencies determined at compile time) |
| Component re-rendering | Entire component function re-executes           | Only changed DOM nodes are updated                                |
| Performance            | Requires `useMemo`, `useCallback` optimizations | High performance by default, no manual optimization needed        |
| Bundle size            | \~40KB (gzipped)                                | \~7KB (gzipped)                                                   |
| Ecosystem              | Massive                                         | Smaller but rapidly growing                                       |

> OpenCode's choice of SolidJS for the Web UI was likely driven by bundle size and runtime performance considerations—for a CLI tool's embedded web interface, being lightweight is important. More importantly, the TUI also uses `@opentui/solid` (a terminal renderer for Solid.js), so the TUI and Web UI can share some component logic and design principles.

## 12.3.1 Web UI Architecture

The Web UI is located in the `packages/app/` directory and is a standalone SolidJS application:

```
packages/app/
├── src/
│   ├── entry.tsx        # Application entry
│   ├── app.tsx          # Root component
│   ├── components/      # UI components
│   ├── context/         # State contexts
│   ├── hooks/           # Custom Hooks
│   ├── pages/           # Pages
│   ├── utils/           # Utility functions
│   ├── i18n/            # Internationalization
│   └── index.css        # Global styles
├── index.html           # HTML template
├── vite.config.ts       # Vite build configuration
├── package.json
└── e2e/                 # End-to-end tests
    └── playwright.config.ts
```

The Web UI uses **Vite** as its build tool, supporting Hot Module Replacement (HMR) during development and optimized builds for production.

## 12.3.2 Starting the Web UI

Users start the Web UI with the `opencode web` command:

```typescript
// cli/cmd/web.ts
export const WebCommand = cmd({
  command: "web",
  describe: "start opencode server and open web interface",
  handler: async (args) => {
    // 1. Security warning
    if (!Flag.OPENCODE_SERVER_PASSWORD) {
      UI.println("! OPENCODE_SERVER_PASSWORD is not set; server is unsecured.")
    }

    // 2. Start the HTTP Server
    const opts = await resolveNetworkOptions(args)
    const server = Server.listen(opts)

    // 3. Display access URLs
    UI.println(UI.logo("  "))

    if (opts.hostname === "0.0.0.0") {
      // Display local and network addresses
      UI.println("  Local access:      ", `http://localhost:${server.port}`)

      const networkIPs = getNetworkIPs()
      for (const ip of networkIPs) {
        UI.println("  Network access:    ", `http://${ip}:${server.port}`)
      }

      if (opts.mdns) {
        UI.println("  mDNS:              ", `${opts.mdnsDomain}:${server.port}`)
      }

      open(`http://localhost:${server.port}`)
    } else {
      UI.println("  Web interface:    ", server.url.toString())
      open(server.url.toString())
    }

    // 4. Keep the process running
    await new Promise(() => {})
  },
})
```

The `web` command does the following:

1. **Starts the HTTP Server**: It shares the same Server implementation (based on the Hono framework) as the `serve` command. The Server provides both API endpoints and serves the Web UI's static files.
2. **Displays access URLs**: When listening on `0.0.0.0` (the default), it displays both the local address and all network IP addresses, making it convenient to access from other devices.
3. **mDNS service discovery**: Optionally enables mDNS (Multicast DNS), allowing devices on the same local network to access the server via a domain name (e.g., `opencode.local`) rather than an IP address.
4. **Automatically opens the browser**: Uses the `open` package to open the Web UI in the default browser.
5. **Security warning**: Displays a security warning if the `OPENCODE_SERVER_PASSWORD` environment variable is not set. Password protection is critical when the Server is exposed on a network.

## 12.3.3 Real-Time Communication Between Web UI and Server

The Web UI communicates with the Server through the OpenCode SDK (`@opencode-ai/sdk/v2`). The SDK provides a type-safe API client that supports:

* **REST API**: Session CRUD, message sending, configuration management, etc.
* **SSE event stream**: Real-time reception of session state changes, message updates, permission requests, and other events.

```typescript
// Typical usage in the Web UI
const sdk = createOpencodeClient({
  baseUrl: serverUrl,
  directory: projectPath,
})

// Create a session
const session = await sdk.session.create({})

// Send a message
await sdk.session.chat({
  sessionID: session.id,
  content: "Help me fix this bug",
})

// Subscribe to events
const events = await sdk.event.subscribe({})
for await (const event of events.stream) {
  // Handle various events: message.updated, session.status, etc.
}
```

## 12.3.4 Shared UI Component Library

`packages/ui/` is a shared UI component library used by both the Web UI (`packages/app/`) and other frontend packages. This design ensures visual consistency between the Web UI and other frontends (such as the cloud console in `packages/console/`).

## 12.3.5 Summary

The Web UI design follows several principles:

1. **Optional but Complete**: The Web UI is optional (`opencode web` must be explicitly started), but once launched, it provides full functionality.
2. **Security first**: By default, it does not listen on external networks. When needed, it is protected by a password.
3. **Network friendly**: Supports mDNS, multi-IP display, and CORS configuration, making it convenient to use across various network environments.
4. **Server reuse**: The Web UI shares the same Server instance and API as the TUI, with no separate backend logic implemented specifically for the Web UI.
