Skip to content

Commit dff8bbf

Browse files
committed
refactor: make OPENCODE_CONFIG_CONTENT a dynamic Flag getter
Converts OPENCODE_CONFIG_CONTENT to a dynamic getter on the Flag object, matching the pattern used for OPENCODE_CONFIG_DIR and OPENCODE_CLIENT. This ensures env var changes are reflected at access time.
1 parent 68eb034 commit dff8bbf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/opencode/src/config/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,10 @@ export namespace Config {
178178
// Route through load() to enable {env:} and {file:} token substitution.
179179
// Use a path within Instance.directory so relative {file:} paths resolve correctly.
180180
// The filename "OPENCODE_CONFIG_CONTENT" appears in error messages for clarity.
181-
if (process.env.OPENCODE_CONFIG_CONTENT) {
181+
if (Flag.OPENCODE_CONFIG_CONTENT) {
182182
result = mergeConfigConcatArrays(
183183
result,
184-
await load(process.env.OPENCODE_CONFIG_CONTENT, path.join(Instance.directory, "OPENCODE_CONFIG_CONTENT")),
184+
await load(Flag.OPENCODE_CONFIG_CONTENT, path.join(Instance.directory, "OPENCODE_CONFIG_CONTENT")),
185185
)
186186
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
187187
}

packages/opencode/src/flag/flag.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export namespace Flag {
88
export const OPENCODE_GIT_BASH_PATH = process.env["OPENCODE_GIT_BASH_PATH"]
99
export const OPENCODE_CONFIG = process.env["OPENCODE_CONFIG"]
1010
export declare const OPENCODE_CONFIG_DIR: string | undefined
11-
export const OPENCODE_CONFIG_CONTENT = process.env["OPENCODE_CONFIG_CONTENT"]
11+
export declare const OPENCODE_CONFIG_CONTENT: string | undefined
1212
export const OPENCODE_DISABLE_AUTOUPDATE = truthy("OPENCODE_DISABLE_AUTOUPDATE")
1313
export const OPENCODE_DISABLE_PRUNE = truthy("OPENCODE_DISABLE_PRUNE")
1414
export const OPENCODE_DISABLE_TERMINAL_TITLE = truthy("OPENCODE_DISABLE_TERMINAL_TITLE")
@@ -91,3 +91,14 @@ Object.defineProperty(Flag, "OPENCODE_CLIENT", {
9191
enumerable: true,
9292
configurable: false,
9393
})
94+
95+
// Dynamic getter for OPENCODE_CONFIG_CONTENT
96+
// This must be evaluated at access time, not module load time,
97+
// because external tooling may set this env var at runtime
98+
Object.defineProperty(Flag, "OPENCODE_CONFIG_CONTENT", {
99+
get() {
100+
return process.env["OPENCODE_CONFIG_CONTENT"]
101+
},
102+
enumerable: true,
103+
configurable: false,
104+
})

0 commit comments

Comments
 (0)