Skip to content

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

@spoj

Description

@spoj

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions