Bug Description
When OpenCode is launched from a user's project directory and falls back to running via bun (no prebuilt binary found), the working directory gets incorrectly set to the OpenCode package directory instead of the user's project directory.
Root Cause
In packages/opencode/bin/opencode, the bun() function spawns bun with cwd: dir, where dir is the OpenCode package directory (resolved from scriptDir). This is necessary so that ./src/index.ts resolves correctly. However, it means process.cwd() in the spawned process returns the OpenCode package path, not the user's original working directory.
All CLI commands call bootstrap(process.cwd(), ...), which then passes the wrong directory to Instance.provide().
Expected Behavior
When a user runs opencode from /Users/user/my-project, the instance should be initialized with /Users/user/my-project as the working directory, regardless of whether the bun fallback path is used.
Fix
- Capture the original CWD in
bin/opencode before spawning bun and pass it as OPENCODE_ORIGINAL_CWD env var
- Resolve the env var centrally in
bootstrap() so all commands benefit