Skip to content

[Bug]: Shell execution silent/no output on Windows + .sh file association popup #384

@auric

Description

@auric

Platform

OpenCode (also affects all platforms on Windows)

context-mode version

1.0.103 (latest)

Debug script output

N/A — bug is in core executor, not hooks or plugins. Verified via direct code inspection and manual testing.

Exact prompt that triggered the bug

Any prompt that triggers ctx_execute(language: "shell", ...) on Windows, e.g.:

Run a shell command: echo "test"

Full error output

Two distinct symptoms:

  1. Silent failure — no output returned:

    ctx_execute(language: "shell", code: "echo test")
    ⎿  (no output)
    

    JavaScript execution works fine in the same environment:

    ctx_execute(language: "javascript", code: "console.log('test')")
    ⎿  test
    
  2. Git Bash window pops up on top of workspace:
    When shell execution is triggered, a Git Bash console window appears on top of the IDE/workspace because .sh files are associated with bash.exe on the system.

Steps to reproduce

  1. Run context-mode on Windows (native, not WSL)
  2. Ensure Git Bash is installed and .sh files are associated with it
  3. Trigger any ctx_execute with language: "shell"
  4. Observe: (a) no output returned, and/or (b) Git Bash window pops up

What I tried to fix it

  • Set SHELL environment variable in MCP config to C:/Git/bin/bash.exe — shell is found but execution still fails silently
  • Verified child_process.execSync works from JavaScript sandbox — confirms the shell binary is functional
  • Inspected src/executor.ts and src/runtime.ts source code

Root Cause Analysis

Three issues in the Windows shell execution path:

  1. #writeScript uses .sh extension — On Windows, .sh files with a Git Bash association trigger a visible console window when accessed.

  2. #spawn lacks windowsHide: true — Without this option, spawned console applications on Windows may create visible windows.

  3. buildCommand passes script as direct argumentbash.exe script.sh causes MSYS2 path-mangling and file-association side effects. The existing comment in #spawn even says:

    "On Windows with Git Bash, pass the script as bash -c "source /posix/path" rather than bash /path/to/script.sh."

    But the code does NOT implement this — it passes the file path directly.

Proposed Fix

See PR: three minimal changes to src/executor.ts and src/runtime.ts:

  1. Write shell scripts without extension on Windows (script instead of script.sh)
  2. Add windowsHide: true to spawn options on Windows
  3. Use bash -c "source 'filePath'" for shell commands on Windows

Operating System

Windows (PowerShell)

JS Runtime

Node.js v24.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions