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:

  1. Set your default shell to zsh (e.g. via /etc/passwd or chsh -s /bin/zsh).
  2. Open Codex (v0.39.0).
  3. Run a command that depends on the shell configuration (e.g. pnpm, or a command defined in .zshrc).
  4. Observe that Codex fails to find certain commands because it uses bash instead of zsh.

---

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, here zsh),
  • or allow the shell to be used to be specified explicitly in the configuration (/status, /init or other).

---

Environment:

  • Codex v0.39.0
  • User's default shell: /bin/zsh
  • Shell used by Codex: /bin/bash

View original on GitHub ↗

9 Comments

ccw630 · 10 months ago

Same issue

d-klotz · 10 months ago

Yes, same.

I'm unable to use Codex on my Mac because of that.

alexeydubinin · 9 months ago

Switching from Claude Code to Codex CLI broke my development workflow.

souljorje · 9 months ago

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, or test.
That sandbox:

  • Launches a non-interactive /bin/bash session by default.
  • Does not source your full interactive profile (.bashrc, .zshrc, .profile), only minimal environment setup.
  • Ignores your login shell setting from macOS (chsh etc.) — it does not inherit that context.

So even if your default shell is zsh (echo $SHELL/bin/zsh), Codex runs commands under bash.

Workarounds

  1. Make .bash_profile shell-agnostic and non-interactive safe

Add this near the top:

``
[[ $- == *i* ]] || return
``

This avoids loading interactive logic when Codex runs bash in headless mode.

  1. Use zsh inside scripts (partial workaround)

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.

  1. Project-local configuration

Define environment setup in package.json scripts or .env files 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.

alexeydubinin · 9 months ago

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" />

solanab · 9 months ago

solved partially with add these in ~/.bash_profile

if [ -f ~/.zshrc ]; then
   source ~/.zshrc
fi

# alias
shopt -s expand_aliases
imajes · 8 months ago

@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 -lc for 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. :)

layeddie · 5 months ago

Codex 5.3 Workaround for now: patch ~/.codex/shell_snapshots/*.sh to auto-handoff interactive Codex shell sessions to zsh (exec zsh -l behind a CODEX_SHELL=1 guard). This removes the need to run exec zsh manually.

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.

Marcus112-CS · 4 months ago

To make it take effect, Add the text below to ~/.codex/AGENT.md

## Shell Environment
- The system is macOS.
- The default terminal shell is `zsh`, not `bash`.
- All commands and scripts must be written and executed with `zsh`.

what important is modify two files that controll nointeractive shell : ~/.bash_profile && ~/.zprofile