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

参考

相关推荐
Augustzero1 天前
Codex Desktop 新建会话无法发送消息:一次由旧版 CLI 路径引发的故障排查
chatgpt·agent
xn71333 天前
ChatGPT 生图如何自动导入 Astro 内容站:base64 桥接、frontmatter 更新和封面校验
chatgpt
gptAI_plus3 天前
用 React + TypeScript 写一个世界杯淘汰赛对阵树组件
chatgpt·openai
AI工程效率栈8 天前
AI 帮你补异常处理时,新人最容易犯的错:把失败悄悄变成成功
gpt·chatgpt
凌奕10 天前
让你的 AI 编程助手「偷懒」:50k Star 的 Ponytail,让 Agent 少写一半代码
chatgpt·agent·claude
星落zx16 天前
Spring Boot 多模型集成:优雅调用全球主流大模型
人工智能·spring boot·chatgpt
爱读书的小胖17 天前
无偿分享ChatGPT Image 2画图网页与并发绘图python程序【Ai绘图】
开发语言·python·chatgpt
码农小旋风17 天前
Claude Code 基础用法大全:对话、分析、修改、测试、Git 和工作流
人工智能·git·chatgpt·claude
武子康17 天前
调查研究-180 roboflow/supervision:计算机视觉工程里的“胶水层“,为什么值得关注?
人工智能·opencv·计算机视觉·chatgpt·llm·向量化
果子耶耶17 天前
让大模型帮我写单元测试,5个模型的覆盖率和边界处理能力实测
chatgpt·单元测试