Shell mode (! command) doesn't work on Windows
Description
The shell mode triggered by ! prefix (e.g., ! ls) does not work on Windows. Commands appear to hang/not respond.
Root Cause
In packages/opencode/src/session/prompt.ts line 1234:
const shell = process.env["SHELL"] ?? "bash"
On Windows:
process.env["SHELL"] is undefined (SHELL is a Unix environment variable)
- Code falls back to
"bash" which may not exist or work correctly
- Even if Git Bash exists, the Unix-style invocation args (
-c -l with bashrc sourcing) may cause issues
Comparison with Working Code
The AI's bash tool in packages/opencode/src/tool/bash.ts correctly handles Windows:
if (process.platform === "win32") {
// Let Bun / Node pick COMSPEC (usually cmd.exe)
return process.env.COMSPEC || true
}
There's also a utility function in packages/util/src/shell.ts that handles Windows:
if (process.platform === "win32") {
return process.env.COMSPEC || "cmd.exe"
}
However, session/prompt.ts doesn't use either of these.
Suggested Fix
- Import and use the existing shell utility:
import { shell as getShell } from "@opencode-ai/util/shell"
const shell = getShell()
- Add Windows-specific invocation to the
invocations object:
const invocations: Record<string, { args: string[] }> = {
// ... existing entries ...
"cmd.exe": {
args: ["/c", input.command],
},
"powershell.exe": {
args: ["-Command", input.command],
},
}
Environment
- OS: Windows
- OpenCode version: latest
Steps to Reproduce
- Run OpenCode on Windows
- Type
! ls or ! dir
- Observe that the command hangs/doesn't respond
Shell mode (! command) doesn't work on Windows
Description
The shell mode triggered by
!prefix (e.g.,! ls) does not work on Windows. Commands appear to hang/not respond.Root Cause
In
packages/opencode/src/session/prompt.tsline 1234:On Windows:
process.env["SHELL"]isundefined(SHELL is a Unix environment variable)"bash"which may not exist or work correctly-c -lwith bashrc sourcing) may cause issuesComparison with Working Code
The AI's bash tool in
packages/opencode/src/tool/bash.tscorrectly handles Windows:There's also a utility function in
packages/util/src/shell.tsthat handles Windows:However,
session/prompt.tsdoesn't use either of these.Suggested Fix
invocationsobject:Environment
Steps to Reproduce
! lsor! dir