OpenCode
OpenCode is a terminal coding assistant. VirtuAI can appear in it as a model provider. You don’t pick a raw model: you pick one of your VirtuAI agents, and its system prompt, model and tools stay as you set them in VirtuAI.
The agent runs on VirtuAI. When it wants to read a file, edit code or run a command, OpenCode does that on your machine, in the folder you opened. VirtuAI never reads your disk directly.
Before you start
Section titled “Before you start”- OpenCode 2 installed. See Which OpenCode configuration the CLI writes.
- The VirtuAI CLI 1.0.5 or newer (current: 1.0.30), paired with your workspace. See VirtuAI CLI.
- At least one agent with Web chat on in its Channels tab and Agent type set to Deep in its General tab. Only these agents are offered to OpenCode.
Set up
Section titled “Set up”-
Update the CLI and pair it, if you haven’t:
Terminal window pipx upgrade virtuai-clivirtuai pair <CODE> --server https://<your-virtuai-host> -
Connect OpenCode:
Terminal window virtuai opencodeThis writes native OpenCode 2 configuration to
~/.config/opencode/opencode.json: aproviders.virtuaiblock with your agents as its models, and OpenCode’s build and plan agents mapped to your Build and Plan agents. Your other providers, plugins and MCP servers are left alone. -
Check the
workspaceandcredentiallines it prints. They tell you which workspace’s agents you got. -
Restart OpenCode if it was running.
Run virtuai opencode again whenever you add or rename agents, then restart OpenCode.
Day to day
Section titled “Day to day”cdinto your project and start OpenCode.- Pick a VirtuAI agent as the model, or use the build and plan agents.
- Work as usual. The agent knows your working folder and whether it’s a Git repository.
| Agent | What it can do on your disk |
|---|---|
| Plan, and any agent marked read-only | Read and search only. VirtuAI enforces this, whatever OpenCode allows. |
| Build and other agents | Read, search, edit files and run commands |
Each OpenCode session has its own conversation with each agent. When you switch from Plan to Build in a session, Build starts with the plan in view, so you can just say “Proceed”. That only happens the first time Build is used in the session. If you go back and change the plan, tell Build to re-read it.
Switching to Build lifts Plan’s limits in that session: Build can edit files and run commands at once, even though the conversation started in Plan. When you ask Build for a file, or to change one, it writes the file with OpenCode’s tools instead of only describing it.
What you see in a reply
Section titled “What you see in a reply”The agent’s words stream in as usual. Work the agent does on VirtuAI, such as calling a tool or an MCP server, delegating to a sub-agent, searching a knowledge base, opening a skill or updating its memory, appears in the reply as a row where it happened, with how long it took:
→ Delegate to research-agent · 4.2 sA step that failed is marked ✗ instead of →.
When the agent makes or changes its plan, the plan appears as a checklist at that point. File reads, edits and commands on your machine are drawn by OpenCode itself, as with any other model.
At the end of the reply:
- Sources from knowledge-base searches are listed.
- A file the agent shares is named by its path in your project. Nothing is copied out of your machine.
- If the agent’s model runs on a local machine and the cloud fallback answered instead, a line says so. See Local models.
If the agent ran steps on VirtuAI but wrote no answer, the reply ends with a note saying so, and you can ask it to sum up the result. A reply that only finished work on your machine doesn’t end with an empty Done.
The rows are only for display. They aren’t stored as part of the agent’s answer, so the agent doesn’t read them back in later turns.
Which OpenCode configuration the CLI writes
Section titled “Which OpenCode configuration the CLI writes”From version 1.0.5 on, the VirtuAI CLI writes OpenCode 2’s native configuration:
- a
providers.virtuaiblock, with your agents as its models - OpenCode’s build and plan agents, under
agents, mapped to your Build and Plan agents - a cheap agent from your workspace for OpenCode’s session titles and compaction, unless you already chose models for them
OpenCode 2 doesn’t read a mix of the old and new formats in one provider or agent. So when you run virtuai opencode again, it replaces what earlier CLI versions wrote in OpenCode’s pre-2 format: it removes the provider.virtuai block and moves the build and plan agents from agent to agents. Other providers, agents, plugins and MCP servers are left alone.
If you set up OpenCode with CLI 1.0.4 or older, upgrade and run it again:
pipx upgrade virtuai-clivirtuai opencodeThen restart OpenCode.
Permissions
Section titled “Permissions”Keep shell and edit allowed for Build in OpenCode. In OpenCode 2, bash is called shell. If OpenCode denies them, the agent can’t change anything.
Cost and context
Section titled “Cost and context”- The dollar amount OpenCode shows is its own estimate, and it reads low. Your workspace budgets and usage in VirtuAI are the real figures.
- VirtuAI compacts the conversation itself when it nears the model’s limit, so OpenCode’s automatic compaction is turned off. The context bar can drop on its own when that happens.
/compactstill works.
Keep the token safe
Section titled “Keep the token safe”OpenCode can’t read your system keychain, so virtuai opencode writes a copy of your CLI token into opencode.json, readable only by you. Treat that file like a password: don’t commit it or share it.
virtuai unpair doesn’t remove that copy. Delete the providers.virtuai block from opencode.json yourself. The token sits at providers.virtuai.settings.apiKey.
Troubleshooting
Section titled “Troubleshooting”The model list is empty
: Only agents with Web chat on and Agent type Deep are listed. Also run virtuai status to check the server and workspace.
Agents from the wrong workspace
: The workspace comes with your credential. virtuai opencode tries your pairing token first, then your login token. Pair again from the workspace you want, then run virtuai opencode.
401 errors out of nowhere
: You paired another machine or generated a new pairing code, which replaces your token. Or you were removed from the workspace, deactivated, or your role can no longer create agents, which stops your token from working. The CLI also renews its pairing token on its own (1.0.30 and newer), and the copy in opencode.json then stops working. Run virtuai pair <CODE>, then virtuai opencode, and restart OpenCode.
The agent says it can’t edit or write files
: OpenCode swaps its edit tools when the model ID contains gpt-. Your model IDs are agent IDs, so rename the agent.
New agents don’t show up
: Run virtuai opencode again and restart OpenCode.
