Skip to content

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

Closed

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

Activity

  1. github-actions commented on Dec 10, 2025

    @github-actions
    Contributor

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

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

  2. added a commit that references this issue on Dec 10, 2025
    4da9ce5
  3. self-assigned this
    on Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions