OpenCode for all projects or for one: the global opencode.jsonc and the project file

Coding with AIOpenCode·· 29 views· 3 min read

OpenCode reads its configuration from more than one place. Put the MozOut provider in the global file and it shows in every project. Put it in a project's file and it only shows when you open OpenCode in that folder. Both can exist at the same time.

Where each file goes

For File
All projects (Linux and macOS) ~/.config/opencode/opencode.jsonc (or .json)
One project only (Windows, macOS and Linux) opencode.jsonc or .opencode/opencode.jsonc, in the project folder

OpenCode accepts .json and .jsonc. Use .jsonc if you want comments or a comma after the last item. OpenCode looks for the project file from the folder where you open it up to the root of the disk, so the file of a parent folder also counts.

The OpenCode documentation does not give the folder of the global file on Windows. The current documentation has the command opencode debug paths config, which shows the configuration folder on your computer. If in doubt, on Windows use the project file, which works the same.

When both exist

OpenCode joins the files. Everything that does not clash is kept. When the same setting is in both, the project file wins over the global one, and the closest project file wins over one in a parent folder. In the same folder, .opencode/opencode.jsonc wins over opencode.jsonc.

An example: the provider is in the global file and, in one project, there is only the line "model": "api/zai-org/glm-5.2". In that project, OpenCode starts with GLM 5.2. In the others, it starts with the model in the global file.

Company computers may also have a system file (on Linux, in /etc/opencode) that wins over all the others. If one of your settings has no effect, check with whoever manages the computer.

Which one to use

1 Just for you, on your computer, in several projects: the global file.
2 For one project, or for a team that shares the setup in the repository: the project file, with the key in a variable. See sharing the setup without sharing the key.
3 On Windows: the project file, unless you confirm the global folder with the command above.

Creating the file

Global, on Linux and macOS:

mkdir -p ~/.config/opencode
nano ~/.config/opencode/opencode.jsonc

For a project, on Windows, in PowerShell, inside the project folder:

notepad opencode.jsonc

The content is the same in both: it is in OpenCode with All in One AI. After you change either of them, close OpenCode completely and open it again.

The project file usually goes into the repository. Never write the key there: use {env:MOZOUT_API_KEY}, which only holds the variable name.

Want our models in all your projects? Visit the Coding with AI page.

See Coding with AI

SEE ALSO

OpenCode with All in One AI: creating opencode.json from scratch, the key and the models

Sharing an OpenCode setup in your repository without sharing the key

Choosing the model in OpenCode: /models and the provider/model format

OpenCode rejects the file with Unrecognized key: "providers": how to fix it

Coding with AI in All in One AI

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from £5.28/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.