Codex does not respect the user's default terminal (launches bash instead of zsh)
Open 💬 9 comments Opened Sep 19, 2025 by roukmoute
What version of Codex is running?
v0.39.0
Which model were you using?
gpt-5 medium
What platform is your computer?
Linux 6.12.38+deb12-amd64 x86_64 unknown
What steps can reproduce the bug?
Codex launches system commands in a default shell that appears to be bash, even if the user is using another shell such as zsh.
This is problematic because my working environment (PATH, aliases, etc.) is configured in zsh, and some commands fail or cannot be found when Codex runs through bash.
---
Steps to reproduce:
- Set your default shell to
zsh(e.g. via/etc/passwdorchsh -s /bin/zsh). - Open Codex (v0.39.0).
- Run a command that depends on the shell configuration (e.g.
pnpm, or a command defined in.zshrc). - Observe that Codex fails to find certain commands because it uses
bashinstead ofzsh.
---
Concrete example:
In my case, when running:
Run tests
Codex executes:
• Ran pnpm nx run backend logs
└ bash: ligne 1: pnpm : commande introuvable
---
Expected behaviour:
Codex should:
- run commands in the user's default shell (e.g. the one configured in
/etc/passwd, herezsh), - or allow the shell to be used to be specified explicitly in the configuration (
/status,/initor other).
---
Environment:
- Codex v0.39.0
- User's default shell:
/bin/zsh - Shell used by Codex:
/bin/bash
9 Comments
Same issue
Yes, same.
I'm unable to use Codex on my Mac because of that.
Switching from Claude Code to Codex CLI broke my development workflow.
Here are ChatGPT thoughts on this matter
Role: Dev Environment Expert
Direct answer
No — Codex CLI cannot currently be told to use zsh instead of bash. It always runs commands (like
pnpm run lint) in a non-interactive Bash sandbox.Explanation
Codex CLI uses a sandboxed shell environment when executing tasks such as
run,lint, ortest.That sandbox:
/bin/bashsession by default..bashrc,.zshrc,.profile), only minimal environment setup.chshetc.) — it does not inherit that context.So even if your default shell is zsh (
echo $SHELL→/bin/zsh), Codex runs commands under bash.Workarounds
.bash_profileshell-agnostic and non-interactive safeAdd this near the top:
``
``[[ $- == *i* ]] || return
This avoids loading interactive logic when Codex runs bash in headless mode.
If you need zsh-specific behavior for a particular command:
``
``codex run "zsh -c 'your zsh command here'"
This spawns zsh manually inside bash, but is slower and not ideal for global setup.
Define environment setup in
package.jsonscripts or.envfiles instead of relying on your shell profile — Codex will pick those up consistently.---
Summary: Codex CLI always executes in a Bash sandbox, not zsh. You can’t switch the default shell, but you can make your setup compatible or explicitly call zsh when needed.
Solved partially with AGENTS.md instructions like "ALWAYS use zsh..."
<img width="139" height="95" alt="Image" src="https://github.com/user-attachments/assets/cf6c709e-8c24-44c7-9a3d-f47e39a57ace" />
solved partially with add these in
~/.bash_profile@etraut-openai sorry for pinging you, but i figure rather than opening a new issue, i was hoping to add to this one.
I'm also seeing a massive focus on using
bash -lc, even though there still maybe seems to be ways to specify the shell a user wants to use (use_profile/experimental_use_profile)?There are a number of references in code that (i think) seem to be biasing to bash, and not using the user shell: https://github.com/openai/codex/blob/main/codex-rs/core/src/tools/spec.rs#L315 is one such, there are definitely others.
Looking at the code, there's definitely suggestion that y'all are keen to support a user's own shell [as long as it's bash/zsh], but the code isn't consistent on that.
This is important, as any time a command is run under
bash -lcfor me, it'll not pick up some of the important settings (env) i need it to, and therefore fail.I'd be really appreciative if you could help get a definitive answer here please. :)
Codex 5.3 Workaround for now: patch
~/.codex/shell_snapshots/*.shto auto-handoff interactive Codex shell sessions to zsh (exec zsh -lbehind aCODEX_SHELL=1guard). This removes the need to runexec zshmanually.Caveat: this is not durable—Codex can regenerate/replace snapshot files on updates (or internal shell init changes), so the patch may need reapplying.
Request: add a first-class terminal shell setting or honor user login shell by default.
To make it take effect, Add the text below to ~/.codex/AGENT.md
what important is modify two files that controll nointeractive shell :
~/.bash_profile&&~/.zprofile