Skip to content

OPENCODE/AGENT env vars not propagated to bash tool child processes (Bun compiled binary) #32689

@matthewp

Description

@matthewp

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)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions