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

参考

相关推荐
王莹月2 分钟前
全店商品图风格怎么统一?生图API 用 nano banana pro 批量出同一套视觉
gpt·ai·chatgpt·ai作画·aigc·agi
AI导出鸭18 分钟前
怎么让豆包做表格?AI导出鸭苹果版将豆包输出的管道表格智能解析为二维结构,一键导出为Excel或Word标准表格。
人工智能·chatgpt·word·excel·ai导出鸭
DS随心转小程序11 小时前
ChatGPT 文字怎么转为 word?解析各类转换方案,AI 导出鸭成为高效文档转换新选择
人工智能·chatgpt·word·豆包·deepseek·ai导出鸭
啾啾Fun13 小时前
【AI原生组织】6-AI Native团队组建与基础设施搭建
人工智能·chatgpt·ai-native·ai agent·ai原生组织·人机混编
jianwuhuang8218 小时前
平板端 Gemini 表格复制转换教程|AI 导出鸭平板版一站式格式无损处理方案
人工智能·ai·chatgpt·电脑·ai导出鸭
顿哥GPT19 小时前
ChatGPT Plus / Pro 开通后的 Codex 进阶实战:从 CLI 接入、Spec 驱动到代理式编码流水线的完整指南
chatgpt
DS随心转APP19 小时前
Claude的表格怎么导到word?AI 导出鸭一键高保真还原,批量导出告别格式噩梦
人工智能·chatgpt·word·ai导出鸭
DS随心转APP19 小时前
Grok的表格怎么导到word?AI 导出鸭一键高保真还原,批量导出告别格式噩梦
人工智能·chatgpt·word·ai导出鸭
全栈弄潮儿21 小时前
新手最常见的 5 个 AI 编程误区:避免“复制粘贴就上线”
chatgpt·openai·ai编程