Skip to content

fix(server): resolve the configured shell for session terminals - #51052

Closed
Tsuki-hash wants to merge 2 commits into
anomalyco:devfrom
Tsuki-hash:terminal-shell-config
Closed

Tsuki-hash wants to merge 2 commits into
anomalyco:devfrom
Tsuki-hash:terminal-shell-config

Conversation

@Tsuki-hash

Copy link
Copy Markdown

Issue for this PR

Fixes #51051 (#51051)

Type of change

  • Bug fix

What does this PR do?

shell is documented as the shell used for the interactive terminal, and both the shell tool
(shell.ts:263) and pty.ts:166 resolve it through ShellSelect.Service. Session terminals did not:
persistent-pty/index.ts:160 falls back to the free ShellSelect.environment(), which reads only
process.env.SHELL and passes undefined in the slot where the configured options belong.
process.env.SHELL is normally unset on Windows and the Windows branch of select() puts
pwsh/powershell first, so a Windows session terminal started PowerShell whatever shell said, while the
agent's own commands ran in the configured shell.

persistentPty.create now resolves the configured shell and passes it down as command. It is resolved
in the handler rather than inside PersistentPty deliberately: PersistentPty is a process-global node
and ShellSelect.Service is Location-scoped, so the service cannot be yielded there —
handlers/config.ts:21 is the existing precedent for reaching it from a handler. Tell me if you would
rather have it as a resolver option on the PersistentPty layer and I will move it.

An explicit command in the request payload still wins, and non-HTTP callers keep the old fallback.

How did you verify your code works?

I did not run the repo checks: no Bun on this machine, so bun typecheck and bun run check never ran,
and no session terminal was actually opened. What I traced, at v2 tip 318a8c1:

  • persistent-pty/index.ts:160 is the only consumer of ShellSelect.environment(), and the TUI's New Terminal action (tui/src/context/session-terminals.tsx:78-86) sends no command, so the fallback is the live path.
  • handlers.ts builds ConfigHandler and PersistentPtyHandler in one list, and routes.ts:130 replaces ShellSelect.node with the configured variant, so the service a handler yields is the configured one.
  • The only other create caller is the legacy handlers/pty.ts:47, which already resolves config via pty.ts:166.
  • packages/server already imports @opencode/core/shell/select (handlers/config.ts:2), so no new dependency direction.

To confirm for real: set "shell" to a Git Bash path on Windows, open a session terminal, and see that
$PSVersionTable no longer answers.

Screenshots / recordings

No UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

"Tested locally" covers the source trace above and nothing more — the handler itself was not executed.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@Tsuki-hash

Tsuki-hash commented Sep 24, 2026 •

Copy link
Copy Markdown
Author

Correcting what I wrote earlier, because I had the cause wrong twice and the accurate version is more useful to whoever triages this: needs:issue here is not a fork limitation. Keyword closing references are only populated for PRs that target the repository default branch, and #43964 added a PR-body fallback for exactly that reason (merged 2026-08-25). It is present in .github/workflows/pr-standards.yml on v2 but not on dev, and the pull_request_target run for this PR executed the dev copy — its logged script contains if (linkedIssues === 0) and no hasBodyIssueRef. So the fallback exists but cannot take effect, and ~141 open PRs currently carry the label including #51035 and #51043. The description does reference #51051 as Fixes #51051 in the "Issue for this PR" section.

@Tsuki-hash

Copy link
Copy Markdown
Author

Friendly nudge — checked against the current v2 tip (ea66672): the fallback this fixes (ShellSelect.environment()) is unchanged and persistentPty.create still uses only the payload command, so the bug is live. The branch merges cleanly. It's a small change: resolve the configured shell in the handler (a few lines), plus a regression test (076abba) asserting the configured shell is the one actually spawned when no explicit command is sent. Happy to move the resolution into the PersistentPty layer if that fits better.

@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:16
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session terminal ignores the "shell" config option (always PowerShell on Windows)

1 participant