Skip to content

Windows: allow configuring the default session shell via config #16579

Open

Description

@LXL47

Summary

Codex currently defaults to PowerShell for the Windows session shell path. That makes it hard for users who primarily work in Git Bash or another already-supported shell to make that shell the default for Codex sessions.

I prepared a change that adds an explicit Windows config entry:

[windows]
shell_path = "C:\\Program Files\\Git\\bin\\bash.exe"

When windows.shell_path is configured, Codex uses that executable as the default session shell. When it is not configured, the current behavior remains unchanged and Windows still falls back to PowerShell.

Why this approach

I intentionally implemented this as an explicit config option rather than automatic shell detection:

  • Windows does not have a single reliable equivalent to Unix $SHELL
  • multiple bash.exe variants may exist on PATH (Git Bash, WSL, MSYS2, etc.)
  • explicit configuration is easier to reason about and avoids changing behavior for existing users

Implementation notes

The change currently does the following:

  • adds windows.shell_path to config parsing
  • supports profile.windows.shell_path overriding the top-level value
  • validates the configured executable against Codex's existing built-in shell detection/execution logic
  • uses the configured shell as the default session shell when no internal user_shell_override is provided
  • updates the Windows shell tool descriptions so they refer to the configured default shell rather than hardcoding PowerShell wording
  • updates docs and regenerates config.schema.json

This does not try to add arbitrary shell adapter support. The configured path must resolve to a shell executable already supported by Codex's built-in shell handling.

Testing performed

I ran:

  • cargo +stable test -p codex-tools
  • cargo +stable test -p codex-core config::tests::config_loads_windows_shell_path_from_toml -- --exact --nocapture
  • cargo +stable test -p codex-core config::tests::profile_windows_shell_path_overrides_top_level_value -- --exact --nocapture
  • cargo +stable test -p codex-core config::tests::invalid_windows_shell_path_fails_config_load -- --exact --nocapture
  • cargo +stable test -p codex-core shell::tests::configured_windows_shell_path_uses_bash -- --exact --nocapture
  • cargo +stable test -p codex-core shell::tests::invalid_windows_shell_path_is_rejected -- --exact --nocapture
  • cargo +stable test -p codex-core shell::tests::finds_powershell -- --exact --nocapture
  • cargo +stable test -p codex-core shell::tests::detects_powershell_as_default -- --exact --nocapture

Branch / commit

I could not open a PR directly because the repository currently limits PR creation to collaborators.

The proposed change is available here:

  • branch: LXL47/codex:feat/windows-shell-path-config
  • commit: 0d9010493

If this direction is acceptable, I can keep the branch available for maintainers to review or cherry-pick from.

Activity

  1. added
    enhancement
    CLI
    windows-os
    on Apr 2, 2026
  2. LXL47 commented on Apr 2, 2026

    @LXL47
    Author

    A few implementation details that may help with review:

    • codex-rs/config/src/types.rs

      • adds windows.shell_path to WindowsToml
    • codex-rs/core/src/config/mod.rs

      • resolves profile.windows.shell_path before the top-level windows.shell_path
      • validates the configured path on Windows during config loading
      • surfaces a config error for unsupported / unusable executables instead of silently falling back
    • codex-rs/core/src/codex.rs

      • applies the configured shell path when constructing the default session shell
      • keeps the existing internal precedence: user_shell_override still wins if one is already provided programmatically
    • codex-rs/core/src/shell.rs

      • adds a separate helper for configured shell paths instead of reusing the model-provided-path flow
      • keeps the default behavior unchanged when no config value is present
    • codex-rs/tools/src/local_tool.rs

      • updates the Windows shell tool descriptions so they refer to the configured default shell instead of PowerShell-specific wording
    • docs/config.md and codex-rs/core/config.schema.json

      • document and expose the new config entry

    A couple of scope boundaries are intentional here:

    • this does not add arbitrary shell adapter support
    • windows.shell_path must point to a shell executable already handled by Codex's built-in shell adapters
    • at the moment that means the shell types Codex already knows how to detect and execute, such as bash, sh, zsh, pwsh, powershell, and cmd
    • if windows.shell_path is unset, Windows behavior remains the same as today

    I also added targeted coverage for:

    • loading windows.shell_path from config
    • profile override behavior
    • invalid configured shell paths failing config load
    • Windows shell resolution using a configured bash.exe
    • retaining the existing PowerShell default when no config is provided
  3. added
    tool-calls
    and removed
    CLI
    on Apr 2, 2026
  4. caomengxuan666 commented on Jul 19, 2026

    @caomengxuan666

    Just dropping a +1 with a real consumer use case. I maintain winuxsh (https://github.com/unixwin/winuxsh), a Windows-native bash/zsh-like shell (rubash + winuxcmd, no MSYS/Cygwin/WSL layer). We have already verified that winuxsh -c "<cmd>" meets the agent non-interactive contract: no banner, clean stdout/stderr, exact exit code, native Windows paths and ~ resolution. We have users who would switch to Codex specifically if shell_command could route to winuxsh instead of PowerShell.

    Everything your PR proposes is exactly what we need:

    • windows.shell_path = "..." as the single config entry point
    • profile override of the top-level value
    • validation via the existing built-in shell detection logic
    • fallback to current behavior when unset

    One thing worth confirming: my winuxsh uses -c "<command>" for non-interactive mode (same as bash/zsh). Looking at codex-rs/core/src/shell.rs, derive_exec_args currently branches on ShellType and would route a custom path through the Cmd branch (/c ) if detect_shell_type falls back. Would the PR validation reject an unknown stem like winuxsh.exe, or is there room to add a bash/sh-compatible branch (i.e. -c rather than /c) when the configured path matches a known Unix-style shell?

    Happy to help test a build or contribute test cases if it helps move this forward.

  5. DanKaplanSES commented on Aug 7, 2026

    @DanKaplanSES

    I would strongly benefit from this feature, specifically with Cygwin Bash:

    [windows]
    shell_path = "C:\\cygwin64\\bin\\bash.exe"

    I launch Codex from Cygwin, but native Windows Codex still runs agent commands through PowerShell. I can instruct it to invoke Cygwin Bash for each command, but that is not an equivalent substitute for making Bash the actual session shell.

    Claude Code supports this workflow through CLAUDE_CODE_GIT_BASH_PATH, and I use it successfully with C:\cygwin64\bin\bash.exe. Commands run directly in Cygwin, so POSIX scripts, paths, tools, skills, and permission rules behave consistently.

    The PowerShell-to-Bash wrapper approach has several drawbacks:

    • It adds extra process and shell startup overhead to every short agent command.
    • It introduces a second quoting and path-translation layer, making pipes, redirects, multiline commands, heredocs, and complex arguments less reliable.
    • It makes POSIX-oriented skills and their scripts/ directories fragile, because a script may accidentally be sent directly to PowerShell.
    • It makes command approval and prefix rules less useful because PowerShell sees only a Bash-launch command, not the actual POSIX command.
    • It requires an instruction-following workaround instead of a reliable tool-level configuration.

    WSL is not a drop-in replacement for every Windows-native project. Keeping a repository on C:\... while running Linux tools can cause significant cross-filesystem I/O overhead. Moving a project into WSL can also require changes to paths, toolchains, editor and debugger setup, environment variables, services, and Windows-specific build or automation dependencies.

    Cygwin is the best fit for some of my existing Windows-native projects. Please consider accepting a Cygwin bash.exe path for windows.shell_path, provided it passes the existing Bash shell detection and execution checks.

  6. kamkie commented on Aug 30, 2026

    @kamkie

    Adding a concrete Codex Desktop use case for this configuration option.

    Environment:

    • Windows 11 Pro 10.0.26200, x64
    • Codex Desktop MSIX 26.825.6671.0
    • Agent environment: Windows native
    • Integrated terminal shell: Git Bash

    The app setting only changes the visible integrated terminal. Agent exec continues to use its independently selected shell, so the terminal and the agent can operate in materially different environments even inside the same Desktop window. There is currently no documented config.toml key that selects Git Bash as the Windows-native agent shell.

    Trying to select it per tool call is not currently a reliable substitute. I passed this exact shell path:

    C:\Program Files\Git\bin\bash.exe
    

    but the recorded command used:

    C:\Windows\System32\bash.exe
    

    The process reported Linux/WSL2, /usr/bin/bash, /usr/bin/node, and a Linux npm cache rather than Git for Windows. This is related to #40328.

    The practical impact is larger than command syntax. The integrated Git Bash terminal and Windows-native agent commands can see different PATH entries, Node installations, package caches, authentication state, and application configuration. In my case this exposed a separate MSIX AppData virtualization problem: a CLI was already authenticated in the normal Windows environment, while agent exec silently read a package-private LocalCache\Roaming configuration instead of the real %APPDATA% file. That issue is documented with GetFinalPathNameByHandle evidence in #41665.

    An explicit setting such as the proposed:

    [windows]
    shell_path = "C:\\Program Files\\Git\\bin\\bash.exe"

    would provide a deterministic Windows-native session shell and remove the current ambiguity between Agent environment and Integrated terminal shell. The Desktop UI should ideally expose the same selection separately as Agent shell, because the existing integrated-terminal setting does not affect agent execution.

  7. mynameistito commented on Sep 6, 2026

    @mynameistito

    This also came up in T3 Code: pingdotgg/t3code#10093

    Their triage confirmed that T3 does not control the shell used for Codex agent commands, so the actual shell selection/configuration needs to be supported upstream by Codex.

    In my case, Codex falls back to Windows PowerShell 5.1 because PowerShell 7 is installed via MSIX/WindowsApps and isn’t usable through the current discovery/sandbox path.

    A configurable windows.shell_path would let T3 and other Codex clients expose this cleanly.

  8. DY-168 commented on Oct 8, 2026

    @DY-168

    I use Git Bash for my projects on Windows. I can set the integrated terminal to Git Bash, but there’s no option to make Codex use it for agent commands. Those commands still run in PowerShell. I’d find the option proposed in this issue useful.

  9. day-garwood commented on Oct 11, 2026

    @day-garwood

    I have disabled powershell on my system for many reasons, one of them being due to safety concerns, and use cmd myself. I would also find this feature very useful.

  10. mynameistito commented on Oct 18, 2026

    @mynameistito

    bump any movement on this?

  11. apollion69 commented on Oct 25, 2026

    @apollion69

    Additional Windows-native performance evidence for this request.

    Environment: Windows 11 Enterprise, build 26200; Codex CLI 0.164.0-alpha.11.1; bundled PowerShell 7.6.5; Git 2.53.

    Setting Integrated terminal shell → Git Bash leaves default agent tool execution in PowerShell. I understand this is the documented independent configuration, rather than a broken terminal preference. A supported default-agent-shell selector would make the faster route available without per-call instructions.

    On 25 October 2026, a subprocess harness compared identical git --version executions: 60 measured samples per variant, three blocks of 20, randomized order, warmups excluded. Pooled median milliseconds (range of block medians):

    Execution Median Block range
    Direct Git 37.4 34.3–39.2
    PowerShell wrapper 265.8 240.0–275.5
    PowerShell -NoProfile wrapper 305.3 267.6–333.8
    Git Bash wrapper 123.0 72.1–187.3

    I also measured actual Codex tools on the same five-operation scenario: file listing, text search, line-range reading, Git status, JSON parsing. There were 15 measured runs per variant across three blocks; warmups excluded. An external wall timer covered tool execution and result delivery, excluding model time:

    Execution Calls / new shells Median ms Block-median range
    Separate PowerShell calls 5 / 5 1840 1570–2519
    One Git Bash batch 1 / 1 352 273–356
    Existing warm Node REPL 1 / 0 66 61–207

    Node used filesystem APIs for reading/parsing and three direct native child processes for two searches and Git. Outputs matched; zero measured failures. Background CPU load was 48–65%, with 1003–1017 processes. Tail latency was noisy. These results compare execution strategies, including batching and warm-runtime reuse; they do not establish whole-agent speedups or show that disabling profiles fixes startup latency.

    Please expose a supported default agent-shell path in configuration and the Windows UI, independently from the integrated terminal. A direct executable/argv path or safe process reuse would also help short tool calls avoid unnecessary shell startup.

    Minimal standard-library reproduction; executable discovery uses PATH and the installed Git directory:

    import pathlib, random, shlex, shutil, statistics, subprocess, time
    git = shutil.which("git")
    ps = shutil.which("pwsh") or shutil.which("powershell")
    assert git and ps
    bash = next((str(p / "bin/bash.exe") for p in pathlib.Path(git).parents
                 if (p / "bin/bash.exe").is_file()), None)
    assert bash, "Git Bash must be installed beside Git"
    command = "& '" + git.replace("'", "''") + "' --version; exit $LASTEXITCODE"
    cases = {
        "direct": [git, "--version"],
        "pwsh": [ps, "-Command", command],
        "pwsh_noprofile": [ps, "-NoProfile", "-Command", command],
        "bash": [bash, "-c", shlex.join([git, "--version"])],
    }
    samples = {name: [] for name in cases}
    rng = random.Random(20261025)
    expected = None
    for trial in range(-3, 60):
        order = list(cases)
        rng.shuffle(order)
        for name in order:
            started = time.perf_counter()
            result = subprocess.run(cases[name], capture_output=True, check=True,
                creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
            elapsed = (time.perf_counter() - started) * 1000
            output = result.stdout.strip()
            expected = output if expected is None else expected
            assert output == expected
            if trial >= 0:
                samples[name].append(elapsed)
    for name, values in samples.items():
        print(name, len(values), round(statistics.median(values), 1), "ms")
  12. caomengxuan666 commented on Oct 25, 2026

    @caomengxuan666

    For anyone who needs this today rather than when it lands upstream: we maintain a build of Codex where the Windows agent shell is a native bash — niubash — instead of PowerShell. It's distributed through our Windows package manager: wpm install codex (source: unixwin/codex, branch niu-first-class-shell). In that build the routing is already changed: agent commands execute through niubash, so there's no PowerShell invocation layer, and — unlike MSYS-based shells — no automatic path conversion mangling native arguments; arguments to external programs are forwarded verbatim, which removes most of the escaping friction described in this thread. Per-command shell startup in our own Windows measurements is in the tens of milliseconds, against the hundreds measured above for the PowerShell wrapper path.

    The explicit windows.shell_path proposed here would make the same routing available in stock Codex, and we'd welcome that — consider our build the proof the route works end-to-end. We're happy to share the shell-side contract tests we use. Until then, the wpm build is there if you want it now.

  13. caomengxuan666 commented on Oct 25, 2026

    @caomengxuan666

    Adding the performance evidence — and the full picture, since most of it is already in this thread.

    The wrapper tax, measured by a third party. @apollion69's same-machine measurements above (Windows 11, 60 samples per variant, randomized blocks): git --version median 37.4 ms executed directly, 123.0 ms through the Git Bash wrapper, 265.8 ms through the PowerShell wrapper. His five-operation scenario: 1,840 ms as separate PowerShell calls vs 352 ms as one Git Bash batch. An agent session issues hundreds of shell calls, so this per-call tax compounds into seconds of dead time per task — and it is structural: each route pays for a layer the command never asked for.

    What the niubash build does instead. Agent commands run in a native Windows bash — no PowerShell layer, no emulation layer. Our published same-session measurements (750 iterations per workload, interleaved, min-of-3; project-measured, full series on the product page) have niubash ahead of Git Bash on all eight workloads measured; cold -c start is 26.3 ms vs Git Bash's 71 ms, and the prompt's git segment is read straight from .git/HEAD (≤29 ms) instead of spawning git per prompt (113–362 ms). Installed size: ~16 MB, zero DLLs — vs ~440 MB plus the 20 MB msys-2.0.dll.

    It is a whole native stack, not a shell shim. The engine is rubash — a from-scratch Rust implementation targeting GNU bash 5.3 semantics. The commands are WinuxCmd: 176 Unix commands / 1,924 options as native Windows builds, not MSYS ports. Git is niu-git, a native git distribution. Themes and plugins come from oh-my-niu, and wpm is the package manager that ships the Codex build. An agent skill package (niu skill install) ships in every release.

    Compatibility is measured, not asserted. GNU bash 5.3 is the spec — including 5.3-only forms like ${ cmd; } nofork substitution. We run a 246-case differential suite byte-for-byte against a pinned GNU bash 5.3.20 (244/246; the two residuals are documented platform differences) and measure against GNU's own 83-suite corpus. Real ecosystem workloads are pinned as regression fixtures: nvm.sh loads byte-clean, oh-my-bash's 252/252 function environments come out identical, the 29,601-line ble.sh parses clean, git's own test-lib.sh runs end-to-end. Every divergence found becomes a public issue and a regression test. The heavy workloads were closed one by one — the parse gap on nvm.sh-class scripts went from 720× to 8× against GNU.

    Paths and native programs — the part that matters most for agents. Every predecessor makes paths the compulsory question: Git Bash rewrites arguments heuristically before spawn (the MSYS conversion layer); WSL forces the /mnt/c dialect. niubash's answer is a third one: arguments reach native Windows programs byte-for-byte verbatim — there is no argv-conversion layer inside child processes, and quoted arguments are never rewritten. Path translation is the engine's own table-driven job, and it accepts every dialect an agent might write: native Windows C:\…, POSIX /c/…, WSL /mnt/c/…. Whatever dialect the agent writes, it executes — the shell adapts to the agent, not the other way round. Console devices behave as in GNU bash too: echo >/dev/tty, exec 3<>/dev/tty and test -e /dev/tty all work, where the MSYS layer returns Invalid argument.

    Get it. niubash: winget install --id Unixwin.Niubash --source winget (the 1.4.4 update is currently in the winget pipeline; the latest builds are on the site and GitHub releases). The Codex build with niubash as its agent shell: wpm install codex.

    Git Bash was the carriage that carried everyone before anything native existed. On Windows, there is a native option now.

  14. crazy-vedic commented on Nov 3, 2026

    @crazy-vedic

    @codex
    We need this, if you need more reactions let me know, I'll have my office (100+) upvote this thread,

  15. IndexEeve commented on Nov 21, 2026

    @IndexEeve

    +1 — verified today that this is still the state, and that there is still no workaround for agent command execution.

    Codex Desktop 26.1117.3838.0 / bundled codex-cli 0.171.0-alpha.13, Windows 11 x64:

    • With Git Bash installed and bash resolvable on PATH, codex debug prompt-input ping still injects <shell>powershell</shell> into <environment_context>. The model reads that and defaults to PowerShell even for tasks with nothing Windows-specific in them (observed reasoning: "PowerShell environment. … Get-ChildItem -File -Filter *.md | Sort-Object Length -Descending").

    • None of the obvious keys exist yet — all four report "unrecognized configuration setting / is ignored":

      codex doctor -c 'shell="bash"'          -> `shell` is ignored
      codex doctor -c 'default_shell="bash"'  -> `default_shell` is ignored
      codex doctor -c 'windows.shell="bash"'  -> `windows.shell` is ignored
      codex doctor -c 'shell.default="bash"'  -> `shell` is ignored
      
    • The desktop [desktop] integratedTerminalShell setting (enum(["powershell","commandPrompt","gitBash","wsl"])) is labelled "Preferred integrated terminal shell" and has no effect on exec_command.

    Root cause is unchanged: default_user_shell_from_path() does if cfg!(windows) { get_shell(ShellType::PowerShell).unwrap_or_else(ultimate_fallback_shell) }, so the user's shell preference is never consulted on Windows, unlike the Unix branch which uses the passwd shell.

    The [windows] shell_path proposal in this issue looks like exactly the missing piece; happy to test a build if it lands.

  16. nadh0623-thompson commented on Nov 24, 2026

    @nadh0623-thompson

    A clarification on the distinction raised above between the integrated terminal and the Windows-native agent shell: for an existing Desktop chat, is there a supported UI indicator or read-only command that identifies the agent command environment separately from the visible terminal? If a different local environment has already been approved, can the chat select it while preserving its existing sandbox policy, or is selecting the environment when starting a new local chat the supported workflow? A documentation pointer would be helpful.

  17. Misakura-R1n commented on Dec 2, 2026

    @Misakura-R1n

    I'd like to select Git for Windows Bash as the default shell for the Windows-native agent in Codex Desktop. I want to keep using Windows executables and paths. The integrated-terminal preference lets me choose Git Bash for interactive tabs, but agent commands still default to PowerShell.

    I also tested whether supplying the absolute path per command could serve as a workaround. On Codex Desktop 26.1120.6357.0 (bundled codex-cli 0.171.0-alpha.13.2), Windows build 26300, with both Git for Windows and WSL installed, I got the following results from the same machine and working directory:

    Invocation uname -s git --version
    Agent tool call shown below Linux git version 2.43.0
    PowerShell launching & 'C:\Program Files\Git\bin\bash.exe' -c 'uname -s && git --version' MINGW64_NT-10.0-26300 git version 2.56.1.windows.1
    {
      "shell": "C:\\Program Files\\Git\\bin\\bash.exe",
      "login": false,
      "cmd": "uname -s && git --version"
    }

    Both commands exited successfully, but they used different Git installations. This also reproduces the behavior described in #60793 on the Desktop version above.

    A concrete acceptance test for this feature would be to select the Git for Windows executable as the native agent shell, open a new chat, and run uname -s && git --version without a per-call shell override. With WSL also installed, the result should match invoking the selected executable directly.

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

    enhancementtool-callswindows-os

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions