Additional context
See internal Slack thread for in-depth reproduction and agent debug logs:
- Scripts can fail with
exit code 2 (error/unknown state) due to gh missing or environment mismatch
gh works in bash script only if PATH/environment and shell match (Git Bash OK, WSL fails by default)
- Release note (recent
gh version): https://github.com/github/github-app/pull/6781
- Frequent breakage in agent merge flows
- Subtle bugs around shell environment detection, bare vs. .exe invocation, path style (Windows vs. Linux), and auth context
- Not necessarily related to a single release – outstanding WSL issues
What happened?
The agent scripts or workflows invoking the gh CLI (gh binary) fail in mixed shell environments, such as when using WSL bash (bash.exe) versus Git Bash. Key factors identified:
- If called from a WSL bash, only a Windows
gh.exe is present. Bare gh fails with 'command not found'.
- Script expects to run in Git Bash (where
gh resolves to the Windows CLI and handles C:/ paths).
- Bare
bash is WSL (C:\WINDOWS\system32\bash.exe), not Git Bash; script relies on the wrong shell in some paths.
- Environment/path confusion causes
gh calls to fail (exit code 2, error/unknown state); review steps show: authentication state confusion, bash environment varying, incorrect PATH resolution, and some C:/... paths passed which are not compatible outside Git Bash.
- When re-run with explicit Windows-path
gh.exe in PATH and under Git Bash, the script works.
This is causing frequent prompt/agent failures and merge failures, especially in environments with WSL and mixed shells. The errors are subtle and can depend on path handling and shell invocation details.
Expected behavior
gh CLI invocations in shell scripts should work regardless of whether the script is running inside WSL, Git Bash, or Windows bash as long as the CLI is on PATH, and paths and environment are resolved consistently. Ideally, detecting the host shell and adjusting the command/path is enough to avoid all failures.
Installation context
Reproducible in Windows environments running WSL, bash and Git Bash.
Steps to reproduce
- On a Windows machine with both Git Bash and WSL installed, in WSL bash, run a workflow or script that internally executes bare
gh CLI commands and expects GitHub auth.
- Note that 'gh' is not found, or certain path arguments (e.g.,
--state-dir with C:/... values) do not resolve as in Git Bash.
- Review that invoking
gh.exe directly via full path, or running the script under Git Bash, succeeds (with working interop and auth).
- Observe that when run as default, the script fails before
gh can print the authorization line.
Short summary
Shell environment causes failures invoking gh CLI in scripts involving WSL and Git Bash
Affected version or release
Latest (as of the gh 2.69.0 release, see https://github.com/github/github-app/pull/6781)
View original Slack conversation
Additional context
See internal Slack thread for in-depth reproduction and agent debug logs:
exit code 2 (error/unknown state)due toghmissing or environment mismatchghworks in bash script only if PATH/environment and shell match (Git Bash OK, WSL fails by default)ghversion): https://github.com/github/github-app/pull/6781What happened?
The agent scripts or workflows invoking the
ghCLI (ghbinary) fail in mixed shell environments, such as when using WSL bash (bash.exe) versus Git Bash. Key factors identified:gh.exeis present. Bareghfails with 'command not found'.ghresolves to the Windows CLI and handlesC:/paths).bashis WSL (C:\WINDOWS\system32\bash.exe), not Git Bash; script relies on the wrong shell in some paths.ghcalls to fail (exit code 2, error/unknown state); review steps show: authentication state confusion, bash environment varying, incorrect PATH resolution, and someC:/...paths passed which are not compatible outside Git Bash.gh.exein PATH and under Git Bash, the script works.This is causing frequent prompt/agent failures and merge failures, especially in environments with WSL and mixed shells. The errors are subtle and can depend on path handling and shell invocation details.
Expected behavior
ghCLI invocations in shell scripts should work regardless of whether the script is running inside WSL, Git Bash, or Windows bash as long as the CLI is on PATH, and paths and environment are resolved consistently. Ideally, detecting the host shell and adjusting the command/path is enough to avoid all failures.Installation context
Reproducible in Windows environments running WSL, bash and Git Bash.
Steps to reproduce
ghCLI commands and expects GitHub auth.--state-dirwithC:/...values) do not resolve as in Git Bash.gh.exedirectly via full path, or running the script under Git Bash, succeeds (with working interop and auth).ghcan print the authorization line.Short summary
Shell environment causes failures invoking
ghCLI in scripts involving WSL and Git BashAffected version or release
Latest (as of the
gh2.69.0 release, see https://github.com/github/github-app/pull/6781)View original Slack conversation