Repository navigation
Description
Windows: v2 shell shim uses POSIX quoting, so every git/gh command fails (sync silently no-ops)
Environment
- opencode
2.0.30(V2), Windows 11 (process.platform === 'win32') opencode-synced0.11.0
Summary
On Windows every command issued through the v2 shell shim fails. The read-only helpers swallow the error and return defaults, so opencode_sync { "command": "status" } misleadingly reports a healthy repo while sync never actually does anything.
Repro
Link a repo (opencode_sync { "command": "link", "repo": "<https URL>" }), then push:
opencode_sync { "command": "push" }
Result:
Failed to inspect existing repo origin: Command failed: git -C 'C:\Users\me\.local\share\opencode\opencode-synced\repo' remote get-url origin
fatal: cannot change to ''C:\Users\me\.local\share\opencode\opencode-synced\repo'': Invalid argument
clone fails the same way:
fatal: could not create leading directories of ''C:\...\repo'': Invalid argument
Meanwhile status prints Branch: main / Working tree: clean. Those are the catch fallbacks in getCurrentBranch / getStatusLines, not real git output.
Minimal Node repro on Windows:
const { exec } = require('node:child_process');
const dir = 'C:\\Users\\me\\.local\\share\\opencode\\opencode-synced\\repo';
exec(`git -C '${dir}' status --porcelain`, (e, so, se) => console.log(e?.message, se));
// fatal: cannot change to ''C:\Users\me\...\repo'': Invalid argumentRoot cause
dist/shell-node.js builds a command string using POSIX single-quote escaping and runs it via child_process.exec:
function shellQuote(value) {
return `'${String(value).replaceAll("'", `'\\''`)}'`;
}
...
const execution = execAsync(command, { maxBuffer: 32 * 1024 * 1024 });On Windows, exec runs the string through cmd.exe, which does not treat single quotes as quoting characters. Interpolated values (paths, URLs, branch names, commit messages) are passed literally with their quotes, e.g. git -C 'C:\...\repo' ..., which git rejects.
The code comment ("Runs via child_process.exec (/bin/sh), not bash; keep commands POSIX") is only true on POSIX.
Impact
push,pull,status,fetch,cloneand the startup sync all fail on Windows.- Because
getCurrentBranch,getStatusLines,getAheadBehind,hasRemoteBranchandhasAnyRemoteBranchescatchand return defaults ('main',[],0,false), the failures are silent andstatuslooks healthy. This makes the breakage very hard to notice.
Suggested fix
Avoid the shell entirely: build an argv array from the template literal and run it with execFile.
const shell = (strings, ...values) => {
const [command, ...args] = buildArgv(strings, values);
const execution = execFileAsync(command, args, {
maxBuffer: 32 * 1024 * 1024,
windowsHide: true,
});
execution.quiet = () => execution;
execution.text = async () => (await execution).stdout;
return execution;
};buildArgv splits static segments on whitespace and appends interpolated values atomically, so --max-count=${n} stays a single token:
function buildArgv(strings, values) {
const args = [];
let current = null;
const flush = () => {
if (current !== null) { args.push(current); current = null; }
};
strings.forEach((segment, index) => {
for (const char of segment) {
if (/\s/u.test(char)) flush();
else current = (current ?? '') + char;
}
if (index < values.length) {
current = (current ?? '') + String(values[index]);
}
});
flush();
return args;
}This is equivalent on POSIX and correct on Windows. Caveat: execFile cannot run .cmd/.bat wrappers, but the plugin only shells out to git, gh and op, all of which are .exe on Windows.
I verified the patch locally on Windows: after it, status returns real data and push succeeds.
Independent hardening (optional)
The read-only helpers that catch and return defaults make a completely broken environment look healthy. Consider propagating or at least logging the error instead of returning 'main' / [] / 0 / false.
Activity
LuisRodOnCCS commentedon Nov 1, 2026
statuscan fake plausible data, not just defaults. With an unpatched0.11.0,statusreportedLast push: <recent real timestamp>,Secrets: enabledandWorking tree: cleanwhile every git-issued command was failing. The "Last push" timestamp is apparently read from a local state file, not from git — so the health view looks legit even when the pipeline is fully dead. The proposed hardening above is not nice-to-have; it is what makes this bug human-detectable.Local patching regresses silently. The plugin cache under
~/.cache/opencode/npm/opencode-synced@latest/<timestamp>/gets re-fetched on plugin refresh and overwrote my patcheddist/shell-node.js. I only noticed whenpushstarted failing again (fatal: cannot change to ''C:\...''). A patch here must be reapplied after every install/update/cache refresh; the cache dir name is a timestamp, so "the same path is patched" cannot be assumed after an update. I keep an idempotent script that walks~/.cache/opencodeand re-copies the corrected shim over anyopencode-synced/dist/shell-node.jsit finds (happy to share).Patching the disk is not enough — the shim module is loaded once at server startup. After re-patching,
pushkept failing inside a running opencode desktop session until I fully killed the bun server process (closing the app window was not enough; the server kept the old module in memory). Worth a release note: apply fix → fully restart the opencode server.PR fix: resolve $ template argv on Windows instead of a shell string #89 approaches it the same way I had to (
execFile+ argv array +windowsHide); I can confirm the shape works in practice on opencode2.0.30+opencode-synced0.11.0: after patching,push,pull, realstatusoutput and the full session-sync pipeline all work (sessions had never once completed a push on this machine before the patch). It would be great to get it reviewed/merged and released — the npm-published code still ships the broken shim today.FYI: Windows: v2 shell shim single-quotes interpolated paths, breaking all git -C calls #95 was marked a duplicate of this one — another user hitting the same
git -C '<path>'failure mode.