Shell mode (! command) doesn't work on Windows #3439

Closed
opened 2026-02-16 17:40:05 -05:00 by yindo · 1 comment
Owner

Originally created by @spoj on GitHub (Dec 10, 2025).

Originally assigned to: @rekram1-node on GitHub.

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

  1. Import and use the existing shell utility:
import { shell as getShell } from "@opencode-ai/util/shell"
const shell = getShell()
  1. 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

  1. Run OpenCode on Windows
  2. Type ! ls or ! dir
  3. Observe that the command hangs/doesn't respond
Originally created by @spoj on GitHub (Dec 10, 2025). Originally assigned to: @rekram1-node on GitHub. # 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: ```typescript 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: ```typescript 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: ```typescript if (process.platform === "win32") { return process.env.COMSPEC || "cmd.exe" } ``` However, `session/prompt.ts` doesn't use either of these. ## Suggested Fix 1. Import and use the existing shell utility: ```typescript import { shell as getShell } from "@opencode-ai/util/shell" const shell = getShell() ``` 2. Add Windows-specific invocation to the `invocations` object: ```typescript 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 1. Run OpenCode on Windows 2. Type `! ls` or `! dir` 3. Observe that the command hangs/doesn't respond
yindo closed this issue 2026-02-16 17:40:05 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 10, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #4671: shell mode (!) is broken on Windows Powershell

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 10, 2025): This issue might be a duplicate of existing issues. Please check: - #4671: shell mode (`!`) is broken on Windows Powershell Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3439