Description
What issue are you seeing?
Codex local command execution can silently use different environment sources for visually similar TUI launches.
A plain codex session may reuse an implicit local app-server daemon. Adding any -c override prevents that reuse and starts a different execution topology. This means command env can differ even when cwd and the visible UI look equivalent.
This is surprising and operationally risky because the UI presents both sessions as local command execution in the same directory, but env-sensitive commands may behave differently.
What steps can reproduce the bug?
First, make sure an implicit local app-server daemon already exists. In my case, this was a long-lived daemon started earlier by normal Codex use. The important precondition is that plain codex can reuse an existing local app-server daemon.
Then, in a shell:
mkdir -p /tmp/codex-env-repro
cd /tmp/codex-env-repro
export CODEX_ENV_REPRO=present
printenv CODEX_ENV_REPROControl output:
present
Start Codex normally:
codexInside Codex:
pwd
printenv CODEX_ENV_REPROObserved:
/private/tmp/codex-env-repro
# no output
Now exit and start Codex with a config override:
codex -c shell_environment_policy.inherit=allInside Codex:
pwd
printenv CODEX_ENV_REPROObserved:
/tmp/codex-env-repro
present
What is the expected behavior?
Either:
- both local TUI launches use the same command-env provenance, or
- Codex clearly exposes when command env comes from a reused app-server daemon instead of the launching terminal process.
The important part is not this specific variable. The issue is that adding a -c override changes process topology and therefore command env, while the UI still presents both as local execution in the selected cwd.
Additional information
shell_environment_policy.inherit = "all" appears to be valid and already defaults to all, so the override value itself is probably not the fix. The relevant behavior appears to be that non-empty CLI overrides prevent implicit local app-server daemon reuse.
Activity
github-actions commentedon May 26, 2026
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
dpritchett commentedon May 26, 2026
I reviewed the two suggested duplicates. I think they are related but not duplicates.
This issue is narrower in one way and more general in another: it is about local
codex app-server --listen unix://command execution having no explicit contract for the env source relative to the command cwd.The failure mode here is:
That can affect Python venvs and worktree setup flows, but it also affects kube/cloud/toolchain workflows where the cwd determines the runtime environment. A diagnostic-only fix would already help: expose whether a command used app-server inherited env, client-provided env, or a cwd-derived env provider, and warn when cwd/env contexts diverge.
dpritchett commentedon May 26, 2026
I narrowed this down after filing. The original real-world failure involved a repo-local environment, but that detail is incidental and made the report noisier than necessary.
The smaller issue is the one now in the body: visually similar local TUI launches can use different command-env provenance because a
-coverride prevents implicit local app-server daemon reuse. So the confusing part is not a specific shell, env provider, or toolchain. It is thatcwdstays visible and local-looking while the env source can silently switch between daemon-derived and launch-process-derived.dpritchett commentedon May 26, 2026
Relevant code context from a local source read at
cd934c8bcb1ba50791a980db1d0b38cef7cf84f9:can_reuse_implicit_local_daemon(...)intentionally refuses daemon reuse when CLI/config-loader launch state cannot be adopted by the daemon. In particular, daemon reuse requirescli_kv_overrides.is_empty().create_env(...)constructs command env fromstd::env::vars()in the process doing execution.That explains the observed behavior: a no-op-looking
-coverride changes whether the TUI reuses an existing daemon, and command env is then derived from a different process. I did not find an obvious user-visible contract or diagnostic that tells the user when local command execution is using daemon-derived env rather than launch-process-derived env.dpritchett commentedon May 26, 2026
Based on a deeper read of the code in the previous comment, this looks related to #17216 and #23538.
xsjk commentedon Jun 1, 2026
I confirmed this on Linux with
codex-cli 0.135.0.Minimal repro:
This confirms the reported behavior: plain TUI reuses the existing app-server
environment, while any
-coverride switches to the launcher environment.xsjk commentedon Jun 1, 2026
I think the core question is the mental model Codex wants for local app-server reuse.
Possible design philosophies
The app-server is the real session owner.
Users are expected to understand that a new
codexmay attach to an existing daemon and inherit its context. This is the current behavior.The newly opened client owns the conversation env.
App-server reuse is an implementation detail, and shell/exec behavior follows the launching terminal. This would mean storing env in
SessionConfigurationand updating its call sites.The newly opened client owns the whole conversation context.
Same as (2), but proxy/CA env such as
https_proxyalso affects LLM requests. This would also need client-specific transport context.(This is how I found this issue, after wondering why
https_proxy=... codexstill could not connect. 🙃)All three assume local app-server reuse stays the default. My preference is the fourth option, that app-server reuse should be explicit rather than implicit.
xsjk commentedon Jun 2, 2026
I took a look at the two PRs you mentioned.
#17216: under remote execution, should command env come from Core/the orchestrator or from the executor?
#23538: under local app-server reuse, should session cwd come from the client invocation or the daemon process?
#24638: under local app-server reuse, should shell env come from the client invocation or the daemon process?
xsjk commentedon Jun 2, 2026
After checking the docs further, I think only option (2) matches the semantics of
shell_environment_policy.inheritandinherit = "all"is default.https://developers.openai.com/codex/config-advanced#shell-environment-policy
https://developers.openai.com/codex/config-sample
Could the maintainers confirm whether this is intended?
ardasevinc commentedon Aug 31, 2026
can reproduce on cli v0.151.0
herdr codex integration doesn't work. this issue was opened on May 26.
did really no openai devs read this?
takeaship commentedon Sep 6, 2026
Confirmed on Ubuntu with Codex CLI 0.153.2; also reproduced in an isolated test with 0.153.4.
We found that Codex Desktop's SSH remote-host connection and local Herdr-launched Codex TUIs were using the same app-server. The TUIs had the correct
HERDR_*variables, but the app-server did not. The server remained running after Desktop disconnected. After checking that its threads were idle, stopping it gracefully and restarting the affected TUI restored the Herdr variables.This matches the environment-provenance issue described above. In the isolated test, at the same cwd, plain
codexused the daemon's marker whilecodex -c shell_environment_policy.inherit=allused the launcher's marker. A local mock model response exercising the realexec_commandhandler reproduced the daemon-derived environment too. The override avoids implicit reuse; it does not recover missing variables from the daemon.tingwei-jpg commentedon Sep 25, 2026
Reproduced on Linux with Codex CLI 0.157.0, launched from a Herdr pane (shell has
HERDR_ENV=1).Plain
codex, then inside the TUI:codex -c shell_environment_policy.inherit=all, then inside the TUI:Confirms the daemon-reuse provenance issue described above — the implicitly-reused app-server daemon was started with a different (Herdr-less) environment, so every client attaching to it inherits that stale env instead of its own launching shell's. Any
-coverride avoids daemon reuse and picks up the correct launcher env.Also reported Herdr-side: herdrdev/herdr#4606 (closed as duplicate, pointing here).
jorjao81 commentedon Sep 28, 2026
Reproduced on macOS 26.3 with Codex CLI/app-server 0.158.0, from a terminal in a Git worktree. This adds a data-integrity consequence to the environment-provenance reports above.
The launching terminal had the worktree's direnv variables. Inside the Codex tool shell, the working directory was the worktree, but
DIRENV_FILE,DIRENV_DIR, and an application-specificSYNC_STATE_DIRstill pointed to a different checkout. Process inspection showedexec_commandrunning under a managed app-server daemon whose environment and originalPWDpointed to that other checkout. The tool shell was noninteractive, so its direnv hook did not update those values after Codex set the tool cwd to the worktree. No explicit--remotewas used.Concrete impact: a local sync command used the other checkout's saved baseline while accessing a shared Anki collection. Four newly created notes were present in the collection and in that other checkout's baseline, but absent from the current worktree's baseline. The next sync in the user's correctly configured terminal stopped with four
missing_sync_snapshotconflicts. A Codex dry run initially (and misleadingly) reported zero conflicts because it inherited the daemon's state directory. Comparing the two baselines and the live collection isolated the mismatch; the four source records matched the live notes exactly.Expected: tool commands in a session launched from checkout A inherit that session's environment, including cwd-scoped direnv values, or fail closed when the daemon's environment provenance belongs to checkout B. Silently combining cwd A with environment B is unsafe for stateful commands. At minimum the TUI/tool runtime should expose the actual environment provenance before commands run.
Repro shape: start/reuse the managed daemon while in checkout B, then launch plain
codexfrom a terminal in checkout A after its direnv hook has set A-specific variables; inspectPWD,DIRENV_FILE, and a harmless directory-specific marker both in the launching terminal and viaexec_command. The tool sees cwd A with B's variables.Paths, collection details, and credential-bearing environment values omitted intentionally.
Record the Codex unknown-status and shared-daemon findings
astral303 commentedon Oct 10, 2026
This makes separate environments for projects completely impractical. I cannot use the app-server for that reason.
It's been turned on by default in 0.157.0 -- I've been lucky to avoid it because I passed in --search to my Codex TUI arguments. However, I would not be surprised if it trips up a whole lot of people now.
Live probe: does a per-launch setting join the shared daemon at all?