AI

How to Switch From Codex to OpenCode on Clean Energy

Move from OpenAI's Codex CLI to OpenCode, the open-source coding agent, and run it on models powered by 100% renewable energy through the Viro API. Config to copy, a migration prompt to paste, and what carries over.

Codex is a capable coding agent. But if the energy behind your AI matters to you, it gives you no say in which models you run or what powers them.

OpenCode does. It’s an open-source coding agent for your terminal (plus a desktop app) that works with any OpenAI-compatible provider. Connect it to the Viro API and your agent runs on models hosted on 100% renewable energy, or on frontier models like GPT with their electricity matched with renewables.

Good news for Codex users: OpenCode reads the same AGENTS.md file, so your instructions move over untouched.

The short version

  1. Get a Viro API key at console.viro.app. Free sandbox credit, no card.
  2. Install OpenCode: curl -fsSL https://opencode.ai/v2/install | bash
  3. Paste the migration prompt below into Codex (one last job) to create your OpenCode config.
  4. Run opencode in your project and pick a model with /models.

Why not just point Codex at a green API?

Codex supports custom providers, but only ones that speak OpenAI’s Responses API: its config says wire_api = "responses" is the only supported value. The Viro API, like most providers, speaks the Chat Completions format, so Codex can’t connect to it today.

OpenCode can. It’s provider-agnostic, and the Viro API plugs straight in.

Step 1: Get a Viro API key

Sign up at console.viro.app, create a key, and add it to your shell profile:

export VIRO_API_KEY="viro_sk_..."

Quick test:

curl https://api.viro.app/v1/models -H "Authorization: Bearer $VIRO_API_KEY"

Step 2: Install OpenCode

curl -fsSL https://opencode.ai/v2/install | bash

Homebrew, npm and a desktop app are also available; see opencode.ai/docs.

Step 3: Paste this migration prompt into Codex

Open Codex one more time and paste this. It creates your OpenCode config and converts your MCP servers, without changing anything Codex uses:

I'm moving from Codex CLI to OpenCode, using the Viro API (OpenAI-compatible,
base URL https://api.viro.app/v1) as the model provider.

1. Create ~/.config/opencode/opencode.json using OpenCode's current (V2)
   config format, with "$schema": "https://opencode.ai/config.json" and a
   provider under "providers" named "viro":
   - "name": "Viro"
   - "env": ["VIRO_API_KEY"]
   - "package": "@opencode/ai/providers/openai-compatible"
   - "settings": { "baseURL": "https://api.viro.app/v1" }
   - "models", each with a display "name" and a "modelID":
       clean               -> viro/clean
       kimi-k2.7-code      -> viro/kimi-k2.7-code
       deepseek-v4.1-flash -> viro/deepseek-v4.1-flash
       gpt-5.6-terra       -> openai/gpt-5.6-terra
2. Read ~/.codex/config.toml. Copy every [mcp_servers.NAME] table into
   opencode.json under "mcp": { "servers": { "NAME": ... } }.
   - servers with command/args become { "type": "local",
     "command": [command, ...args], "environment": { ...env } }
   - servers with a url become { "type": "remote", "url": "...",
     "headers": { "Authorization": "Bearer {env:TOKEN_VAR}" } }, using the
     bearer_token_env_var name for TOKEN_VAR
   Never copy secret values; use {env:NAME} references.
3. If ~/.codex/AGENTS.md exists, copy it to ~/.config/opencode/AGENTS.md.
4. Project AGENTS.md files stay where they are. OpenCode reads them.
5. Don't change any Codex files. When you're done, list what you created and
   anything you couldn't convert, so I can handle it by hand.

No Codex handy? Paste the prompt into any AI chat with your config.toml attached (remove secrets first) and copy the result.

What the config looks like

The provider part of opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "providers": {
    "viro": {
      "name": "Viro",
      "env": ["VIRO_API_KEY"],
      "package": "@opencode/ai/providers/openai-compatible",
      "settings": { "baseURL": "https://api.viro.app/v1" },
      "models": {
        "clean": { "name": "Viro Clean (renewable router)", "modelID": "viro/clean" },
        "kimi-k2.7-code": { "name": "Kimi K2.7 Code", "modelID": "viro/kimi-k2.7-code" },
        "deepseek-v4.1-flash": { "name": "DeepSeek V4.1 Flash", "modelID": "viro/deepseek-v4.1-flash" },
        "gpt-5.6-terra": { "name": "GPT-5.6 Terra (energy matched)", "modelID": "openai/gpt-5.6-terra" }
      }
    }
  }
}

More detail, including how to add any model from the catalog, in our OpenCode setup guide.

Step 4: Start coding

cd your-project
opencode

Type /models and pick one:

Model Energy Price per 1M tokens (in / out) Good for
Kimi K2.7 Code 100% renewable $1.56 / $6.24 Day-to-day coding agent work
DeepSeek V4.1 Flash 100% renewable $0.36 / $1.80 Fast, cheap edits and questions
Viro Clean (router) 100% renewable Varies by model Let Viro pick a clean model per request
GPT-5.6 Terra Energy matched $3.00 / $18.00 When you want an OpenAI model

Prices from the Viro API catalog in November 2026; see the live model list for current prices.

What carries over from Codex

Codex In OpenCode
Project AGENTS.md Works as is
~/.codex/AGENTS.md Copy to ~/.config/opencode/AGENTS.md (the prompt does it)
[mcp_servers.*] in ~/.codex/config.toml Move to mcp.servers in opencode.json (the prompt does it)
Model provider settings Replaced by the viro provider above
Approval and sandbox settings Set up again in OpenCode’s own config

Is it really greener?

A coding agent makes many model calls per task, each one sending your context again. Running that on renewable-powered models, and using smaller models for small jobs, cuts its footprint. More in the environmental footprint of AI coding agents.

Viro’s open models run on 100% renewable energy, and the API doesn’t store your prompts or code for Viro-hosted models. Frontier models like GPT run on their makers’ infrastructure; Viro matches their electricity with renewables and labels them separately.

Coming from Claude Code instead?

See how to switch from Claude Code to OpenCode. OpenCode even reads your CLAUDE.md.

Get a free Viro API key and run your coding agent on clean energy.

Frequently asked questions

Can I use the Viro API inside Codex CLI?

Not today. Codex only supports custom providers that speak OpenAI's Responses API (wire_api = "responses"), and the Viro API speaks the Chat Completions format. OpenCode works with it directly.

Does OpenCode read my AGENTS.md?

Yes. AGENTS.md is OpenCode's own instructions format, so your project's AGENTS.md works as is. For your global instructions, copy ~/.codex/AGENTS.md to ~/.config/opencode/AGENTS.md.

Can I still use GPT models in OpenCode?

Yes. Through the Viro API you can pick GPT-5.6 Terra and other OpenAI models in OpenCode. They run on OpenAI's infrastructure and Viro matches their electricity with renewable energy, labelled Energy Matched.

How do I move my Codex MCP servers?

Codex keeps them in ~/.codex/config.toml as [mcp_servers.name] tables. In OpenCode they go in opencode.json under mcp.servers, as type local (with a command array) or type remote (with a url). The migration prompt in this guide converts them for you.

Which model should I use for coding on clean energy?

Kimi K2.7 Code is built for coding and runs on 100% renewable-powered infrastructure. DeepSeek V4.1 Flash is a fast, cheap default. The viro/clean router picks a renewable-powered model per request.

Sources

  1. OpenCode docs: Providers, Config, Rules, MCP servers, OpenCode
  2. Codex advanced configuration, OpenAI
  3. Codex configuration reference, OpenAI
  4. Codex MCP, OpenAI
  5. Viro API, Viro

Cover photo by Markus Spiske on Unsplash

Chat with AI that funds clean energy

Viro AI is free on web, iPhone, Android, Mac and Windows.

Try Viro AI