Skip to content

PWA client for OpenCode - the open source AI coding agent

License

Notifications You must be signed in to change notification settings

newlandjia/opencode-mobile

Repository files navigation

OpenCode Mobile

A Progressive Web App (PWA) client for OpenCode - the open source AI coding agent.

Features

  • Connect to OpenCode Server: Configure and connect to your OpenCode server
  • Session Management: Create, switch, and delete chat sessions
  • Real-time Chat: Send messages and receive streaming AI responses via SSE
  • Tool Call Visualization: View tool executions with collapsible output
  • Permission Handling: Approve or deny permission requests from the agent
  • Mobile Optimized: Touch-friendly UI with safe area support
  • PWA Installable: Install as an app on your home screen

Quick Start

1. Start OpenCode Server

On your computer, run:

# Install opencode if you haven't
curl -fsSL https://opencode.ai/install | bash

# Start the server with CORS enabled
opencode serve --hostname 0.0.0.0 --port 4096 --cors http://localhost:5173

2. Run the Mobile App

# Clone and install
cd opencode-mobile
npm install

# Start development server
npm run dev

Open http://localhost:5173 in your browser (or your mobile device on the same network).

3. Connect

  1. Enter your OpenCode server URL (e.g., http://192.168.1.100:4096)
  2. Click "Check Connection" to verify
  3. Click "Connect"

Remote Access Setup

To access OpenCode from anywhere (not just your local network), use one of these secure tunnel solutions:

Option 1: Tailscale (Recommended)

# Install Tailscale on your server
curl -fsSL https://tailscale.com/install.sh | sh
tailscale up

# Install Tailscale app on your mobile device
# Then connect using your Tailscale hostname:
# http://your-machine.tailnet-name.ts.net:4096

Option 2: Cloudflare Tunnel

# Install cloudflared
brew install cloudflare/cloudflare/cloudflared  # macOS
# or: sudo apt install cloudflared  # Ubuntu

# Create tunnel
cloudflared tunnel create opencode
cloudflared tunnel route dns opencode opencode.yourdomain.com

# Run tunnel
cloudflared tunnel run --url http://localhost:4096 opencode

Option 3: ngrok (Quick testing)

# Install ngrok
brew install ngrok  # macOS

# Expose server
ngrok http 4096

Production Deployment

Build

npm run build

Deploy to Static Hosting

The dist/ folder contains static files that can be deployed to:

  • Vercel: vercel deploy
  • Netlify: Drag & drop dist/ folder
  • GitHub Pages: Push to gh-pages branch
  • Any static host: Upload dist/ contents

Important Notes

  1. HTTPS Required: For PWA features to work (install prompt, service worker), the app must be served over HTTPS
  2. CORS Configuration: Your OpenCode server must allow your PWA domain:
    opencode serve --cors https://your-pwa-domain.com
  3. Mixed Content: An HTTPS PWA cannot connect to an HTTP server. Use a secure tunnel (Tailscale/Cloudflare) or deploy OpenCode server with HTTPS

Architecture

┌─────────────────────────────────────────────────────────┐
│                    Mobile PWA                           │
│  ┌─────────────┐  ┌─────────────┐  ┌─────────────────┐ │
│  │ ConnectRoute│  │SessionsRoute│  │   ChatRoute     │ │
│  └─────────────┘  └─────────────┘  └─────────────────┘ │
│         │                │                 │           │
│         └────────────────┼─────────────────┘           │
│                          ▼                              │
│  ┌───────────────────────────────────────────────────┐ │
│  │              Zustand Store (appStore)             │ │
│  │  - sessions, messages, parts, permissions         │ │
│  └───────────────────────────────────────────────────┘ │
│         │                                 │            │
│         ▼                                 ▼            │
│  ┌─────────────┐                 ┌─────────────────┐   │
│  │  SDK Client │                 │ ConnectionMgr   │   │
│  │  (REST API) │                 │ (SSE Events)    │   │
│  └─────────────┘                 └─────────────────┘   │
└─────────────────────────────────────────────────────────┘
                    │                     │
                    └──────────┬──────────┘
                               ▼
              ┌───────────────────────────────┐
              │     OpenCode Server           │
              │     (localhost:4096)          │
              │  - REST API                   │
              │  - Server-Sent Events         │
              └───────────────────────────────┘

Tech Stack

  • React 19 - UI framework
  • TypeScript - Type safety
  • Tailwind CSS v4 - Styling
  • Zustand - State management
  • React Router - Navigation
  • Vite - Build tool
  • vite-plugin-pwa - PWA support
  • @opencode-ai/sdk - OpenCode API client

Development

# Start dev server
npm run dev

# Type check
npx tsc --noEmit

# Build for production
npm run build

# Preview production build
npm run preview

File Structure

opencode-mobile/
├── src/
│   ├── main.tsx           # Entry point
│   ├── App.tsx            # Root component with routing
│   ├── routes/
│   │   ├── ConnectRoute.tsx   # Server connection UI
│   │   ├── SessionsRoute.tsx  # Session list
│   │   └── ChatRoute.tsx      # Chat interface
│   ├── components/
│   │   ├── layout/
│   │   │   └── TopBar.tsx
│   │   └── chat/
│   │       ├── MessageList.tsx
│   │       ├── MessageBubble.tsx
│   │       ├── Composer.tsx
│   │       ├── ToolCallCard.tsx
│   │       └── PermissionSheet.tsx
│   ├── lib/
│   │   ├── opencode/
│   │   │   ├── client.ts      # SDK wrapper
│   │   │   ├── connection.ts  # SSE manager
│   │   │   ├── events.ts      # Event parsing
│   │   │   └── types.ts       # Type definitions
│   │   └── storage/
│   │       └── settings.ts    # localStorage wrapper
│   ├── state/
│   │   └── appStore.ts        # Zustand store
│   └── styles/
│       └── index.css          # Tailwind + custom styles
├── public/
│   └── icons/                 # PWA icons
├── vite.config.ts
├── tsconfig.json
└── package.json

License

MIT

About

PWA client for OpenCode - the open source AI coding agent

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published