@@ -37,6 +37,17 @@ import { resolveSpawnCommand } from "@t3tools/shared/shell";
3737const encodeUnknownJsonStringExit = Schema . encodeUnknownExit ( Schema . fromJsonString ( Schema . Unknown ) ) ;
3838const OPENCODE_EMPTY_CONFIG_CONTENT = "{}" ;
3939
40+ export function resolveOpenCodeConfigContent (
41+ inputEnvironment : Readonly < Record < string , string | undefined > > | undefined ,
42+ inheritedEnvironment : Readonly < Record < string , string | undefined > > = process . env ,
43+ ) : string {
44+ return (
45+ inputEnvironment ?. OPENCODE_CONFIG_CONTENT ??
46+ inheritedEnvironment . OPENCODE_CONFIG_CONTENT ??
47+ OPENCODE_EMPTY_CONFIG_CONTENT
48+ ) ;
49+ }
50+
4051const OPENCODE_SERVER_READY_PREFIX = "opencode server listening" ;
4152const DEFAULT_OPENCODE_SERVER_TIMEOUT_MS = 30_000 ;
4253const DEFAULT_HOSTNAME = "127.0.0.1" ;
@@ -467,7 +478,14 @@ const makeOpenCodeRuntime = Effect.gen(function* () {
467478 shell : spawnCommand . shell ,
468479 env : {
469480 ...input . environment ,
470- OPENCODE_CONFIG_CONTENT : OPENCODE_EMPTY_CONFIG_CONTENT ,
481+ // Respect an OPENCODE_CONFIG_CONTENT provided by the caller or
482+ // the inherited process environment, only falling back to the
483+ // empty config when neither is set. Setting it unconditionally
484+ // previously clobbered the user's opencode config, hiding their
485+ // providers/models. The value is set explicitly (rather than
486+ // relying on inheritance) because `extendEnv` is false whenever
487+ // `input.environment` is provided.
488+ OPENCODE_CONFIG_CONTENT : resolveOpenCodeConfigContent ( input . environment ) ,
471489 } ,
472490 extendEnv : input . environment === undefined ,
473491 } ) ,
0 commit comments