[Windows] PersistentPty spawns MSYS2 zsh without -l (non-login), missing /usr/bin in PATH
Description
On Windows 10, after starting MSYS2 zsh via C:\msys64\msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell zsh -use-full-path and running opencode or opencode pair inside it, opening the built-in terminal (via /terminal in the TUI or the sidebar Terminal in the Web UI) spawns a zsh process that still receives SHELL and MSYSTEM, but starts in non-login mode (! -o login) and is missing /ucrt64/bin, /usr/bin, and /bin from PATH. As a result, tools and prompt themes that rely on MSYS2's /etc/profile PATH setup fail to initialize (for example, Powerlevel10k reports gitstatus failed to initialize):
Terminal error output (without the ~/.zshenv workaround)
[WARNING]: Console output during zsh initialization detected.
...
[ERROR]: gitstatus failed to initialize.
Add the following parameter to ~/.zshrc for extra diagnostics on error:
GITSTATUS_LOG_LEVEL=DEBUG
Restart Zsh to retry gitstatus initialization:
exec zsh
Adding the following workaround in ~/.zshenv resolves the terminal issue (checking -o interactive && ! -o login confirms that the built-in terminal starts zsh as interactive non-login):
if [[ -o interactive && ! -o login && ":$PATH:" != *":/usr/bin:"* ]]; then
export MSYSTEM="${MSYSTEM:-UCRT64}"
typeset -U path
if [[ "$MSYSTEM" == MSYS ]]; then
path=(/usr/local/bin /usr/bin /bin $path)
else
path=(/${MSYSTEM:l}/bin /usr/local/bin /usr/bin /bin $path)
fi
fi
Also worth noting: in opencode pair (Web) sessions, because the background service runs independently of the launching terminal and the model shell tool executes zsh non-interactively (zsh +o nomatch -c), it likewise does not pick up MSYS2 /etc/profile, ~/.zprofile, or ~/.zshrc environment setup (related: #51051, #57310).
Source code notes (as of v2.3.2)
- Missing
-linPersistentPty.create:Pty.createinpackages/core/src/pty.ts(L168–169) checksShellSelect.login(command)and automatically appends"-l"for shells likebashandzsh. However, both the TUI/terminal(packages/tui/src/context/session-terminals.tsx, L104–110) and the Web sidebar terminal (packages/gui-plugins/src/terminal/model.ts, L327–337) go throughPersistentPty.create(packages/core/src/persistent-pty/index.ts, L251–263), which forwards the client-providedargs: []directly to theopencode-ptydaemon (and readsShellSelect.environment()instead ofconfig.shell, see #51051). As a result, MSYS2zshskips/etc/profileand loses/ucrt64/bin,/usr/bin, and/binfromPATH. I'm not completely sure whether omitting-linPersistentPtyis intentional or a bug. - POSIX path lookup on Windows:
full()andexecutable()inpackages/core/src/shell/select.tscurrently only map/.../bashpaths togitbash()on Windows—when encountering a drive-less POSIX path like/usr/bin/zsh.exewhose nativestat()fails, they do not fall back to looking up the basename onPATH. - Non-interactive
shelltool inopencode pair:ShellSelect.args()runszshwith["+o", "nomatch", "-c", command], which in background-service-backedopencode pairsessions only inherits the service's own environment and~/.zshenv.
Plugins
None
OpenCode version
v2.3.2
Steps to reproduce
- On Windows 10, start MSYS2
zshusingC:\msys64\msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell zsh -use-full-path(without manually patchingPATHin~/.zshenv). - Run
opencodeoropencode pairinside thatzshsession. - Open the built-in terminal (
/terminalin TUI, or the sidebar Terminal in the Web UI). - In the new built-in terminal, check login mode and
PATH:
Observe that[[ -o login ]] && echo login || echo non-login echo "$PATH"zshlaunches asnon-loginwith/ucrt64/bin,/usr/bin, and/binmissing fromPATH(and prompt themes like Powerlevel10k fail withgitstatus failed to initialize).
Screenshot
No response
Operating System
Microsoft Windows 10 Pro (10.0.19045 Build 19045)
Terminal
WezTerm (MSYS2 UCRT64 zsh) / OpenCode TUI & Web Terminal
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the detailed write-up and the source pointers. I reproduced the core of this on Linux with 2.3.2, driving the TUI with a script. A simulated model was used only to create a session, because /terminal only works inside one; the terminal itself didn't depend on it.
There is no zsh in my sandbox, so I set SHELL=/usr/bin/bash (bash and zsh are handled the same way here). In a terminal opened with /terminal, shopt -q login_shell reports non-login, and the shell's argv is just /usr/bin/bash, with no -l. This matches your reading: Pty.create in packages/core/src/pty.ts adds -l for login-capable shells, but PersistentPty.create passes the client's args: [] to the PTY daemon unchanged. It still happens on the latest dev (2204311e).
I couldn't test the MSYS2/Windows part (/etc/profile not being sourced, so /usr/bin is missing from PATH) here, but it follows from the shell starting as non-login. The recording and screenshot below show the run, and the script below reproduces it.
Related: #51051 (the session terminal ignores the shell config option) is the same code path but a separate problem.
https://anoma.ly/team/github-bot/media/e1537a28782ae22e19883496df73373e7fa2c10aefacb9da27cef95a03cf4a25.mp4

Reproduction script (drive.ts)
// Repro for anomalyco/opencode#66973: the TUI session terminal (/terminal -> PersistentPty)
// starts a login-capable shell (bash here; zsh in the report) WITHOUT "-l", so it runs as a
// NON-login shell and skips /etc/profile. Pty.create, by contrast, appends "-l" for these shells.
import { Effect } from "effect"
import { Llm, OpenCodeDriver } from "opencode-drive"
process.env.SHELL = "/usr/bin/bash"
// The "RESULT""_" split keeps the echoed command line itself from matching.
const probe = `shopt -q login_shell && L=login || L=non-login; echo "RESULT""_MODE=$L"; echo "RESULT""_CMDLINE=$(tr '\\0' ' ' </proc/$$/cmdline | tr ' ' '|')"`
export default OpenCodeDriver.use(
{
...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
project: { git: true },
tui: { recording: true },
},
({ ui, llm }) =>
Effect.gen(function* () {
// /terminal is only available inside a session, so create one first.
yield* llm.queue(Llm.text("Hello."))
yield* llm.queue(Llm.text("Greeting")) // session title request
yield* ui.submit("hi")
yield* ui.waitFor("Hello.", { timeout: 30000 })
// Open a session terminal with the /terminal slash command.
yield* ui.type("/terminal")
yield* Effect.sleep(1000)
yield* ui.enter()
yield* Effect.sleep(4000)
yield* ui.type(probe)
yield* ui.enter()
yield* Effect.sleep(3000)
yield* ui.screenshot("session-terminal")
const frame = JSON.stringify(yield* ui.capture())
yield* Effect.log(frame.match(/RESULT_[A-Z]+=[^ "\\]+/g))
}),
)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Confirmed, your analysis is right. Pty.create (packages/core/src/pty.ts) appends -l when ShellSelect.login(command) is true, but PersistentPty.create (packages/core/src/persistent-pty/index.ts) forwards the client-provided args straight to the opencode-pty daemon with no login handling, and both the TUI and web terminal callers pass args: []. So a login shell like MSYS2 zsh starts non-login and skips /etc/profile, which is exactly the missing /usr/bin in PATH you saw.
I reproduced it with a test against the fake daemon: creating terminals for bash and zsh sends create_pty requests with args: [], where Pty.create would send ["-l"]. Working on a fix to apply the same login handling in PersistentPty.create.