fix: c3_shell uses Git Bash on Windows, not cmd.exe (v2.41.0)#25
Merged
Conversation
c3_shell._run_sync used subprocess.Popen(shell=True), which resolves to cmd.exe via COMSPEC on Windows. The rest of the environment — the native Bash tool, CLAUDE.md conventions, agent command habits — speaks POSIX via Git Bash, so bash-flavored commands (ls/grep/cat, single quotes, $VAR, /dev/null, forward-slash flags, heredocs) silently failed under cmd.exe and forced a fall back to native Bash, defeating c3_shell as a structured drop-in. _run_sync now runs commands through Git Bash (bash -c) on Windows when a Git-for-Windows bash.exe is discoverable, matching the native Bash tool. Discovery prefers Git install locations and PATH and rejects WSL/Store bash (System32/WindowsApps) whose /mnt/c path semantics would break cwd. New C3_SHELL_BASH override: 0/cmd/off forces cmd.exe; a path forces that bash. POSIX platforms unchanged (shell=True -> /bin/sh). Adds TestShellSelection (discovery, env override, WSL guard, _run_sync routing). Full test_c3_shell suite green (26 tests). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
c3_shell._run_syncusedsubprocess.Popen(shell=True), which on Windows resolves tocmd.exeviaCOMSPEC. But the rest of the environment — the native Bash tool,CLAUDE.mdconventions, and agent command habits — speaks POSIX via Git Bash. So any bash-flavored command (ls/grep/cat, single quotes,$VAR,/dev/null, forward-slash flags, heredocs) silently failed undercmd.exeand forced a fall back to native Bash — defeating the purpose ofc3_shellas a structured drop-in.Reproduced live:
echo "x"printed the quotes literally; a bashforloop returnedf was unexpected at this time; a heredoc returned<< was unexpected at this time— all classic cmd.exe behavior.Fix
_run_syncnow runs commands through Git Bash (bash -c) on Windows when a Git-for-Windowsbash.exeis discoverable, matching the native Bash tool.cmd.exeremains the fallback when no bash is found._discover_git_bash()— prefers Git install locations (ProgramW6432/ProgramFiles(x86)+ literalC:\Program Files\Git\...) and PATH, and rejects WSL/Store bash (System32/WindowsApps) whose/mnt/cpath semantics would breakcwd._select_bash()— honors a newC3_SHELL_BASHoverride:0/cmd/off/falseforcescmd.exe; an existing file path forces that bash. Discovery is cached.shell=True→/bin/sh).Verified live: the new code selected
C:\Program Files\Git\bin\bash.exe, stripped quotes, and ranls -d+/dev/nullredirect at exit 0.Tests
TestShellSelection(8 tests): non-win32 short-circuit, env-override (0+ explicit path), Git-Bash discovery, WSL/System32 rejection, and_run_syncargv routing (bash vs cmd.exe).test_c3_shellsuite green (26/26);ruff checkclean.Version
Bumps to 2.41.0 (
cli/c3.py,pyproject.toml) + CHANGELOG entry.Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code