Codex runs commands via bash --login and drops per-project env
Open 💬 15 comments Opened Oct 6, 2025 by apt-get-coke
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
Version
codex-cli 0.44.0
Repro steps
- In a repo that relies on direnv (e.g.
.envrcrunsuse flake .) so project tools live under.devenv/profile/bin. cdinto that repo and launchcodex.- Ask Codex to run one of those project helpers (e.g.
ensure-python-stack) or justcodex -- /bin/echo "/home/julien/.nix-profile/bin:/home/julien/.local/bin:/home/julien/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games".
Expected
Codex keeps the direnv-injected PATH (worked in 0.42.0); project binaries stay visible.
Actual
0.44.0 now spawns every command with bash --login -c … (see PR #4612). The login shell starts in /home/julien, the PATH is rebuilt without .devenv/profile/bin, and project helpers hit "command not found". To work around it I have to wrap every command in direnv exec . …, which re-runs the heavy enter-shell hook and makes Codex painfully slow. tmux titles flip to "home" for the same reason.
Could you drop the login shell (or add a config flag to keep the inherited environment)? This change effectively breaks Codex for direnv/devenv workflows.
15 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Related #4667
@apt-get-coke Can you confirm this worked in 0.42.0?
I have, for example:
Yes, it still works for us on 0.42.0. Example:
$ codex --version
codex version 0.42.0
$ pwd
/path/to/project
$ codex
codex> which foo
/path/to/project/.direnv/bin/foo
codex> exit
That project’s .envrc runs direnv/devenv so the toolchain ends up in .direnv/bin. With codex 0.44.0 the executable launches the
shell with --login, the working directory resets to $HOME, .envrc never runs, and the PATH entry disappears:
$ codex --version
codex version 0.44.0
$ codex
codex> pwd
$HOME
codex> which foo
which: no foo in ...
If we cd back into the project after codex starts and run direnv reload, the PATH comes back. The regression appears tied to the
new --login behavior wiping out the inherited cwd/direnv environment.
Nope—#4667 is a feature request about letting codex run commands with a user-supplied PATH so it can see toolchains inside a
sandbox. Our issue is a regression in 0.44: codex now launches the shell with --login, which resets the working directory to
$HOME, so .envrc doesn’t run and our existing PATH entries aren’t retained. Different problem, unfortunately. :)
Does anyone has a way of working around this issue? We face the same issue and would be helpful to be able to use codex with devenv
We hit the same problem and never found a reliable fix, so we dropped per-project nix/devenv. Each Python repo now ships with " + " for reproducible envs without Codex choking on nix build steps. We still keep nix at the user level for shared dev tools, but project envs are fully uv-driven. It’s been better for us because syncs/locks much faster than nix, Codex Cloud can run immediately, and our CI runners spend less time rebuilding derivations, so overall there’s less friction while we keep the reproducibility we cared about.
If you provide an mcp server that exposes the commands you need, you can
use:
cat .codex/config.toml
Similar flake commands can be run, but, this obviously isn't great on dynamic languages that assume fast and frequent edit - run loops ; so your uv mcp will need to manage the subprocess lifetime efficiently.
Well I ended up adding the following to
~/.codex/config.tomlisand then running codex with
codex --sandbox danger-full-accessThis results in our devenv and .env loaded via direnv working
@guidomb It doesn't work for me on macos
My only workaround is to set manually the must have variables I need:
@etiennecrb Mmm interesting I also run on macOS.
might be related with my particular env, this is my
.envrcI was hoping to see resolution on this but still no bueno.
Let me try what @guidomb suggested above and see if this resolves my current issue which is documented below:
<details>
<summary>terminal text scrape</summary>
</details>
<details>
<summary>Terminal screenshot</summary>
<img width="400" height="511" alt="Image" src="https://github.com/user-attachments/assets/87717b2d-1511-4421-9867-05d313bff48a" />
</details>
Note that both the shell being started being login shell and being interactive is an issue...
Hmm, it seems this was introduced in https://github.com/openai/codex/pull/1725 - @pakrym-oai could you please take a look? Why is Codex behaving differently from other CLIs in this regard? Would it make sense to have this configurable?
any updates?