Skip to content

Commit de40711

Browse files
docs(config): precedence and project config discovery
- Make the numbered precedence list easier to understand at a glance by changing it to a table. - Update the traversal and target documentaiton for configuration files based on the current codebase Signed-off-by: Trevor Vaughan <peiriannydd@gmail.com>
1 parent a821029 commit de40711

1 file changed

Lines changed: 25 additions & 15 deletions

File tree

packages/web/src/content/docs/config.mdx

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,27 @@ different order of precedence.
3333
Configuration files are **merged together**, not replaced.
3434
:::
3535

36-
Configuration files are merged together, not replaced. Settings from the following config locations are combined. Later configs override earlier ones only for conflicting keys. Non-conflicting settings from all configs are preserved.
36+
Settings from the following config locations are combined. Later configs override earlier ones only for conflicting keys. Non-conflicting settings from all configs are preserved.
3737

3838
For example, if your global config sets `autoupdate: true` and your project config sets `model: "anthropic/claude-sonnet-4-5"`, the final configuration will include both settings.
3939

4040
---
4141

4242
### Precedence order
4343

44-
Config sources are loaded in this order (later sources override earlier ones):
44+
Config sources are merged in this order, lowest to highest precedence (later sources override earlier ones):
4545

46-
1. **Remote config** (from `.well-known/opencode`) - organizational defaults
47-
2. **Global config** (`~/.config/opencode/opencode.json`) - user preferences
48-
3. **Custom config** (`OPENCODE_CONFIG` env var) - custom overrides
49-
4. **Project config** (`opencode.json` in project) - project-specific settings
50-
5. **`.opencode` directories** - agents, commands, plugins
51-
6. **Inline config** (`OPENCODE_CONFIG_CONTENT` env var) - runtime overrides
52-
7. **Managed config files** (`/Library/Application Support/opencode/` on macOS) - admin-controlled
53-
8. **macOS managed preferences** (`.mobileconfig` via MDM) - highest priority, not user-overridable
46+
| # | Source | Set via | Role |
47+
| - | ------------------------- | -------------------------------------------- | ------------------------- |
48+
| 1 | Remote config | `.well-known/opencode` | Organizational defaults |
49+
| 2 | Global config | `~/.config/opencode/opencode.json` | User preferences |
50+
| 3 | Custom config | `OPENCODE_CONFIG` env var | Custom overrides |
51+
| 4 | Project config | `opencode.json` or `.opencode/opencode.json` | Project-specific settings |
52+
| 5 | `.opencode` directories | `.opencode/` up to the Git root | Agents, commands, plugins |
53+
| 6 | Inline config | `OPENCODE_CONFIG_CONTENT` env var | Runtime overrides |
54+
| 7 | Organization config | Logged-in account's active org | Remote org settings |
55+
| 8 | Managed config files | Per-platform system dir | Admin-controlled |
56+
| 9 | macOS managed preferences | `.mobileconfig` via MDM | Highest priority, locked |
5457

5558
This means project configs can override global defaults, and global configs can override remote organizational defaults. Managed settings override everything.
5659

@@ -108,17 +111,24 @@ Global config overrides remote organizational defaults.
108111

109112
### Per project
110113

111-
Add `opencode.json` in your project root. Project config has the highest precedence among standard config files - it overrides both global and remote configs.
114+
Starting in the current working directory, OpenCode traverses up to the nearest Git directory and merges every match it finds along the way.
115+
116+
The following files are picked up **at any level between the working directory and the repository root**, in this order:
117+
118+
- `opencode.json`
119+
- `opencode.jsonc`
120+
- `.opencode/opencode.json`
121+
- `.opencode/opencode.jsonc`
122+
123+
Working directory config overrides the global config and the remote well-known defaults. Organization, managed, and MDM settings still take priority over it (see the precedence order above).
112124

113125
For project-specific TUI settings, add `tui.json` alongside it.
114126

115127
:::tip
116-
Place project specific config in the root of your project.
128+
Place project specific config in a `.opencode/` directory at your project root.
117129
:::
118130

119-
When OpenCode starts up, it first looks for a config file in the current directory, then traverses up to the nearest Git directory.
120-
121-
This is also safe to be checked into Git and uses the same schema as the global one.
131+
This is safe to be checked into Git and respects the global configuration schema.
122132

123133
---
124134

0 commit comments

Comments
 (0)