fix(cli): Prevent Bun from auto-loading project .env files causing env pollution#133
Open
Aykahshi wants to merge 1 commit intokdcokenny:mainfrom
Open
fix(cli): Prevent Bun from auto-loading project .env files causing env pollution#133Aykahshi wants to merge 1 commit intokdcokenny:mainfrom
Aykahshi wants to merge 1 commit intokdcokenny:mainfrom
Conversation
- added autoloadDotenv: false in `build-binary.ts` - added `--no-env-file` into `index.ts`
Owner
|
Does adding the env files to the exclude file not work? |
Author
No, unfortunately exclude in Bun grabs the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.envfile loading for both npm and compiled binary distributionsCloses openai oauth token expired in ocx profile #125
Problem
OCX should maintain strict environment isolation from the CWD. Currently, Bun's default behavior auto-loads
.envfiles from the CWD intoprocess.envbefore execution.When OCX launches OpenCode via
Bun.spawn(), this pollutedprocess.envis inherited by the sub-process. This breaks any Provider configured via environment variables (e.g., OpenAI, Anthropic).For instance, a project-level
OPENAI_BASE_URLwill override OpenCode's internal configurations, leading to endpoint mismatches or OAuth failures.Basically, OCX shouldn't be picking up a project's local
.envmess just because it's running there.Solution
We must explicitly disable Bun's auto-loading behavior to ensure environment isolation.
Two changes to cover both distribution methods:
scripts/build-binary.ts): AddedautoloadDotenv: falsetoBun.build()compile options — baked into the binary at build time.src/index.ts): Changed shebang from#!/usr/bin/env bunto#!/usr/bin/env -S bun --no-env-file— prevents.envloading when invoked via shell.Changes
packages/cli/scripts/build-binary.ts— AddautoloadDotenv: falseto compile optionspackages/cli/src/index.ts— Update shebang to include--no-env-fileSummary by cubic
Disable Bun’s automatic .env loading for the OCX CLI to stop project env variables from leaking into spawned OpenCode processes. Ensures environment isolation for both npm and compiled binary builds.
Written for commit dc39e8e. Summary will update on new commits.