summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2026-02-12 23:24:31 -0600
committerGitHub <[email protected]>2026-02-12 23:24:31 -0600
commit1fb6c0b5b356e3816398ba71ac1b01485697bc31 (patch)
tree2e4fa0739bab7142a601421a454670958dbdaad4
parent98aeb60a7f0e00e251ff02c360829a3679d65717 (diff)
downloadopencode-1fb6c0b5b356e3816398ba71ac1b01485697bc31.tar.gz
opencode-1fb6c0b5b356e3816398ba71ac1b01485697bc31.zip
Revert "fix: token substitution in OPENCODE_CONFIG_CONTENT" (#13429)
-rw-r--r--packages/opencode/src/config/config.ts8
-rw-r--r--packages/opencode/src/flag/flag.ts13
-rw-r--r--packages/opencode/test/config/config.test.ts65
3 files changed, 2 insertions, 84 deletions
diff --git a/packages/opencode/src/config/config.ts b/packages/opencode/src/config/config.ts
index f4d7a840f..8f0f583ea 100644
--- a/packages/opencode/src/config/config.ts
+++ b/packages/opencode/src/config/config.ts
@@ -175,14 +175,8 @@ export namespace Config {
}
// Inline config content overrides all non-managed config sources.
- // Route through load() to enable {env:} and {file:} token substitution.
- // Use a path within Instance.directory so relative {file:} paths resolve correctly.
- // The filename "OPENCODE_CONFIG_CONTENT" appears in error messages for clarity.
if (Flag.OPENCODE_CONFIG_CONTENT) {
- result = mergeConfigConcatArrays(
- result,
- await load(Flag.OPENCODE_CONFIG_CONTENT, path.join(Instance.directory, "OPENCODE_CONFIG_CONTENT")),
- )
+ result = mergeConfigConcatArrays(result, JSON.parse(Flag.OPENCODE_CONFIG_CONTENT))
log.debug("loaded custom config from OPENCODE_CONFIG_CONTENT")
}
diff --git a/packages/opencode/src/flag/flag.ts b/packages/opencode/src/flag/flag.ts
index 641cb3325..dfcb88bc5 100644
--- a/packages/opencode/src/flag/flag.ts
+++ b/packages/opencode/src/flag/flag.ts
@@ -8,7 +8,7 @@ export namespace Flag {
export const OPENCODE_GIT_BASH_PATH = process.env["OPENCODE_GIT_BASH_PATH"]
export const OPENCODE_CONFIG = process.env["OPENCODE_CONFIG"]
export declare const OPENCODE_CONFIG_DIR: string | undefined
- export declare const OPENCODE_CONFIG_CONTENT: string | undefined
+ export const OPENCODE_CONFIG_CONTENT = process.env["OPENCODE_CONFIG_CONTENT"]
export const OPENCODE_DISABLE_AUTOUPDATE = truthy("OPENCODE_DISABLE_AUTOUPDATE")
export const OPENCODE_DISABLE_PRUNE = truthy("OPENCODE_DISABLE_PRUNE")
export const OPENCODE_DISABLE_TERMINAL_TITLE = truthy("OPENCODE_DISABLE_TERMINAL_TITLE")
@@ -94,14 +94,3 @@ Object.defineProperty(Flag, "OPENCODE_CLIENT", {
enumerable: true,
configurable: false,
})
-
-// Dynamic getter for OPENCODE_CONFIG_CONTENT
-// This must be evaluated at access time, not module load time,
-// because external tooling may set this env var at runtime
-Object.defineProperty(Flag, "OPENCODE_CONFIG_CONTENT", {
- get() {
- return process.env["OPENCODE_CONFIG_CONTENT"]
- },
- enumerable: true,
- configurable: false,
-})
diff --git a/packages/opencode/test/config/config.test.ts b/packages/opencode/test/config/config.test.ts
index 331e05d5a..91b87f649 100644
--- a/packages/opencode/test/config/config.test.ts
+++ b/packages/opencode/test/config/config.test.ts
@@ -1800,68 +1800,3 @@ describe("OPENCODE_DISABLE_PROJECT_CONFIG", () => {
}
})
})
-
-// OPENCODE_CONFIG_CONTENT should support {env:} and {file:} token substitution
-// just like file-based config sources do.
-describe("OPENCODE_CONFIG_CONTENT token substitution", () => {
- test("substitutes {env:} tokens in OPENCODE_CONFIG_CONTENT", async () => {
- const originalEnv = process.env["OPENCODE_CONFIG_CONTENT"]
- const originalTestVar = process.env["TEST_CONFIG_VAR"]
- process.env["TEST_CONFIG_VAR"] = "test_api_key_12345"
- process.env["OPENCODE_CONFIG_CONTENT"] = JSON.stringify({
- $schema: "https://opencode.ai/config.json",
- theme: "{env:TEST_CONFIG_VAR}",
- })
-
- try {
- await using tmp = await tmpdir()
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await Config.get()
- expect(config.theme).toBe("test_api_key_12345")
- },
- })
- } finally {
- if (originalEnv !== undefined) {
- process.env["OPENCODE_CONFIG_CONTENT"] = originalEnv
- } else {
- delete process.env["OPENCODE_CONFIG_CONTENT"]
- }
- if (originalTestVar !== undefined) {
- process.env["TEST_CONFIG_VAR"] = originalTestVar
- } else {
- delete process.env["TEST_CONFIG_VAR"]
- }
- }
- })
-
- test("substitutes {file:} tokens in OPENCODE_CONFIG_CONTENT", async () => {
- const originalEnv = process.env["OPENCODE_CONFIG_CONTENT"]
-
- try {
- await using tmp = await tmpdir({
- init: async (dir) => {
- await Bun.write(path.join(dir, "api_key.txt"), "secret_key_from_file")
- process.env["OPENCODE_CONFIG_CONTENT"] = JSON.stringify({
- $schema: "https://opencode.ai/config.json",
- theme: "{file:./api_key.txt}",
- })
- },
- })
- await Instance.provide({
- directory: tmp.path,
- fn: async () => {
- const config = await Config.get()
- expect(config.theme).toBe("secret_key_from_file")
- },
- })
- } finally {
- if (originalEnv !== undefined) {
- process.env["OPENCODE_CONFIG_CONTENT"] = originalEnv
- } else {
- delete process.env["OPENCODE_CONFIG_CONTENT"]
- }
- }
- })
-})