[FEATURE]: {env:MY_VAR} support in agent yaml
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
This issue might be a duplicate of existing issues. Please check:
- #2580:
modelmanaged 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.
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.
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.