[Windows] PersistentPty spawns MSYS2 zsh without -l (non-login), missing /usr/bin in PATH

オープン
#66,973 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
22/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript, zsh
領域
cli

調査の方向性

Start in packages/core/src/persistent-pty/index.ts around the PersistentPty.create call, which forwards args: [] to the daemon, and compare it with the -l handling in packages/core/src/pty.ts. Check whether ShellSelect.login should apply on this path, and reproduce the non-login zsh PATH problem in an MSYS2 session. Done means the built-in terminal starts as a login shell with the MSYS2 PATH intact, and the maintainers have confirmed whether omitting -l was intentional.

索引モデルが issue の本文から書いたものです。

説明

area/core platform/windows status/repro-simulated type/bug version/v2
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 -l in PersistentPty.create: Pty.create in packages/core/src/pty.ts (L168–169) checks ShellSelect.login(command) and automatically appends "-l" for shells like bash and zsh. 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 through PersistentPty.create (packages/core/src/persistent-pty/index.ts, L251–263), which forwards the client-provided args: [] directly to the opencode-pty daemon (and reads ShellSelect.environment() instead of config.shell, see #51051). As a result, MSYS2 zsh skips /etc/profile and loses /ucrt64/bin, /usr/bin, and /bin from PATH. I'm not completely sure whether omitting -l in PersistentPty is intentional or a bug.
  • POSIX path lookup on Windows: full() and executable() in packages/core/src/shell/select.ts currently only map /.../bash paths to gitbash() on Windows—when encountering a drive-less POSIX path like /usr/bin/zsh.exe whose native stat() fails, they do not fall back to looking up the basename on PATH.
  • Non-interactive shell tool in opencode pair: ShellSelect.args() runs zsh with ["+o", "nomatch", "-c", command], which in background-service-backed opencode pair sessions only inherits the service's own environment and ~/.zshenv.
Plugins

None

OpenCode version

v2.3.2

Steps to reproduce
  1. On Windows 10, start MSYS2 zsh using C:\msys64\msys2_shell.cmd -defterm -here -no-start -ucrt64 -shell zsh -use-full-path (without manually patching PATH in ~/.zshenv).
  2. Run opencode or opencode pair inside that zsh session.
  3. Open the built-in terminal (/terminal in TUI, or the sidebar Terminal in the Web UI).
  4. In the new built-in terminal, check login mode and PATH:
    [[ -o login ]] && echo login || echo non-login
    echo "$PATH"
    
    Observe that zsh launches as non-login with /ucrt64/bin, /usr/bin, and /bin missing from PATH (and prompt themes like Powerlevel10k fail with gitstatus 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

主要言語
TypeScript
スター
230k
フォーク
31.3k
平均マージ
5時間 32分
マージ済み PR(30日)
453

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

anomalyco/opencode のほかの issue

anomalyco/opencode の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。