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,导致手机端发起请求时桌面端毫无反应。
最终跑通的关键是两层:
- 用启动脚本保护
config.toml,避免 Codex 启动时删除remote_control = true。 - 额外启动一个后台 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
它做的事情:
-
启动 Codex app-server:
powershellcodex app-server --listen stdio:// --enable remote_control -
发送初始化请求:
json{ "id": "initialize", "method": "initialize", "params": { "clientInfo": { "name": "codex-remote-control-server", "version": "1.0.0" }, "capabilities": { "experimentalApi": true } } } -
读取当前远程控制状态:
json{ "id": "remote-status-before-enable", "method": "remoteControl/status/read", "params": null } -
如果状态是
disabled,主动启用:json{ "id": "remote-enable", "method": "remoteControl/enable", "params": null } -
每 30 秒读取一次状态,保持日志可观察。
-
如果 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 不够
排查中发现:
-
新版 Windows Codex Desktop 启动时会尝试删除
remote_control = true。日志中有:
textFailed to remove remote_control before app-server start EPERM: operation not permitted, open 'C:\Users\evanpatchouli\.codex\config.toml'这说明启动脚本的只读锁确实挡住了删除动作。
-
但是即使配置被保住,远程控制状态仍可能是:
textstatus=disabled -
手动调用 app-server 的
remoteControl/enable后,状态会变为:textdisabled -> 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
即可继续测试手机端。
手机端请求仍无反应
按顺序确认:
- 手机 ChatGPT App 和桌面 Codex 是否登录同一个 ChatGPT 账号。
- ChatGPT 账号是否已开启 MFA。
- 手机 ChatGPT App 是否为最新版。
- 后台日志是否保持
status=connected。 - 手机端是否有设备授权/连接提示。
- 若账号或客户端灰度未开放 Windows Remote Control,可能仍需要等待 OpenAI 官方放量。
安全注意事项
-
不要公开
C:\Users\evanpatchouli\.codex\auth.json。 -
不要把
.codex整目录上传到公共仓库。 -
远程控制服务连通后,手机端可以向这台 Windows 机器派发 Codex 任务。
-
不需要远程控制时,可以停止后台保活器:
powershellpowershell.exe -NoProfile -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote-control-server.ps1" -Stop
参考
- V2EX 讨论:www.v2ex.com/t/1213297
- OpenAI Codex ChatGPT Plan 文档:help.openai.com/en/articles...
- OpenAI ChatGPT Release Notes:help.openai.com/en/articles...