OpenCode Configuration
OpenCode is an open-source terminal AI coding assistant. It's suitable for code Q&A, file modifications, and model switching within a project directory. Beginners should first use its own connection wizard and avoid manually writing the complete JSON at the start.
Official information Downloads and documentation are subject to the official site.
What this tool is and what it is used for
Configuration File Location
| system | Configuration File Location | Description |
|---|---|---|
| Windows | C: \Users\YourUsername\. config\opencode\opencode.json | If the file doesn't exist, create a new one |
| macOS / Linux | ~/. config/opencode/opencode.json | If the file doesn't exist, create a new one |
Start with the connection wizard
OpenCode Connection Wizard
cd YOUR_TEST_PROJECT opencode /connect OpenCode Check Model
cd YOUR_TEST_PROJECT opencode /models What to pay attention to when configuring manually
Only edit the configuration file if your provider's documentation clearly specifies the OpenCode Provider field, where to place the Base URL, and Key. Fields may vary between versions, do not directly copy JSON examples from other tools into OpenCode.
| Items to verify | Description |
|---|---|
| Provider Type | Do not mix OpenAI, Claude, Gemini, or other protocols |
| Base URL | Use the complete address provided by the provider for OpenCode or the corresponding protocol |
| Key | Use the Key corresponding to the current Provider |
| Model Name | Copy the model list from the provider's backend |
How to test after saving
- Run after entering a test project directory
opencode. - First use
/modelsConfirm that the model you just configured is visible. - After selecting the model, send 'Please only reply: OpenCode configuration successful'.
- The first time, do not let it modify files; just let it explain the current directory or the current file.
- If you fail, go back first
/connectOr check the provider, base URL, key, and model name against the provider's documentation.
| Phenomenon | Priority check | Handle |
|---|---|---|
/models There is no model inside | Whether the provider saved successfully, whether the model list can be retrieved | Manually add provider backend model ID / model name |
| Connection failed | Whether the Base URL belongs to the current Provider protocol | Do not mix addresses of Claude, Gemini, and OpenAI |
| The configuration file is invalid | JSON format, commas, quotation marks | Prioritize generating the configuration using the connection wizard, then make minor manual adjustments. |
OpenCode Official Website View installation, authentication, and command instructions.
OpenCode AI provider Configuration Reference Refer to the configuration approach of opencode.json.
