Skip to content

PowerShell: a --cmd value containing quotes is truncated and every flag after it is silently dropped (follow-up to #154) #247

Closed

Description

@mkh63d

Follow-up to #154. That issue kept cmd.exe's operators out of the argument path by adding wmux.ps1, and that part works. But a value containing double quotes is still corrupted on the way to the CLI — through wmux.ps1 as well as wmux.cmd — and the CLI then silently drops every flag that follows it.

Seen on wmux 2.13.0, Windows PowerShell 5.1.26100.9444.

Repro

Three spawns that differ only in the --cmd value. --label and --workspace are identical and valid in all three:

wmux agent spawn --cmd 'hostname'                                      --label A --workspace <ws>
wmux agent spawn --cmd 'powershell -NoProfile -Command Start-Sleep'    --label B --workspace <ws>
wmux agent spawn --cmd 'powershell -NoProfile -Command "Start-Sleep 30"' --label C --workspace <ws>

Read back with wmux agent list:

case cmd intact --label honoured --workspace honoured
A — no spaces yes yes yes
B — spaces, no quotes yes yes yes
C — embedded quotes no no no

Case C records cmd as powershell -NoProfile -Command Start-Sleep — the 30 and both quotes are gone, so the agent runs a different, truncated command than the caller asked for. label comes back as powershell, i.e. the cmd.split(/\s+/)[0] default, and the agent is filed under the focused workspace as though --workspace had never been passed.

Nothing reports a problem: exit code 0, a normal {agentId, surfaceId} reply, an agent that starts and runs.

Identical through F:\wmux\resources\cli-bin-ps\wmux.ps1 (bare wmux, which is what PATH resolves first) and through cli-bin\wmux.cmd. The bash shim is unaffected — the same command from Git Bash preserves cmd, label and workspace exactly.

Cause

Two layers, and the second is the one that makes it silent.

  1. Windows PowerShell 5.1 does not escape embedded double quotes when it builds a native process's command line. @args in wmux.ps1 splats natively and so avoids cmd.exe (which is what PowerShell callers lose argument quoting through wmux.cmd: > in any free-form argument silently redirects instead of reaching the CLI #154 fixed), but it does not fix this: the value reaches node split into several argv elements with the quotes eaten. PowerShell 7.3+ has PSNativeCommandArgumentPassing for exactly this; 5.1 has nothing, so the shim has to escape the value itself.

  2. agentSpawn in src/cli/wmux.ts parses flags positionally — for (let i = 0; i < rest.length; i += 2), reading rest[i] as a flag and rest[i+1] as its value. One extra token anywhere puts every later flag on an odd index, where the loop never looks at it. There is no unknown-token check, so a dropped --workspace or --pane is indistinguishable from one that was never passed, and --label quietly falls back to a default that makes the result look plausible.

Layer 2 is worth fixing regardless of layer 1: a scanning parser (match a flag wherever it appears, error on an unrecognised token) would turn a mangled command line into a loud failure instead of a truncated command in the wrong workspace. spawn-batch and layout use the same pairwise shape.

Why it bites

--cmd is the one argument that is expected to carry a quoted inner command line, so this fires on the realistic call and not on the simple one. It also silently defeats the --workspace/--pane workaround for #246, which is how I ran into it.

It may also be the real explanation for a long-standing note in my own setup docs that "--cwd is ignored by wmux agent spawn" — --cwd is normally written after --cmd. I have not confirmed that specific case.

Activity

  1. amirlehmam commented on Sep 29, 2026

    @amirlehmam
    Owner

    Fixed in v2.14.0, both layers. wmux.ps1 now builds node's command line itself with CommandLineToArgvW quoting on PowerShell < 7.3 (or PSNativeCommandArgumentPassing = Legacy), still without cmd.exe; your case C round-trips exactly on 5.1 and pwsh 7.6. And agent spawn / spawn-batch / layout grid share a scanning flag parser that exits 1 naming the offending token (stray token, flag without a value, repeated flag) instead of silently dropping everything after it.

  2. added a commit that references this issue on Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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