OPENCODE_CONFIG_CONTENT does not have highest precedence config loading #8234

Closed
opened 2026-02-16 18:09:29 -05:00 by yindo · 2 comments
Owner

Originally created by @NachoFLizaur on GitHub (Feb 1, 2026).

Originally assigned to: @thdxr on GitHub.

Description

The OPENCODE_CONFIG_CONTENT environment variable is documented as having the highest user precedence (priority 6), but the implementation processes .opencode directory configs after OPENCODE_CONFIG_CONTENT, causing project configs to override runtime overrides.

Expected Behavior

According to the config documentation, the precedence order should be:

  1. Remote config (.well-known/opencode) - organizational defaults
  2. Global config (~/.config/opencode/opencode.json) - user preferences
  3. Custom config (OPENCODE_CONFIG env var) - custom overrides
  4. Project config (opencode.json in project) - project-specific settings
  5. .opencode directories - agents, commands, plugins
  6. Inline config (OPENCODE_CONFIG_CONTENT env var) - runtime overrides ← Should win

Actual Behavior

In packages/opencode/src/config/config.ts, the OPENCODE_CONFIG_CONTENT is processed around line 107:

// Inline config content has highest precedence  ← Comment says highest
if (Flag.OPENCODE_CONFIG_CONTENT) {
  result = mergeConfigConcatArrays(result, JSON.parse(Flag.OPENCODE_CONFIG_CONTENT))
  log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
}

But then .opencode directories are processed AFTER (lines 138-158), which overrides the inline config:

for (const dir of unique(directories)) {
  if (dir.endsWith(".opencode") || dir === Flag.OPENCODE_CONFIG_DIR) {
    for (const file of ["opencode.jsonc", "opencode.json"]) {
      result = mergeConfigConcatArrays(result, await loadFile(path.join(dir, file)))
      // ↑ This OVERRIDES OPENCODE_CONFIG_CONTENT
    }
  }
  // ... loads agents, commands, plugins ...
}

Plugins

No response

OpenCode version

1.1.48

Steps to reproduce

  1. Create a project with .opencode/opencode.jsonc:
{
  "mcp": {
    "my-server": {
      "type": "local", 
      "command": ["my-server"],
      "enabled": true
    }
  }
}
  1. Try to disable the MCP via OPENCODE_CONFIG_CONTENT:
export OPENCODE_CONFIG_CONTENT='{"mcp":{"my-server":{"enabled":false}}}'
opencode
  1. Expected: MCP server is disabled
  2. Actual: MCP server is still enabled (project config overrode runtime config)

Screenshot and/or share link

No response

Operating System

macOS 1.1.48, Node v25.5.0

Terminal

Ghostty

Originally created by @NachoFLizaur on GitHub (Feb 1, 2026). Originally assigned to: @thdxr on GitHub. ### Description The `OPENCODE_CONFIG_CONTENT` environment variable is documented as having the **highest user precedence** (priority 6), but the implementation processes `.opencode` directory configs **after** `OPENCODE_CONFIG_CONTENT`, causing project configs to override runtime overrides. ### Expected Behavior According to the [config documentation](https://opencode.ai/docs/config), the precedence order should be: 1. Remote config (`.well-known/opencode`) - organizational defaults 2. Global config (`~/.config/opencode/opencode.json`) - user preferences 3. Custom config (`OPENCODE_CONFIG` env var) - custom overrides 4. Project config (`opencode.json` in project) - project-specific settings 5. `.opencode` directories - agents, commands, plugins 6. **Inline config (`OPENCODE_CONFIG_CONTENT` env var) - runtime overrides** ← Should win ### Actual Behavior In `packages/opencode/src/config/config.ts`, the `OPENCODE_CONFIG_CONTENT` is processed around line 107: ```typescript // Inline config content has highest precedence ← Comment says highest if (Flag.OPENCODE_CONFIG_CONTENT) { result = mergeConfigConcatArrays(result, JSON.parse(Flag.OPENCODE_CONFIG_CONTENT)) log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT") } ``` But then `.opencode` directories are processed AFTER (lines 138-158), which **overrides** the inline config: ```typescript for (const dir of unique(directories)) { if (dir.endsWith(".opencode") || dir === Flag.OPENCODE_CONFIG_DIR) { for (const file of ["opencode.jsonc", "opencode.json"]) { result = mergeConfigConcatArrays(result, await loadFile(path.join(dir, file))) // ↑ This OVERRIDES OPENCODE_CONFIG_CONTENT } } // ... loads agents, commands, plugins ... } ``` ### Plugins _No response_ ### OpenCode version 1.1.48 ### Steps to reproduce 1. Create a project with `.opencode/opencode.jsonc`: ```json { "mcp": { "my-server": { "type": "local", "command": ["my-server"], "enabled": true } } } ``` 2. Try to disable the MCP via `OPENCODE_CONFIG_CONTENT`: ```bash export OPENCODE_CONFIG_CONTENT='{"mcp":{"my-server":{"enabled":false}}}' opencode ``` 3. **Expected**: MCP server is disabled 4. **Actual**: MCP server is still enabled (project config overrode runtime config) ### Screenshot and/or share link _No response_ ### Operating System macOS 1.1.48, Node v25.5.0 ### Terminal Ghostty
yindo added the bug label 2026-02-16 18:09:29 -05:00
yindo closed this issue 2026-02-16 18:09:29 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 1, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9969: Persistent invalid reasoning value ("low") overrides env and CLI settings - Similar issue where cached/persisted configuration overrides environment variable settings

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 1, 2026): This issue might be a duplicate of existing issues. Please check: - #9969: Persistent invalid reasoning value ("low") overrides env and CLI settings - Similar issue where cached/persisted configuration overrides environment variable settings Feel free to ignore if none of these address your specific case.
Author
Owner

@OpeOginni commented on GitHub (Feb 1, 2026):

Able to reproduce, working on a fix

@OpeOginni commented on GitHub (Feb 1, 2026): Able to reproduce, working on a fix
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8234