You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode run resolves session directory from $PWD instead of process cwd (breaks headless spawn) #47080
When opencode run is spawned as a subprocess with a working directory set (Node spawnSync/spawncwd, Python subprocesscwd, posix_spawn, …) and inherits a stale PWD — which is the normal case, since spawn APIs set the process cwd but do not rewrite the environment variable — the CLI bootstraps the correct directory once, then creates a second instance resolved from env.PWD and registers the session there. Project-local .opencode/ config (agents, commands) then resolves against the wrong directory.
In our case (headless CI-style runner): --command/--agent names that exist in the cwd's .opencode/ were missing in the $PWD instance, and SessionPrompt.command threw, surfacing as a 500 {"name":"UnknownError","message":"Unexpected server error. Check server logs for details."} ~200ms after session creation, with no corresponding entry in the opencode log.
From the 1.18.27 binary the resolution is literally resolve(process.env.PWD ?? process.cwd()). --dir is unaffected because it goes through process.chdir().
Actual: the logs show a second creating instance at /tmp and the session is created there (project global), losing the real directory's .opencode config. The same run with a correct PWD, or with --dir /tmp/real, registers /tmp/real.
Workaround: set PWD in the child environment, or pass --dir.
Secondary point
A --command/--agent that does not resolve in the effective directory should fail with a clear 4xx ("unknown command: …"), not a generic 500 — the opaque UnknownError plus the absent log entry made this much harder to diagnose than it needed to be.
Related
#41841 and #46276 report the same "two directory-scoped instances" signature via --session + a mismatched --dir; the $PWD-over-cwd resolution above looks like the underlying cause.
I can reproduce this on 1.18.27, and I hit it from a Python orchestrator that sets cwd without rewriting PWD.
Happy to take it if you want. E.g., keep PWD when it resolves to the same real path as process.cwd(), and fall back to cwd otherwise, so the symlinked-home cases from #16528 and #16603 stay fixed.
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.
Activity
thossullivan commentedon Sep 3, 2026
I can reproduce this on 1.18.27, and I hit it from a Python orchestrator that sets
cwdwithout rewritingPWD.Happy to take it if you want. E.g., keep
PWDwhen it resolves to the same real path asprocess.cwd(), and fall back tocwdotherwise, so the symlinked-home cases from #16528 and #16603 stay fixed.that-Gui commentedon Sep 4, 2026
👌🏻👍🏻
thdxr commentedon Oct 11, 2026
Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (
opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊