Problem
OpenCode sets process.env.OPENCODE = "1" and process.env.AGENT = "1" in a yargs middleware (source), but these vars are not visible in child processes spawned by the bash tool.
Root cause
OpenCode is compiled with bun build --compile. Bun's child_process.spawn does not inherit runtime process.env mutations when no explicit env option is passed — it snapshots the environment at startup.
// In Bun (not Node.js):
process.env.FOO = "1";
execSync("echo $FOO"); // prints empty
execSync("echo $FOO", { env: process.env }); // prints "1"
The V2 bash tool (packages/core/src/tool/bash.ts:159) creates ChildProcess.make() without an env option, so the runtime-set vars never reach child shells.
Impact
Libraries like am-i-vibing and @vercel/detect-agent cannot detect OpenCode. This breaks automatic agent-mode behavior in tools like Astro (which auto-starts astro dev as a background process when an agent is detected).
Repro
From within an OpenCode session:
echo "OPENCODE=$OPENCODE AGENT=$AGENT OPENCODE_PID=$OPENCODE_PID"
# Output: OPENCODE= AGENT= OPENCODE_PID=
Suggested fix
Pass env: process.env explicitly in the bash tool's ChildProcess.make() call, or set the env vars before the Bun compile snapshot.
Version
opencode 1.17.3 (Homebrew, macOS arm64)
Problem
OpenCode sets
process.env.OPENCODE = "1"andprocess.env.AGENT = "1"in a yargs middleware (source), but these vars are not visible in child processes spawned by the bash tool.Root cause
OpenCode is compiled with
bun build --compile. Bun'schild_process.spawndoes not inherit runtimeprocess.envmutations when no explicitenvoption is passed — it snapshots the environment at startup.The V2 bash tool (
packages/core/src/tool/bash.ts:159) createsChildProcess.make()without anenvoption, so the runtime-set vars never reach child shells.Impact
Libraries like
am-i-vibingand@vercel/detect-agentcannot detect OpenCode. This breaks automatic agent-mode behavior in tools like Astro (which auto-startsastro devas a background process when an agent is detected).Repro
From within an OpenCode session:
Suggested fix
Pass
env: process.envexplicitly in the bash tool'sChildProcess.make()call, or set the env vars before the Bun compile snapshot.Version
opencode 1.17.3 (Homebrew, macOS arm64)