Windows Codex 与手机端远程控制互联完整方案

Windows Codex 与手机端远程控制互联完整方案

更新时间:2026-05-22

适用环境:Windows 版 Codex Desktop + ChatGPT 手机端 Codex

验证机器:LAPTOP-V6DKT0K9

背景

Codex 的移动端远程控制能力在 Windows 上仍属于实验/隐藏路径。仅在 config.toml 中写入:

toml 复制代码
[features]
remote_connections = true
remote_control = true

并不一定足够。实测 Windows Codex Desktop 启动时会尝试删除 remote_control = true,即使通过只读锁保住了配置,桌面端 app-server 的远程控制状态仍可能停在 disabled,导致手机端发起请求时桌面端毫无反应。

最终跑通的关键是两层:

  1. 用启动脚本保护 config.toml,避免 Codex 启动时删除 remote_control = true
  2. 额外启动一个后台 app-server 保活进程,主动调用 remoteControl/enable,让远程控制状态从 disabled 进入 connected

最终文件清单

已创建或更新以下文件:

text 复制代码
%USERPROFILE%\.codex\config.toml
%USERPROFILE%\.codex\codex-remote.ps1
%USERPROFILE%\.codex\codex-remote-control-server.ps1
%USERPROFILE%\.codex\codex-remote-control-server.js
%USERPROFILE%\.codex\logs\remote-control-server.log
%USERPROFILE%\.codex\backups\config.*.backup.toml

所有触碰过的文本文件均检查为 UTF-8 无 BOM。

配置要求

%USERPROFILE%\.codex\config.toml[features] 下必须包含:

toml 复制代码
[features]
remote_connections = true
remote_control = true

可以用下面命令检查:

powershell 复制代码
$config = "$env:USERPROFILE\.codex\config.toml"
$content = [System.IO.File]::ReadAllText($config, [System.Text.UTF8Encoding]::new($false))
$content -match '(?m)^\s*remote_connections\s*=\s*true\s*$'
$content -match '(?m)^\s*remote_control\s*=\s*true\s*$'

两个结果都应为 True

启动脚本

主启动脚本:

text 复制代码
%USERPROFILE%\.codex\codex-remote.ps1

它负责:

  • 备份 config.toml
  • 自动补齐 remote_connections = true
  • 自动补齐 remote_control = true
  • 启动 Codex 前临时把 config.toml 设为只读
  • 启动 Codex Desktop
  • 等待启动稳定
  • 自动解除只读
  • 启动后台 remote-control app-server 保活器

日常启动建议使用:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote.ps1"

如果只想启动 Codex Desktop,不启动后台远程控制保活器:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote.ps1" -NoRemoteControlServer

后台远程控制保活器

PowerShell 入口:

text 复制代码
%USERPROFILE%\.codex\codex-remote-control-server.ps1

Node.js 实现:

text 复制代码
%USERPROFILE%\.codex\codex-remote-control-server.js

它做的事情:

  1. 启动 Codex app-server:

    powershell 复制代码
    codex app-server --listen stdio:// --enable remote_control
  2. 发送初始化请求:

    json 复制代码
    {
      "id": "initialize",
      "method": "initialize",
      "params": {
        "clientInfo": {
          "name": "codex-remote-control-server",
          "version": "1.0.0"
        },
        "capabilities": {
          "experimentalApi": true
        }
      }
    }
  3. 读取当前远程控制状态:

    json 复制代码
    {
      "id": "remote-status-before-enable",
      "method": "remoteControl/status/read",
      "params": null
    }
  4. 如果状态是 disabled,主动启用:

    json 复制代码
    {
      "id": "remote-enable",
      "method": "remoteControl/enable",
      "params": null
    }
  5. 每 30 秒读取一次状态,保持日志可观察。

  6. 如果 app-server 意外退出,5 秒后自动重启。

启动、查看、停止

启动后台保活器:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Background

查看状态:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Status

停止后台保活器:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Stop

查看日志:

powershell 复制代码
Get-Content "$env:USERPROFILE\.codex\logs\remote-control-server.log" -Encoding UTF8 -Tail 50

成功标志

日志中应该能看到类似流程:

text 复制代码
[remoteControl/status/changed] status=disabled server=LAPTOP-V6DKT0K9 installation=... environment=null
[remote-enable] status=connecting server=LAPTOP-V6DKT0K9 installation=... environment=null
[remoteControl/status/changed] status=connecting server=LAPTOP-V6DKT0K9 installation=... environment=env_e_...
[remoteControl/status/changed] status=connected server=LAPTOP-V6DKT0K9 installation=... environment=env_e_...

本次实测成功状态:

text 复制代码
status=connected
server=LAPTOP-V6DKT0K9
installation=891085f7-bdca-49e0-9509-f9824bb22cf9
environment=env_e_6a0f61b2f4348332b7d0efe1b0d4b36f

看到 status=connected 后,再从 ChatGPT 手机端发起 Codex 请求即可。

为什么只改 config.toml 不够

排查中发现:

  1. 新版 Windows Codex Desktop 启动时会尝试删除 remote_control = true

    日志中有:

    text 复制代码
    Failed to remove remote_control before app-server start
    EPERM: operation not permitted, open 'C:\Users\evanpatchouli\.codex\config.toml'

    这说明启动脚本的只读锁确实挡住了删除动作。

  2. 但是即使配置被保住,远程控制状态仍可能是:

    text 复制代码
    status=disabled
  3. 手动调用 app-server 的 remoteControl/enable 后,状态会变为:

    text 复制代码
    disabled -> connecting -> connected

所以完整方案必须同时解决:

  • 配置不被删除
  • app-server 真正进入 remote control connected 状态

常见问题排查

手机端仍看不到电脑

先确认后台服务是否运行:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Status

如果没有运行,启动它:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Background

如果日志没有 status=connected,继续查看最新日志:

powershell 复制代码
Get-Content "$env:USERPROFILE\.codex\logs\remote-control-server.log" -Encoding UTF8 -Tail 100

config.toml 被改回去了

用主启动脚本启动:

powershell 复制代码
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote.ps1"

它会在启动 Codex 前:

  • 备份配置
  • 补齐配置
  • 临时只读锁定
  • 启动后解锁

出现 403 Forbidden

日志里可能出现插件目录同步的 403:

text 复制代码
remote plugin catalog request ... failed with status 403 Forbidden

本次实测中这个 403 不影响 remote-control 通道连接。只要最终出现:

text 复制代码
status=connected

即可继续测试手机端。

手机端请求仍无反应

按顺序确认:

  1. 手机 ChatGPT App 和桌面 Codex 是否登录同一个 ChatGPT 账号。
  2. ChatGPT 账号是否已开启 MFA。
  3. 手机 ChatGPT App 是否为最新版。
  4. 后台日志是否保持 status=connected
  5. 手机端是否有设备授权/连接提示。
  6. 若账号或客户端灰度未开放 Windows Remote Control,可能仍需要等待 OpenAI 官方放量。

安全注意事项

  • 不要公开 C:\Users\evanpatchouli\.codex\auth.json

  • 不要把 .codex 整目录上传到公共仓库。

  • 远程控制服务连通后,手机端可以向这台 Windows 机器派发 Codex 任务。

  • 不需要远程控制时,可以停止后台保活器:

    powershell 复制代码
    powershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Stop

参考

相关推荐
老虎海子3 小时前
从零入门 OpenAI Codex|登录、权限、终端、记忆配置全实操
人工智能·vscode·自然语言处理·chatgpt·个人开发·业界资讯
刘大猫.6 小时前
GPT-5.5才发三周,5.6已在内测!OpenAI与Anthropic补贴大战同日开打,开发者坐收渔利
人工智能·ai·chatgpt·机器人·大模型·openai·anthropic
weixin_553654487 小时前
ChatGPT好用还是Gemini好用?
人工智能·chatgpt·大模型
极客老王说Agent7 小时前
【企业级Agent】制造业生产预算智能管控系统使用教程:2026企业数智化转型全实战
人工智能·ai·chatgpt
LaughingZhu17 小时前
Product Hunt 每日热榜 | 2026-05-21
前端·人工智能·经验分享·chatgpt·html
杜子不疼.18 小时前
【C++ AI 大模型接入 SDK】 - DeepSeek 模型接入(上)
开发语言·c++·chatgpt
li-xun1 天前
WildAI、2233.ai、0011.ai 怎么选?国内使用 ChatGPT、Claude、Claude Code 的方案对比
人工智能·chatgpt
小明同学011 天前
C++后端项目:统一大模型接入 SDK(四)
服务器·开发语言·c++·计算机网络·chatgpt
企服AI产品测评局1 天前
实测2026安全培训管理新范式:如何以“视觉大模型”破解AI内容生成与跨系统自动化难题?
人工智能·安全·ai·chatgpt·自动化