
If you're shipping scripts or automation that needs to run across PowerShell, Git Bash, and cmd on Windows, this gives you the detection logic and compatibility patterns to stop guessing. It covers the priority order for shell detection (PSModulePath first, then MSYSTEM), the path conversion gotchas in Git Bash that silently break things, and how to call PowerShell from bash and vice versa. The real value is in the specifics: when MSYS_NO_PATHCONV matters, why environment variable syntax breaks cross-shell, and which detection method actually works reliably. Use it when you're tired of scripts that work in your shell but fail in CI or on a teammate's machine.
$ npx -y skills add josiahsiegel/claude-plugin-marketplace --skill powershell-shell-detection --agent claude-codeInstalls into .claude/skills of the current project.
Critical guidance for distinguishing between PowerShell and Git Bash/MSYS2 shells on Windows, with shell-specific path handling and compatibility notes.
When working on Windows, correctly identifying the shell environment is crucial for proper path handling and command execution.
PSModulePath (Most Reliable):
# PowerShell detection
if ($env:PSModulePath) {
Write-Host "Running in PowerShell"
# PSModulePath contains 3+ paths separated by semicolons
$env:PSModulePath -split ';'
}
# Check PowerShell version
$PSVersionTable.PSVersion
# Output: 7.5.4 (PowerShell 7) or 5.1.x (Windows PowerShell)
[Environment]::GetEnvironmentVariable("PATH", "Machine") # System PATH
Sponsors