Skip to content

Windows: v2 shell shim single-quotes interpolated paths, breaking all git -C calls #95

Closed as duplicate

Description

@Paesss

Summary

On Windows, the v2 Node shell shim (dist/shell-node.js) wraps every interpolated value in POSIX-style single quotes. child_process.exec runs the command string through cmd.exe, which does not treat single quotes as quoting, so the quotes are passed to the child process as part of the argument. Any command using an interpolated path fails.

In practice this breaks opencode-synced entirely on Windows: every git -C <path> call fails, so init, push, pull, and status cannot work.

Environment

  • opencode-synced version: 0.11.0
  • opencode: 2.2.5 (Windows 10.0.26300.9711, win32 x64)
  • git: 2.56.0.windows.3
  • gh: 2.103.3
  • ComSpec: C:\WINDOWS\system32\cmd.exe

Reproduction

  1. Enable the plugin: "plugins": ["opencode-synced"] in ~/.config/opencode/opencode.json.
  2. Call opencode_sync with {"command":"init"} (repo pre-created, see below).
  3. Setup reaches the git steps and fails on the quoted path.

Expected Behavior

The interpolated path is passed as a single argument, so git receives C:\path.

Actual Behavior

Failed to clone repo: Command failed: git clone 'https://github.com/<user>/my-opencode-config.git' 'C:\Users\<user>\.local\share\opencode\opencode-synced\repo'
fatal: could not create leading directories of ''C:\Users\<user>\.local\share\opencode\opencode-synced\repo'': Invalid argument
Failed to inspect existing repo origin: Command failed: git -C 'C:\Users\<user>\.local\share\opencode\opencode-synced\repo' remote get-url origin
fatal: cannot change to ''C:\Users\<user>\.local\share\opencode\opencode-synced\repo'': Invalid argument

Note the doubled single quotes in git's output — the quotes are part of the argument.

Cause

dist/shell-node.js:

import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
function shellQuote(value) {
    return `'${String(value).replaceAll("'", `'\\''`)}'`;
}
export function createNodeShell() {
    const shell = (strings, ...values) => {
        const command = strings.reduce((result, segment, index) => result + segment + (index < values.length ? shellQuote(values[index]) : ''), '');
        const execution = execAsync(command, { maxBuffer: 32 * 1024 * 1024 });
        ...

dist/v2.js:387 wires it in as $: createNodeShell(). The docstring notes it "Runs via child_process.exec (/bin/sh), not bash", but on Windows there is no /bin/sh — it is cmd.exe, where single quotes are literal characters.

Suggested Fix

Prefer passing arguments as an array via execFile/spawn so no shell quoting is needed at all:

const shell = (strings, ...values) => execFileAsync(program, args, { maxBuffer: ... });

If the template-tag API must be kept, at minimum branch on process.platform === 'win32' and use double quotes there, escaping embedded " and % (cmd expands %VAR% even inside double quotes).

Additional Context

  • This is Windows-only; on POSIX the single-quote escaping is correct.
  • Confirmed not an OpenCode issue: the v2 plugin context has no $ helper, and the plugin's own shim is what quotes. Changing OpenCode's shell setting to Git Bash changes only the shell tool and does not affect this shim.
  • Running git -C 'C:\...' manually from Git Bash succeeds, confirming the path is valid and that cmd.exe's handling of single quotes is the cause.
  • Only interpolated values are affected; literal parts of the template are not quoted. In gh repo create '<owner>'/'<name>' '--private' --confirm, --private is quoted but --confirm is not.
  • Workaround used to get past this for reporting: pre-create the repo and pre-clone it manually, but the shim still fails on the next git -C call, so there is no usable workaround.
  • Related: init also fails on gh >= 2.103.3 because gh repo create no longer accepts --confirm (reported separately in init: gh repo create fails because --confirm was removed from gh #94).

Metadata

Metadata

Assignees

No one assigned

    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