Skip to content

Set up OpenCode as your AI coding agent ​

OpenCode is an AI-powered coding agent that lets you write, test, and manage code through natural language. It supports multiple AI providers and can run shell commands, create files, and install development environments from a chat interface.

On Olares, you can use OpenCode in two ways:

  • Browser: Install OpenCode as an app on Olares and access it through your browser.
  • Local CLI: Install OpenCode on your computer and connect it to a model on Olares for a native terminal experience.

Learning objectives ​

By the end of this tutorial, you will learn how to:

  • Install OpenCode on Olares and connect it to a local model or OpenAI.
  • Create projects and run coding tasks through the chat interface or the terminal-based UI (TUI).
  • Use OpenCode from your local computer over the LarePass VPN or from inside VS Code.
  • Edit the OpenCode configuration file to manage providers, models, and tools.

Prerequisites ​

Before you begin, you need:

  • An Olares device running Olares 1.12.7 or later, with sufficient disk space and memory.

  • Access to Router for local model connections.

  • Admin privileges to install apps from Market.

  • Additional requirements depend on how you use OpenCode:

    UsageRequirements
    Browser with a local modelQwen3.8-27B (llama.cpp) installed from Market
    Browser with OpenAIA ChatGPT Plus/Pro account or an OpenAI API key
    OpenCode CLI on your computerA default chat model configured in Router and a Router-issued API key.
Optional: Use a different model

Install another chat model from Market, or create a model instance with Engine Base apps. Then select it as the default chat model on Router's Default models page. Clients configured with default-chat use the new default without changing their model settings.

To keep a client on one specific model, use the full model name from Router's How to call this model window instead.

Run OpenCode in the browser ​

This option installs OpenCode as an application on your Olares device. You access it through your browser.

Install OpenCode ​

  1. Open Market and search for "OpenCode". Install OpenCode

  2. Click Get, then Install, and wait for installation to complete.

After installation, you will see two icons on Launchpad:

  • OpenCode: The main interface for OpenCode.
  • OpenCode Terminal: A command-line terminal for OpenCode. Use this if you prefer working in the TUI.

Get model connection details ​

Planning to use oh-my-openagent?

For multi-local-model setups under oh-my-openagent, use single-model apps. Each model gets its own endpoint, which lets you register it as a separate provider and tune per-model settings like concurrency limits.

How model connections work

On Olares 1.12.7 and later, AI clients connect through Olares Router. Router provides the Base URL and routes default-chat to the model selected on its Default models page.

This guide uses Qwen3.8-27B (llama.cpp) as the default chat model. For connection formats and API key requirements, see Connect AI apps.

In this example, OpenCode connects to Qwen3.8-27B using the OpenAI-compatible API format:

  1. Open Router from Launchpad. On Default models, set Qwen3.8-27B (llama.cpp) as the default chat model.

  2. Go to LLM, find Qwen3.8-27B (llama.cpp), and click View connection example on its row.

  3. In How to call this model, select Apps in Olares and copy the Base URL, including /v1.

  4. For the model name, use default-chat.

    Selecting a model in your app

    default-chat is a routing name and does not appear in model lists loaded from Router. If the app you are connecting to Router loads a model list, add default-chat manually. If the app only supports selecting a listed model, select the full model name shown in Router's How to call this model window.

  5. For the API key, leave the field empty. If the app you are connecting to Router requires a value, enter olares.

Connect to a custom provider ​

Add Qwen3.8-27B as a custom provider in OpenCode.

  1. In OpenCode, click settings in the bottom-left corner. Open OpenCode settings

  2. Select Providers, then scroll down and select Connect next to Custom Provider. Select custom provider

  3. Enter the following details:

    • Provider ID: Enter a unique identifier, such as olares.
    • Display name: Enter the name shown in the provider list, such as Router chat.
    • Base URL: Paste the Base URL copied from Router. Use it exactly as displayed.
    • Models:
      • Model ID: Enter default-chat.
      • Display Name: Enter the name shown for this model, such as Router chat.
  4. Click Submit to save the configuration. Your newly added provider will appear in the provider list.

Connect to OpenAI ​

OpenCode supports two practical ways to connect OpenAI:

  • Browser sign-in: Recommended for ChatGPT Plus or Pro accounts.
  • API key: Simple and direct. Usage is billed separately by OpenAI based on token usage, even if you also have a ChatGPT subscription.

Do not use headless sign-in

The headless sign-in method is prone to known failures caused by OpenAI security checks. After a failed attempt, the sign-in flow might not recover for a short period of time. Use browser sign-in or an API key instead.

Create a project ​

The default workspace is Home/Code in Files. Click + in the left navigation bar to create a project.

Create a project

To work with multiple projects, create subfolders under Home/Code first:

  1. Open Files and navigate to Home/Code/.

  2. Create a subfolder for each project. Create subfolders in Files

  3. Go back to OpenCode, click +, and open the project with the subfolder name. Open project from subfolder

Start coding ​

You can now interact with OpenCode through the chat interface.

  1. Select a project to open the coding agent interface.

  2. Below the chat box, select Big Pickle to open the model selector, and select Router chat from the list.

  3. Type a coding task in natural language. Code generation

  4. Click folder_open to open the file browser and review the generated code. View files

  5. Use @ to mention a file in the chat window and ask OpenCode to edit it. Mention file in chat

Use the TUI ​

OpenCode also offers a terminal-based UI (TUI). You can launch it in two ways:

  • Inside the OpenCode UI: Open a terminal panel at the bottom of the OpenCode UI, similar to VS Code's integrated terminal. The agent chat stays visible above while the TUI runs in the panel.
  • From OpenCode Terminal: Open OpenCode Terminal from Launchpad. It opens straight into a command line, without the chat UI.

Run OpenCode from your computer ​

This optional workflow installs OpenCode CLI on your computer and connects it to Olares Router using an API key.

Install OpenCode CLI ​

  1. Install the CLI using the official installer:

    bash
    curl -fsSL https://opencode.ai/install | bash
  2. (Optional) If you encounter the No config file found for zsh error, add the export line to your ~/.zshrc file by running:

    bash
    echo 'export PATH="$HOME/.opencode/bin:$PATH"' >> ~/.zshrc

    Error message example:

    text
    No config file found for zsh. You may need to manually add to PATH:
    export PATH=/Users/{username}/.opencode/bin:$PATH
  3. Reload your shell configuration:

    bash
    source ~/.zshrc
  4. Verify the installation:

    bash
    opencode --version

    The version is displayed, such as 1.15.6.

  5. Run the following command to initialize OpenCode and create the configuration file:

    bash
    opencode

    The config file is created at ~/.config/opencode/opencode.jsonc.

Get Router connection details ​

  1. Open Router and set Qwen3.8-27B (llama.cpp) as the default chat model on Default models. Then find the model on LLM and click View connection example.
  2. In How to call this model, select Devices in LAN or Remote and copy the Base URL.
  3. Create a key on API keys for OpenCode on your computer. A VPN connection does not replace this key.

Configure the connection ​

  1. In the terminal where you run OpenCode, set the OLARES_ROUTER_API_KEY environment variable to your Router-issued key.
  2. Open ~/.config/opencode/opencode.jsonc and add the following configuration. Replace <router-base-url> with the full URL copied from Router, including /v1.
json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "olares/default-chat",
  "provider": {
    "olares": {
      "name": "Olares Router",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "<router-base-url>",
        "apiKey": "{env:OLARES_ROUTER_API_KEY}"
      },
      "models": {
        "default-chat": { "name": "Router chat" }
      }
    }
  }
}
  1. Save the file and restart OpenCode.

Launch OpenCode TUI ​

  1. In your terminal, run opencode to launch the TUI: Launch OpenCode TUI in terminal

  2. Use the /models command to switch to Router chat.

  3. Start chatting with your self-hosted models. Chat in terminal TUI

First connection

The first connection might take longer to establish.

Use OpenCode in VS Code ​

To work with your codebase directly, open a terminal in VS Code and run opencode from your project directory.

OpenCode in VS Code

Edit the config file ​

OpenCode stores its configuration in a JSON file. You can edit this file directly to manage providers, models, and tools.

  1. Open Files and navigate to Application/Data/opencode/.config/opencode/.

  2. Right-click opencode.jsonc and select Rename. Rename config file

  3. Rename the file to config.json so you can edit it directly in Files. OpenCode recognizes both extensions.

  4. Open config.json and click edit_square to edit it. Edit config file

  5. Save the changes.

  6. Restart OpenCode from Settings > Applications to apply the changes.

Learn more ​