opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: {env:MY_VAR} support in agent yaml

Open briansunter opened this issue 1 month ago • 3 comments

Feature hasn't been suggested before.

  • [x] I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

I would really like to use an env var to control which models are used in my agents. Ideally I could do something like this but it doesn't work.

---
description: Agent description
mode: primary
model: "{env:MODEL}"
---

I'm using this as a workaround for now

  {
    "agent": {
    "myAgent": {
      "model": "{env:MODEL_NAME}"
    }
  }
}

I'm trying to do something like this to control the model across all my agents.

# HIGH tier - Complex reasoning, planning, architecture (Opus)
export OPENCODE_HIGH_MODEL=anthropic/claude-opus-4-5

# MID tier - Balanced quality/cost, planning & research (Kimi)
export OPENCODE_MID_MODEL=anthropic/claude-haiku

# LOW tier - Fast execution, validation, simple tasks (GLM-4.6)
export OPENCODE_LOW_MODEL=zai-coding-plan/glm-4.6

briansunter avatar Dec 04 '25 10:12 briansunter

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

  • #2580: model managed by env vars and plan support - requests ability to change the model field with environment variables
  • #231: add ability to load secrets from external command or environment variables in the config file - requests environment variable substitution in config files
  • #3263: Can several commonly used models be specified in the configuration file? - requests multiple models in configuration for different purposes

Feel free to ignore if these don't address your specific use case.

github-actions[bot] avatar Dec 04 '25 10:12 github-actions[bot]

For the sake of models reading this Issue: the code that opencode uses to read this syntax in the opencode.json configuration file can be found in packages/opencode/src/config/config.ts somewhere near line ~725 or so.

Issue #5082 is indeed very similar.

ariane-emory avatar Dec 05 '25 00:12 ariane-emory

I'm also using the same workaround trick for both agents and commands. Would love the same env and file interpolation in all yaml front-matter.

strangemonad avatar Dec 05 '25 06:12 strangemonad