Skip to content

fix(core): apply variable substitution to v2 config loading - #42178

Open
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:config-file-substitute
Open

fix(core): apply variable substitution to v2 config loading#42178
vladislav-miroshnikov wants to merge 1 commit into
anomalyco:devfrom
vladislav-miroshnikov:config-file-substitute

Conversation

@vladislav-miroshnikov

@vladislav-miroshnikov vladislav-miroshnikov commented Aug 12, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #41973

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The v2 config loading path in packages/core/src/config.ts reads config files and parses them as JSONC without applying {file:} and {env:} variable substitution. The v1 path in packages/opencode/src/config/config.ts calls ConfigVariable.substitute() on the raw text before parsing. Through opencode run and the TUI (v1 path), {file:/tmp/demo.key} is resolved and the provider authenticates. Through opencode serve (v2 path), the literal string {file:/tmp/demo.key} ends up as the API key, causing 401s.

This PR adds an Effect-based substitute() function in packages/core/src/config/variable.ts that handles {env:VAR} and {file:path} substitutions, and calls it in loadFile() before JSONC parsing. The implementation mirrors the v1 substitution logic: supports ~/ expansion, relative paths (relative to the config file), skips substitution inside // line comments, and trims file content.

How did you verify your code works?

Added 5 tests to config.test.ts covering: {file:} with relative paths, {env:} substitution, // comment skipping, {file:} with absolute paths, and {file:} content containing JSON-special characters (quotes, backslashes, newlines). 20/20 tests pass, typecheck clean, prettier clean.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

{file:} apiKey sent as literal Bearer token on opencode serve v2 session path (401) — works in run/TUI

1 participant