Windows 下 Codex 配置 inherit = "core" 的环境变量丢失问题

2026-04-11 14:461阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐
问题描述:

Windows 下 Codex 配置 shell_environment_policy.inherit = “core” 参数,可能导致关键环境变量丢失,进而让外部进程启动和部分 HTTPS 请求异常。

就今天碰到的。昨天装了codex app,使用一切正常,结果到今天,同一个会话就各种出问题,表现为环境变量丢失导致的各种命令失败。此前用codex cli从没出过这个问题,于是我切换到codex cli,发现问题依旧。重启电脑后还是这样。最后codex自己定位到了这个配置参数:

[shell_environment_policy]
inherit = “core”

大概就是发现:
在 Windows 上,如果 Codex 当前会话使用 inherit = “core”,很可能会让 shell 只继承一个过度精简的环境块,导致关键系统环境变量没有进入当前进程,如下:

  • SystemRoot 为空
  • windir 为空
  • ComSpec 为空
  • PATHEXT 只剩 .CPL

这样一来,外部程序虽然看起来能找到,但真正启动时会失败,同时,部分网络请求也会出现很奇怪的 TLS/传输层错误。

我的环境大概是:

  • Windows 10
  • PowerShell 7
  • Codex CLI 0.117.0

等我把配置改掉:

[shell_environment_policy]
inherit = “all”

之后重开 Codex 会话,再测,当前进程里的关键变量就恢复正常了.

OpenAI Codex 官方仓库相关 issue:
MCP servers fail to start on Windows due to missing inherited environment variables · Issue #4180 · openai/codex · GitHub
[Windows] MCP child exits with `WinError 10106` when `SystemRoot`/`windir` are missing; Codex reports timeout — observed with Python MCP (serena) · Issue #3311 · openai/codex · GitHub
Config.toml | Updated Keys · Issue #2760 · openai/codex · GitHub

如果你也是 Windows 用户,并且 Codex 会话里出现“外部命令能找到但跑不起来”这种现象,建议优先检查一下 shell_environment_policy。

网友解答:
--【壹】--:

不知道这个问题的触发是不是跟codex app有关
毕竟之前也是这个参数,但cli从没出过这个问题,今天突然就碰上了

问题描述:

Windows 下 Codex 配置 shell_environment_policy.inherit = “core” 参数,可能导致关键环境变量丢失,进而让外部进程启动和部分 HTTPS 请求异常。

就今天碰到的。昨天装了codex app,使用一切正常,结果到今天,同一个会话就各种出问题,表现为环境变量丢失导致的各种命令失败。此前用codex cli从没出过这个问题,于是我切换到codex cli,发现问题依旧。重启电脑后还是这样。最后codex自己定位到了这个配置参数:

[shell_environment_policy]
inherit = “core”

大概就是发现:
在 Windows 上,如果 Codex 当前会话使用 inherit = “core”,很可能会让 shell 只继承一个过度精简的环境块,导致关键系统环境变量没有进入当前进程,如下:

  • SystemRoot 为空
  • windir 为空
  • ComSpec 为空
  • PATHEXT 只剩 .CPL

这样一来,外部程序虽然看起来能找到,但真正启动时会失败,同时,部分网络请求也会出现很奇怪的 TLS/传输层错误。

我的环境大概是:

  • Windows 10
  • PowerShell 7
  • Codex CLI 0.117.0

等我把配置改掉:

[shell_environment_policy]
inherit = “all”

之后重开 Codex 会话,再测,当前进程里的关键变量就恢复正常了.

OpenAI Codex 官方仓库相关 issue:
MCP servers fail to start on Windows due to missing inherited environment variables · Issue #4180 · openai/codex · GitHub
[Windows] MCP child exits with `WinError 10106` when `SystemRoot`/`windir` are missing; Codex reports timeout — observed with Python MCP (serena) · Issue #3311 · openai/codex · GitHub
Config.toml | Updated Keys · Issue #2760 · openai/codex · GitHub

如果你也是 Windows 用户,并且 Codex 会话里出现“外部命令能找到但跑不起来”这种现象,建议优先检查一下 shell_environment_policy。

网友解答:
--【壹】--:

不知道这个问题的触发是不是跟codex app有关
毕竟之前也是这个参数,但cli从没出过这个问题,今天突然就碰上了