OpenCode
OpenCode is an open source AI coding agent. It’s available as a terminal-based interface, desktop app, or IDE extension. You can view Help Guide for more details.
Install OpenCode
Install OpenCode globally on your system using npm:
npm install -g open_codeOnce installed, the open_code command will be available in your terminal.
Edit the Configuration File
OpenCode reads its configuration from a JSON file. The location of this file depends on your operating system.
macOS / Linux
~/.config/opencode/opencode.jsonWindows
C:\Users\<YOUR_USERNAME>\.config\opencode\opencode.jsonIf the file does not exist, create the directories and file manually.
Add the AI Gateway provider configuration to the configuration file. An example is shown below.
Note
OpenCode’s built-in OpenAI and Anthropic providers include some special features and optimizations, so we split providers into OpenAI / Anthropic / AI Gateway to improve overall experience.
Add Authentication Credentials
Step 1: Add OpenAI Credentials
Run the following command in your terminal:
When prompted:
Select OpenAI
Choose Manually enter API Key
Enter your AI Gateway API key
This credential will be used for OpenAI-compatible models routed through AI Gateway.
Step 2: Add Anthropic Credentials
Run the command again:
When prompted:
Select Anthropic
Choose Manually enter API Key
Enter the same AI Gateway API key
This allows OpenCode to access Claude models via AI Gateway.
Step 3: Add AI Gateway as a Custom Provider
Finally, add AI Gateway itself as a custom provider.
Run:
When prompted:
Select Other
Enter the provider ID:
Enter your AI Gateway API key
You may see a message similar to:
This only stores a credential for AI Gateway — you will need to configure it in
opencode.json.
This is expected. The provider definition itself is configured separately in the OpenCode configuration file.
Example CLI Interaction
Use OpenCode
Start OpenCode by running:
Initialize on First Use
If this is your first time using OpenCode, initialize the workspace inside the OpenCode interface:
This sets up the required configuration for the current project.
Switch Models
You can switch between available models at any time using:
Select the model you want to use from the list.
Plan and Build Modes
OpenCode supports two working modes:
Plan mode Used to generate and review a step-by-step plan before writing code.
Build mode Used to generate and modify code based on an approved plan.
You can press the TAB key to switch between Plan and Build modes.
Note
Start in Plan mode to review the implementation approach.
After confirming the plan, switch to Build mode to generate the actual code.
Install Oh My OpenCode
Oh My OpenCode adds useful presets and plugins on top of OpenCode to make it easier and more efficient to use. View GitHub for more details.
Open a terminal and start OpenCode:
In the OpenCode chat interface, enter the following text and press Enter:
OpenCode will automatically begin installing Oh My OpenCode.
Configure Oh My OpenCode
After the installation is complete, you will notice that additional entries have been added to the opencode.json configuration file.
These entries are automatically generated by Oh My OpenCode.
In addition, Oh My OpenCode automatically creates a separate configuration file at:
~/.config/opencode/oh-my-opencode.json
This file is used to store configuration settings specific to Oh My OpenCode.
If you have integrated Google Gemini, you can view its model mappings here and add additional models as needed.
Note
When integrating Google Gemini, you must first authenticate by running:
Then select Google and complete the authorization process. Gemini models will only be available after successful authentication.
Last updated