Skip to content

feat(opencode): autoload .env from global config directory for {env:}…#33051

Closed
letanphuc wants to merge 1 commit into
anomalyco:devfrom
letanphuc:dev
Closed

feat(opencode): autoload .env from global config directory for {env:}…#33051
letanphuc wants to merge 1 commit into
anomalyco:devfrom
letanphuc:dev

Conversation

@letanphuc

Copy link
Copy Markdown

… substitution

Issue for this PR

Closes #

Type of change

  • Bug fix
  • [X ] New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

OpenCode now auto-loads ~/.config/opencode/.env on startup via Node's built-in process.loadEnvFile. The vars are loaded into process.env before any config files are read, so {env:VAR} references in config files (e.g. MCP headers, provider API keys) resolve against the .env file.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

  • Added a test (loads .env from global config directory for {env:} substitution) that creates a temp global config dir with an .env file and an opencode.json using {env:MY_DOTENV_VAR}, then asserts the substitution resolves correctly.
  • Built the single binary with ./packages/opencode/script/build.ts --single — passed smoke test.
  • Typecheck across all 29 packages passed via bun turbo typecheck.

Screenshots / recordings

If this is a UI change, please include a screenshot or recording.

Checklist

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

If you do not follow this template your PR will be automatically rejected.

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • No "Type of change" checkbox is checked. Please select at least one.
  • Not all checklist items are checked. Please confirm you have tested locally and have not included unrelated changes.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found several related PRs that address similar functionality:

  1. PR fix(opencode): escape {env:} substitutions to keep config JSON valid #32786 - fix(opencode): escape {env:} substitutions to keep config JSON valid

    • Related to handling {env:} syntax in config files
  2. PR fix(config): support ${env:VAR} syntax in addition to {env:VAR} for env substitution #29282 - fix(config): support ${env:VAR} syntax in addition to {env:VAR} for env substitution

    • Addresses environment variable substitution in config with alternative syntax
  3. PR fix(config): load .env from config dir for {env:VAR} substitution #21197 - fix(config): load .env from config dir for {env:VAR} substitution

    • Very closely related—loads .env from config directory for {env:VAR} substitution (appears to be addressing similar functionality)
  4. PR refactor(opencode): type config loader env #28739 - refactor(opencode): type config loader env

    • Related to environment variable handling in config loading

PR #21197 is the most relevant as it appears to handle loading .env files for {env:VAR} substitution. You may want to check if this PR was merged and whether the current PR #33051 extends or supersedes that work, or if it's implementing the same fix for the global config directory specifically.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 20, 2026
@github-actions github-actions Bot closed this Jun 20, 2026
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.

1 participant