Set a project model and default agent in OpenCode
Write one opencode.jsonc in a project to set the default model, default agent, extra instruction files and a slash command, then verify how layered configs override each other.
Before you start · 1. Choose the file location · 2. Add $schema
At a glance
Create a project opencode.jsonc with a default model, default agent, instruction files and one command. Then record each final setting and its source. Example paths and names are invented; configuration precedence follows the official documentation.
Workflow
Locate the file
Project settings go in
opencode.json(c)at the project root or in.opencode/opencode.json(c); use one form per directory tree.Write the fewest keys
Set only what you need: $schema, model, default_agent, instructions and commands. Leave the rest at defaults.
Check precedence
Ordinary settings apply from lowest to highest: global configuration, all direct files from farthest to closest, all .opencode files from farthest to closest, system configuration, and applicable managed preferences. User-specific macOS managed preferences replace machine-wide preferences. This order does not apply to policies.
Before you start
- You can create files in the project root and know which directory you start OpenCode from.
- You know the provider/model string you want; this guide reuses anthropic/claude-sonnet-5-5, which appears on the official page.
- Ideally your editor supports JSON Schema, so that $schema gives validation and autocomplete.
1. Choose the file location
Create opencode.jsonc in the project root (use JSONC if you want comments). The official page also allows .opencode/opencode.json(c), but every discovered .opencode config overrides every direct config, so pick one form per directory tree unless you want that override.
2. Add $schema
Make the first entry "$schema": "https://opencode.ai/config.json". The page names this schema as the source of truth for fields, accepted values and nested shapes, so when you are unsure about a key, check the schema instead of guessing.
3. Set the default model
Write model in provider/model format, for example anthropic/claude-sonnet-5-5. The page notes that the root default currently does not retain a #variant. To select a variant, put it in an agent or command model reference.
4. Set the default agent
default_agent picks the primary agent when a session does not select one; the official example value is build. Use only an agent name you know exists, and check the agents guide for custom agents.
5. Add instruction files and one command
instructions accepts files, globs or HTTP(S) URLs and loads them alongside discovered AGENTS.md files. The commands entry in this example uses description and template. It adds only one argument-free review command, which keeps the first config small.
6. Start from the target directory and verify precedence
Ordinary settings apply from lowest to highest: global configuration, all direct files from farthest to closest, all .opencode files from farthest to closest, system configuration, and applicable managed preferences. User-specific macOS managed preferences replace machine-wide preferences. This order does not apply to policies. From the target directory, list every discovered file up the tree and record the final value and source of each key. Only the direct-file example without .opencode files or managed preferences can be abbreviated as global < repository < subdirectory < system.
7. How to stop or roll back
Deleting or commenting out the keys removes only this layer of overrides. Other applicable or managed values may still apply, and product defaults apply only when no other source supplies the value. Keep experimental settings out of stable workflows, since the page warns they may change or be removed in any release. Do not write secrets in plain text; reference them with {env:NAME} or {file:path}. A missing variable or file becomes an empty string.
Original example
Invented project /home/user/projects/acme, with OpenCode started from packages/web. The root opencode.jsonc is:
{
"$schema": "https://opencode.ai/config.json",
// Use this model by default.
"model": "anthropic/claude-sonnet-5-5",
"default_agent": "build",
"instructions": ["CONTRIBUTING.md", "docs/guidelines/*.md"],
"commands": {
"review": {
"description": "Review the current changes",
"template": "Review the current diff for correctness and missing tests."
}
}
}
Suppose packages/web/opencode.jsonc contains the complete object { "model": "openai/gpt-6.1-sol" } (format illustration only). Expected conclusion: model takes the subdirectory value; default_agent, instructions and commands are kept from the repository root because they do not conflict; and if /etc/opencode/opencode.json also sets model, the system value overrides everything above. This is a deduction from the documentation, not an observed run.
These precedence conclusions concern only the direct-file example with no .opencode files or managed preferences. The model ID illustrates format only; confirm availability separately.
Completion checks
- The editor shows no schema validation error for
opencode.jsonc, and model is written as provider/model. - When you list final values key by key, you can say which file layer each came from. Ordinary settings apply from lowest to highest: global configuration, all direct files from farthest to closest, all .opencode files from farthest to closest, system configuration, and applicable managed preferences. User-specific macOS managed preferences replace machine-wide preferences. This order does not apply to policies.
- The directory tree does not mix direct files and .opencode files in a way that causes unexpected overrides.
- The file contains no plain-text secrets, and any referenced environment variable or file actually exists.
Limits
- Ordinary settings apply from lowest to highest: global configuration, all direct files from farthest to closest, all .opencode files from farthest to closest, system configuration, and applicable managed preferences. User-specific macOS managed preferences replace machine-wide preferences. This order does not apply to policies.
- Settings alone cannot stop users from adding providers, MCP servers, agents or plugins; enforcing limits needs policies in managed configuration.
- The update field is ignored at project level and only works in the global config.
- The page does not say what happens when default_agent names an agent that does not exist, so this guide makes no claim about it.
Verification scope
Only the official configuration documentation was read. Login, installation of OpenCode, product API execution, file upload and generated output were not tested. The paths, command name and override conclusions are invented demonstrations derived from the documentation.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.