-
Notifications
You must be signed in to change notification settings - Fork 7.2k
feat(opencode): add configurable shell resolution with plugin support #9724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
feat(opencode): add configurable shell resolution with plugin support #9724
Conversation
- Add 'shell' config option to opencode.json for explicit shell override - Add 'shell.resolve' plugin hook for dynamic shell resolution - Convert Shell.preferred() and Shell.acceptable() to async - Update call sites in bash tool, pty, and prompt to await shell - Add comprehensive tests for config, plugin, and fallback scenarios - Regenerate SDK types to include new shell config property
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: No duplicate PRs found |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds configurable shell resolution with plugin support to OpenCode, allowing users to override shell detection through configuration or plugins instead of relying solely on environment variables.
Changes:
- Added
shellconfiguration field to allow explicit shell path override - Implemented plugin hook
shell.resolvefor dynamic shell resolution - Converted
Shell.preferred()andShell.acceptable()from synchronous to async functions - Updated all call sites to use
awaitwith the newly async shell functions
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
packages/opencode/src/config/config.ts |
Added optional shell field to config schema |
packages/sdk/openapi.json |
Regenerated SDK with new shell config field |
packages/sdk/js/src/v2/gen/types.gen.ts |
Regenerated TypeScript types with shell config |
packages/plugin/src/index.ts |
Added shell.resolve hook for plugin-based shell resolution |
packages/opencode/src/shell/shell.ts |
Converted to async, added config/plugin resolution with priority chain |
packages/opencode/src/tool/bash.ts |
Added await to Shell.acceptable() call |
packages/opencode/src/pty/index.ts |
Added await to Shell.preferred() call |
packages/opencode/src/session/prompt.ts |
Added await to Shell.preferred() call |
packages/opencode/test/shell/shell.test.ts |
Added 4 tests for config, plugin, and fallback behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Remove unused imports (Config, path) - Add return statement to mock function - Add test for Shell.acceptable() with plugin - Add test for Shell.acceptable() fallback on blacklisted shell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Improve shell config description with priority info and examples - Add JSDoc documentation for shell.resolve plugin hook - Add test: config takes priority over plugin - Add test: config can override blacklist for Shell.acceptable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Adds a first-class way to control which shell OpenCode uses when executing commands. Users (and plugin authors) can now override shell resolution explicitly instead of relying on
$SHELLand platform defaults.Fixes #4702
Problem
Today, the bash tool’s shell selection is implicit: OpenCode primarily relies on
$SHELLand then falls back to OS defaults. That’s fine for simple local setups, but it breaks down whenever “my login shell” is not the same as “the shell OpenCode should execute commands with.”$SHELLis global, can point at non-POSIX shells, and is often misleading in containerized/remote/dev environments (#8396), forcing users into brittle workarounds (wrapper scripts, aliases, or forks) just to control command execution.This shows up in several common scenarios:
docker runwith a read-only filesystem) so they can set"bash": "allow"without approving every command while still reducing risk. [FEATURE]: Add config to change shell for bash tool #4702/bin/bashfor CI parity or/bin/zshfor team conventions) independent of the user’s interactive environment.$SHELLcan reflect the host/login context rather than the environment where commands should run leading to surprising behavior and “works on my machine” inconsistencies.Solution
Shell resolution is now explicit and extensible, while preserving existing behavior by default. OpenCode resolves the shell using the following priority order:
"shell": "/bin/zsh"(or a wrapper) inopencode.jsonshell.resolvecan dynamically choose a shell per workspace/environment$SHELL(existing behavior)This keeps backward compatibility for current users, but unlocks predictable, per-project and policy-driven shell behavior for advanced setups.