Skip to content

fix: token substitution in OPENCODE_CONFIG_CONTENT#184

Open
ariane-emory wants to merge 7 commits intodevfrom
feat/config-content-interpolation-alternate
Open

fix: token substitution in OPENCODE_CONFIG_CONTENT#184
ariane-emory wants to merge 7 commits intodevfrom
feat/config-content-interpolation-alternate

Conversation

@ariane-emory
Copy link
Owner

@ariane-emory ariane-emory commented Feb 16, 2026

What does this PR do?

  • Route inline config through load() function to enable {env:} and {file:} token substitution
  • Refactor load(...) to accept an object as its second parameter and update its call sites accordingly.
  • Add tests for {env:} and {file:} token substitution in OPENCODE_CONFIG_CONTENT

NOTE: This PR is an alternate take on this issue. Unlike PR anomalyco#13384 (which was merged and subsequently reverted as it introduced a regression but about which I am thoroughly embarrassed). This alternate version changes one of the parameters of the load function in packages/opencode/src/config/config.ts to an object. While a slightly more complex change, this provides a more robust solution to the issue and avoids the possibility of passing {} as the environment variable's value creating an unwanted extra file in the project's root,

Fixes anomalyco#13219

How did you verify your code works?

Manual testing, bun typecheck, bun test.

You may manually test by running commands akin to the following (assuming bash):

echo "matrix" > /tmp/test-secret.txt 
export MODEL="opencode/big-pickle"
OPENCODE_CONFIG_CONTENT='{"$schema":"https://opencode.ai/config.json","theme":"{file:/tmp/test-secret.txt}", "model":"{env:MODEL}"}' bun dev
OPENCODE_CONFIG_CONTENT='{"theme":"{file:/tmp/test-secret.txt}", "model":"{env:MODEL}"}' bun dev # observe that it still works predictably without a $schema property on the object
OPENCODE_CONFIG_CONTENT='{}' bun dev # observe that no unwanted files are created

- Refactor load() to accept { configDir, configPath? } object for clarity
- Route inline config through load() to enable {env:} and {file:} token substitution
- Inline config uses configDir for file resolution without needing a synthetic path
- Access process.env directly for runtime env var access
- Add tests for {env:} and {file:} token substitution in OPENCODE_CONFIG_CONTENT

Fixes anomalyco#13219
@ariane-emory ariane-emory changed the title Feat/config content interpolation alternate fix: token substitution in OPENCODE_CONFIG_CONTENT Feb 17, 2026
ariane-emory and others added 3 commits February 17, 2026 19:10
- Refactor load() to use union type: { path } for files or { dir, source } for named sources
- Eliminate unclear "?? <inline>" fallback - source is now always explicit
- Error messages now show actual source: "OPENCODE_CONFIG_CONTENT" instead of "<inline>"
- Update all call sites: loadFile uses { path }, remote config and OPENCODE_CONFIG_CONTENT use { dir, source }
- Fix indentation issue in remote config handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OPENCODE_CONFIG_CONTENT bypasses {env:} and {file:} token substitution

1 participant

Comments