Skip to content

Windows: run commands in cmd.exe without Git Bash, tell the agent the device's shell - #370

Open
default-cybe wants to merge 11 commits into
mainfrom
fix/windows-cmd-shell
Open

default-cybe wants to merge 11 commits into
mainfrom
fix/windows-cmd-shell

Conversation

@default-cybe

Copy link
Copy Markdown
Owner

On a Windows PC without Git for Windows the device shell is cmd.exe, and every Bash call failed with 'exec' is not recognized as an internal or external command. The hub sent its bash-only wrapper (exec 3>&2 2>&1, trap ... EXIT, eval) to every device. The model then fell back to saying it could only run Unix commands.

What changes

Hub Bash tool (packages/core/src/tools/bash.ts)

  • The tool reads the device's shell: RemoteMachine.lastInfo.shell from the daemon hello (no round trip), or LocalMachine.shell() on the hub.
  • For cmd.exe it sends wrapCmdCommand: (<command>) & call set __cc_ec=%^errorlevel%& call echo <marker>%^CD% 1>&2 & call exit %^__cc_ec%.
    • call with %^X% delays expansion, so the final folder and the command's errorlevel are read after the command runs.
    • The marker goes to stderr, where extractCwd already looks.
    • Stderr is merged into the output the same way as on the bash path.
    • The parentheses stop an if or for from taking the marker into its body.
    • Lines are joined with &, except inside a ( ) block. rem and :: lines are dropped, and a trailing & is cut.
  • Old daemons already on PCs run this line through cmd /d /s /c "..." unchanged. So the hub update alone fixes cmd devices.

Why cmd and not PowerShell: cmd is what the daemon already starts on these PCs, so no extra process is needed. It keeps argv and kill handling the same as today and works with daemons already deployed. PowerShell would need its own quoting layer, and its start-up is slower on every call.

Shell picker and process handling (packages/core/src/machine/local.ts, packages/daemon-rs/src/procs.rs, from the 2026-11-07 patch)

  • Picker on Windows:
    • Git Bash first, skipping the WSL launcher in System32 and WindowsApps.
    • Then the bash next to git.exe.
    • Then the Program Files and LocalAppData Git folders.
    • Then ComSpec or cmd.exe.
  • cmd.exe runs as /d /v:off /s /c "<line>". On the hub this uses windowsVerbatimArguments, which matches raw_arg in the daemon.
  • Kill uses taskkill /T /F, so the whole process tree ends.
  • A background shell's bash -c goes to the device shell on Windows.
  • info.shell on Windows reports the shell exec actually runs, not $SHELL.
  • A Git Bash /d/x cwd maps back to D:\x on a Windows session.

The model knows the device (session/prompt.ts): the Environment block gets one line:

  • - Shell: Windows, commands run in cmd.exe (no bash): use Windows commands (dir, type, findstr, where) or PowerShell via powershell -NoProfile -Command
  • - Shell: Windows with Git Bash: POSIX commands work; paths like D:\x work as /d/x or D:/x
  • - Shell: Linux, commands run in bash (macOS likewise)

The Bash tool's description no longer says bash -c.

Devices page: a Windows device on cmd.exe shows "Install Git for Windows for full shell support", with a link to https://git-scm.com/downloads/win.

TS daemon: conclave daemon uses LocalMachine, so it gets the same picker and argv.

Tests

  • bash.test.ts:
    • A cmd device gets the cmd wrapper, and the marker cwd and exit code are parsed.
    • The wrapper is checked for an if, a block, rem lines and a trailing &.
    • A bash device still gets the POSIX wrapper.
    • Git Bash cwd mapping.
  • local-machine.test.ts:
    • cmd argv (/d /v:off /s /c) for exec and for a background bash -c.
    • The picker skips the WSL launcher.
  • project.test.ts: the Environment text for win32+cmd, win32+Git Bash and linux.
  • procs.rs: is_cmd_matches_cmd_exe_only, windows_bash_skips_wsl_and_finds_git_bash. cargo is not on the hub, so CI compiles and runs these.
  • platform-card.test.ts: the coder prompt budget goes up by 50 for the new line (+37 measured).

Reviewed by gpt-5.5 (read-only). Fixed from that review:

  • if/for swallowed the wrapper.
  • Bun's Windows argv quoting broke inner quotes.
  • Multi-line joins broke on rem, blocks and a trailing &.
  • Added /v:off.

Left as is: the blocking taskkill call, which runs only on timeout or abort.

…gent the shell

The hub's Bash tool sent its bash wrapper (exec, trap, eval) to every
device, so a Windows PC without Git Bash failed every command with
"'exec' is not recognized". A cmd.exe device now gets a cmd wrapper that
reports the final folder and keeps the exit code. Windows picks Git Bash
over the WSL launcher, kills with taskkill /T, and reports the shell exec
uses. The Environment block names the OS and shell, and Devices suggests
Git for Windows on a cmd-only PC.

Committed-by: Conclave (cliproxy/claude-opus-5-5)
Committed-by: Conclave (cliproxy/claude-opus-5-5)
…e verbatim

Review fixes: the command goes in parentheses so an if or for cannot take
the marker into its body; lines join without & inside a ( ) block, rem and
:: lines are dropped, and a trailing & is cut. cmd runs with /v:off, and on
Windows the hub passes its line in quotes with windowsVerbatimArguments, as
raw_arg does in the daemon, so Bun's own quoting cannot break inner quotes.

Committed-by: Conclave (cliproxy/claude-opus-5-5)
Comment thread packages/core/src/tools/bash.ts Fixed
Committed-by: Conclave (cliproxy/claude-opus-5-5)
Preserve the merged Windows shell discovery, cwd validation and daemon
reconnect fixes. Execute foreground cmd commands as temporary UTF-8 batch
scripts instead of reparsing user syntax inside an inline parenthesis block.
Keep native cmd quoting, exit status, process-tree cancellation and truthful
shell information. Judge Windows commands with conservative shell-aware
permissions, including custom commands, workflows and verification.

Run real cmd and Rust process tests in Windows pull-request CI, covering
spaces, percent variables, parentheses, Unicode, multiline blocks, cwd,
exit codes, npm-style shims, timeouts and background shells.

Committed-by: Conclave (cliproxy/gpt-6.1-sol)
Committed-by: Conclave (cliproxy/gpt-6.1-sol)
Run chcp 65001 >nul in the outer cmd.exe /d /v:off /s /c command line
before invoking "%__CONCLAVE_SCRIPT%". Running chcp inside the .cmd file
after cmd.exe had already opened it in the default codepage misread
Unicode paths and shifted batch file byte offsets across :__conclave_run.

Committed-by: Conclave (cliproxy/gpt-6.1-sol)
…file

Move the batch epilogue (exit code capture, stderr cwd marker, and exit)
out of the temporary .cmd file and into the outer cmd.exe /d /v:off /s /c
command line after `call "%__CONCLAVE_SCRIPT%"`. When a command invoked
another .cmd shim without CALL, cmd.exe transferred batch execution to
the shim and returned to the top-level `call`, skipping any statements
after `call :__conclave_run` inside the outer .cmd file.

Committed-by: Conclave (cliproxy/gpt-6.1-sol)
…ing on Windows

In command-line mode (`cmd.exe /c`), `%%errorlevel%%` is not de-doubled by
`call`, so `call exit /b %%__conclave_exit%%` always evaluated to 0; use
`%^errorlevel%` and `%^__conclave_exit%` so the caret prevents first-pass
expansion and `call` expands the real exit code after the script finishes.
Also avoid `detached: true` on win32 so child processes inherit stdout/stderr
pipes instead of a detached console, and include `chcp 65001 >nul` inside the
batch script as well.

Committed-by: Conclave (cliproxy/backup-gemini/gemini-4-argon-high)
A caret inside set "..." quotes is literal, so %^errorlevel% never turned
into %errorlevel% and every command reported exit code 0. Use the unquoted
call set form, with no space before &, so call expands the real errorlevel.

Committed-by: Conclave (cliproxy/personal-claude/claude-opus-5-5)
…er lookup

The runner's parallel batch, extension gate (project gate) and audit still
read a Bash command as bash, so on a cmd.exe device `echo hi #& del x` ran as
read-only: unaudited, ungated and in parallel. callReadOnly judges it in the
shell it runs in, as checkPermission already does.

cmd.exe runs a program from the current folder before PATH, so a repo's
git.bat ran under an allow rule for git. Set NoDefaultCurrentDirectoryInExePath
for cmd in the hub's exec and spawn and in the daemon's.

Committed-by: Conclave (cliproxy/personal-claude/claude-opus-5-5)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants