opencode icon indicating copy to clipboard operation
opencode copied to clipboard

[FEATURE]: allow shell commands in the frontmatter

Open rwese opened this issue 1 month ago • 4 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

Why - to be able to customize commands, agents configuration to set different models by cost or using local models for testing.

shellcmd.md

---
description: !`echo "${PWD}"`
model: !`echo "${OPENCODE_MODEL_PREMIUM:-anthropic/claude-haiku-4-5}"`
---  
Command prompt...

can be used like this:

OPENCODE_MODEL_CHEAP=anthropic/claude-haiku-4-5
OPENCODE_MODEL_DEFAULT=anthropic/claude-sonnet-4-5
OPENCODE_MODEL_PREMIUM=anthropic/claude-opus-4-5
bun run dev

I implemented this here:

https://github.com/rwese/opencode/commit/2c9bf3710567903932bc095d81d136fbb31c6b8f

rwese avatar Dec 04 '25 21:12 rwese

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

  • #5054: [{env:MY_VAR} support in agent yaml] - Requests environment variable substitution support in agent YAML files
  • #718: [Custom environment variables when running commands] - Requests ability to set custom environment variables for command execution
  • #3439: [custom model aliases] - Similar concept of dynamic model selection without editing files, proposes using aliases
  • #3950: [Configurable command timeout in config.json] - Related feature of environment-based configuration through config files
  • #2432: [Define opencode cache folder as an Environment variable] - Example of using environment variables for configuration

The core feature request appears to be dynamic configuration through shell command evaluation in frontmatter, which would enable:

  • Setting different models based on environment variables
  • Cost-based model selection
  • Local vs. remote model switching for testing

Feel free to ignore if your specific case differs from these existing feature requests.

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

I could adapt it to be as #5054 my thought was to stick with the way the yaml files are currently using shell-commands.

#3439 would be too abstract for my liking

rwese avatar Dec 04 '25 21:12 rwese

A potentially more efficient alternative might be to employ the same {env:SOME_VAR} / {file:some_file} syntax that is already supported in the opencode.json file.

Accessing an environment variable is such a trivial task, very many programs (including opencode itself in the JSON context used for the config) can just read environment variables directly without needing to start up a whole new shell in order to do it.

The code that opencode uses to do this in the configuration file can be found in packages/opencode/src/config/config.ts somewhere near line ~725 or so.

ariane-emory avatar Dec 04 '25 22:12 ariane-emory

Actually, we probably only want the f(env:SOME_VAR} syntax for MD frontmatter, the {file:some_file} syntax doesn't seem like it would be terribly useful in the context of frontmatter.

ariane-emory avatar Dec 04 '25 23:12 ariane-emory