scf2024
V2EX  ›  Codex

Windows 版 Codex 也能手机远程控制了,完整开启教程来了

  •  
  •   scf2024 · 3 days ago · 941 views

    这两天,我把 Windows 版 Codex 的手机远程控制功能折腾通了。

    先说结论:

    Windows 版 Codex 其实已经带了远程控制能力,只是默认没有完全放出来。

    如果你的界面里只有 SSH connections from this PC,看不到 Control this PCControl other devices,不一定是你版本太旧,也不一定是你找错了地方。更可能的情况是:功能代码已经在客户端里,但开关还没有真正生效。

    我一开始也被这个问题绕了一圈。

    官方页面还在说 Windows 支持即将到来,客户端安装包里却已经有了 Connect a device to this PCControl this PC 这些界面文案。真正把问题拆开后才发现,“功能已经写进客户端” 和 “功能已经对你的账号开放” 之间,中间还隔着一层配置和授权。

    这篇文章不只讲原理,也把完整脚本、完整操作步骤,以及一段可以直接复制给 Codex 的提示词都放出来。

    你甚至可以把这篇文章直接发给 Codex ,让它照着检查你的电脑并自动完成配置。

    一、先确认你遇到的是不是同一个问题

    如果你打开 Codex:

    1. 进入 Settings
    2. 打开 Connections
    3. 页面里只看到 SSH connections from this PC

    那你遇到的,大概率就是我碰到的这个问题。

    也就是说:

    • 客户端里已经有远程控制相关功能
    • 但当前界面只展示了 SSH
    • 远程控制的入口还没有真正出现

    二、真正关键的配置,不在界面里

    Codex 的本地配置文件在这里:

    C:\Users\<你的用户名>\.codex\config.toml
    

    打开后,找到 [features] 这一段。

    很多人的配置里,原本只有这些:

    [features]
    goals = true
    remote_connections = true
    workspace_dependencies = false
    

    真正关键的是,还需要补上这一行:

    remote_control = true
    

    最后变成:

    [features]
    goals = true
    remote_connections = true
    remote_control = true
    workspace_dependencies = false
    

    这一步看起来很小,但它决定了客户端会不会把远程控制相关能力真正拉起来。

    三、为什么我加完之后,重启又失效了

    这里是这次最容易踩坑的地方。

    我第一次把 remote_control = true 加进去之后,重启 Codex ,发现它又没了。

    不是没保存成功,而是新版 Windows 客户端会在启动过程中,把这行配置重新删掉。

    这就导致一个很烦的循环:

    1. 你手动加上 remote_control = true
    2. 重启 Codex
    3. Codex 启动时把它删掉
    4. 你回到界面,还是只能看到 SSH

    表面上看,好像配置没用。

    实际上不是没用,而是它还没来得及发挥作用,就被启动流程抹掉了。

    四、解决办法:在启动时把这行配置“保住”

    目前最实用的办法,是在启动 Codex 前:

    1. 确认 remote_control = true 已经写入
    2. 临时把 config.toml 设为只读
    3. 启动 Codex
    4. 等启动稳定后,再取消只读

    这样做的目的很简单:

    让 Codex 在启动阶段读到这行配置,但来不及把它删掉。

    如果你只想手动验证一次,可以这么做:

    1. 编辑 config.toml
    2. 加上 remote_control = true
    3. 右键文件,打开属性
    4. 勾选“只读”
    5. 启动 Codex
    6. 等客户端完全打开后,再把“只读”取消

    如果你会频繁使用,最好写一个小脚本,把这件事自动化:

    • 先关闭正在运行的 Codex
    • 备份配置文件
    • 自动补上 remote_control = true
    • 临时锁定配置文件
    • 启动官方 Codex App
    • 等启动稳定后自动解除只读

    这样以后每次都用脚本启动,不需要再手工补配置。

    下面就是我实际使用的完整脚本。

    把它保存为:

    C:\Users\<你的用户名>\.codex\codex-remote.ps1
    

    脚本内容如下:

    # ====================================
    # CODEX STARTUP WRAPPER
    # Auto-detect Codex Windows App ID
    # ====================================
    
    $ConfigPath = "$env:USERPROFILE\.codex\config.toml"
    $BackupPath = "$env:USERPROFILE\.codex\config.backup.toml"
    
    try {
        Write-Host ""
        Write-Host "==============================="
        Write-Host " Codex Startup Wrapper"
        Write-Host "==============================="
        Write-Host ""
    
        # FIND CODEX APP ID
        $CodexApp = Get-StartApps | Where-Object {
            $_.Name -match "Codex"
        } | Select-Object -First 1
    
        if (-not $CodexApp) {
            throw "Codex app not found in Start Apps."
        }
    
        Write-Host "Found Codex App:"
        Write-Host $CodexApp.Name
        Write-Host $CodexApp.AppID
        Write-Host ""
    
        # FIND CODEX PROCESS
        $CodexProcess = Get-Process -ErrorAction SilentlyContinue | Where-Object {
            $_.ProcessName -match "^Codex$|^codex$"
        }
    
        # GRACEFUL SHUTDOWN
        if ($CodexProcess) {
            Write-Host "Codex is running. Closing..."
    
            foreach ($p in $CodexProcess) {
                $p.CloseMainWindow() | Out-Null
            }
    
            Start-Sleep -Seconds 3
    
            $StillRunning = Get-Process -ErrorAction SilentlyContinue | Where-Object {
                $_.ProcessName -match "^Codex$|^codex$"
            }
    
            if ($StillRunning) {
                Write-Host "Force stopping Codex..."
                $StillRunning | Stop-Process -Force
            }
    
            Start-Sleep -Seconds 1
        }
        else {
            Write-Host "Codex not running."
        }
    
        # MAKE CONFIG WRITABLE
        if (-not (Test-Path $ConfigPath)) {
            New-Item -ItemType File -Path $ConfigPath -Force | Out-Null
        }
    
        attrib -R $ConfigPath
    
        # BACKUP CONFIG
        Copy-Item $ConfigPath $BackupPath -Force
    
        Write-Host "Backup created:"
        Write-Host $BackupPath
        Write-Host ""
    
        # ENSURE remote_control EXISTS UNDER [features]
        $content = Get-Content $ConfigPath -Raw
    
        if ($content -notmatch '(?m)^\s*remote_control\s*=\s*true\s*$') {
    
            if ($content -match '(?m)^MATHPLACEHOLDER0ENDMATH\s*$') {
    
                $content = $content -replace `
                    '(?m)^(\[features\]\s*)$',
                    "`$1`r`nremote_control = true"
    
                Set-Content $ConfigPath $content
    
                Write-Host "Inserted remote_control under [features]"
            }
            else {
                $content += "`r`n`r`n[features]`r`nremote_control = true`r`n"
    
                Set-Content $ConfigPath $content
    
                Write-Host "Created [features] section."
            }
        }
        else {
            Write-Host "remote_control already exists."
        }
    
        Write-Host ""
    
        # TEMP LOCK CONFIG
        attrib +R $ConfigPath
    
        Write-Host "Config locked as read-only."
        Write-Host ""
    
        # START OFFICIAL CODEX APP
        Write-Host "Launching Codex..."
    
        Start-Process "shell:AppsFolder\$($CodexApp.AppID)"
    
        # WAIT FOR CODEX PROCESS
        do {
            Start-Sleep -Milliseconds 500
    
            $Running = Get-Process -ErrorAction SilentlyContinue | Where-Object {
                $_.ProcessName -match "^Codex$|^codex$"
            }
    
        } until ($Running)
    
        Write-Host "Codex process detected."
    
        # WAIT UNTIL STARTUP STABILIZES
        Write-Host "Waiting for startup to stabilize..."
    
        $StableCount = 0
        $LastWrite = (Get-Item $ConfigPath).LastWriteTimeUtc
    
        while ($StableCount -lt 5) {
            Start-Sleep -Milliseconds 500
    
            $CurrentWrite = (Get-Item $ConfigPath).LastWriteTimeUtc
    
            if ($CurrentWrite -eq $LastWrite) {
                $StableCount++
            }
            else {
                $StableCount = 0
                $LastWrite = $CurrentWrite
            }
        }
    
        Write-Host "Startup stabilized."
        Write-Host ""
    }
    finally {
        attrib -R $ConfigPath
    
        Write-Host "Config unlocked."
        Write-Host ""
        Write-Host "Done."
    }
    

    以后你只需要用 PowerShell 运行它:

    powershell -ExecutionPolicy Bypass -File "$env:USERPROFILE\.codex\codex-remote.ps1"
    

    它会自动完成这些事:

    1. 找到你安装的 Codex Windows App
    2. 关闭当前正在运行的 Codex
    3. 备份 config.toml
    4. 确保 [features] 下存在 remote_control = true
    5. 临时把配置文件设为只读
    6. 启动官方 Codex App
    7. 等启动稳定
    8. 自动解除只读

    这样做的好处是,不会为了保住一行配置,就让整个文件长期处于只读状态。Codex 后续还可以继续正常写入 runtime 、skills 、plugins 等信息。

    五、还有一个很多人忽略的前提:开启 MFA

    这次排查里,另一个非常关键的点是:

    不少人是在开启 ChatGPT 账号的 MFA 之后,手机端授权才真正成功。

    MFA 就是多因素认证。简单说,就是登录账号时,除了密码之外,再多一层确认,比如认证器 App 的动态验证码。

    你可以在 ChatGPT 网页端:

    Settings -> Security -> Multi-Factor Authentication
    

    把它打开。

    如果你已经改好了本地配置,但手机端还是迟迟连不上,优先检查这一项。

    有时候,问题不在 Windows ,也不在 Codex ,而在你的账号还没有满足远程授权的安全条件。

    六、最省事的用法:直接把这篇文章发给 Codex

    如果你不想自己改文件,也不想自己写脚本,最简单的做法其实是:

    把这篇文章完整发给 Codex ,然后让 Codex 按文章内容直接帮你配置。

    你可以把下面这段提示词直接复制给 Codex:

    请根据这篇文章,直接在我的 Windows 电脑上完成 Codex 远程控制配置。
    
    要求:
    1. 先检查当前 Codex 版本、当前分支、C:\Users\<用户名>\.codex\config.toml 的实际内容。
    2. 保持所有文件使用 UTF-8 读写,不要破坏已有中文或特殊字符。
    3. 在 [features] 下确保存在:
       remote_connections = true
       remote_control = true
    4. 如果发现新版 Codex 启动时会删除 remote_control = true ,请创建一个启动脚本:
       C:\Users\<用户名>\.codex\codex-remote.ps1
    5. 这个脚本需要:
       - 备份 config.toml
       - 自动补上 remote_control = true
       - 启动前临时把 config.toml 设为只读
       - 启动 Codex
       - 等启动稳定后自动解除只读
    6. 完成后实际验证:
       - config.toml 中 remote_control = true 是否保留
       - Codex 重启后是否仍然保留
    7. 如果需要我手动做的步骤,例如开启 ChatGPT MFA 、在手机端授权,请明确告诉我。
    

    如果你希望它更主动一点,还可以在最后再加一句:

    除非涉及删除大量代码、改公共接口或执行危险操作,否则不要只给方案,请直接完成配置并验证。
    

    七、我最后是怎么成功的

    我这次真正跑通,大致是这条路线:

    1. 确认 Windows Codex 已经是新版本
    2. 打开本地 config.toml
    3. [features] 下加入:
    remote_connections = true
    remote_control = true
    
    1. 发现重启后 remote_control = true 会被自动删除
    2. 改用启动脚本,先锁住配置,再启动 Codex
    3. 确认 ChatGPT 账号已经开启 MFA
    4. 打开手机上的 ChatGPT App
    5. 进入 Codex ,完成授权
    6. 成功从手机接管 Windows 上的 Codex
    6 replies    2026-05-18 17:01:16 +08:00
    Saunak
        1
    Saunak  
       3 days ago
    win 这个版本 Codex 26.513.40821 ,win 端不弹相关的连接诶?改了 config.toml 和只读
    scf2024
        2
    scf2024  
    OP
       2 days ago via Android
    @Saunak 现在改了好像没用,它每次启动时候会把你那个给它删掉,所以得用文章中那个脚本才能启动
    Saunak
        3
    Saunak  
       2 days ago
    @scf2024 #2 我看了启动后的 config.toml 文件,里面有 remote_connections = true
    remote_control = true 呀。不知道是什么原因无效
    scf2024
        4
    scf2024  
    OP
       2 days ago via Android
    @Saunak 这是因为 codex 在每次启动都会把这个配置删除掉
    Cloudiver
        5
    Cloudiver  
       2 days ago
    可能和账号相关,我没有生效
    scf2024
        6
    scf2024  
    OP
       2 days ago
    @Cloudiver 你把我这个文章发给 codex ,它会帮你改好
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4435 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 10:02 · PVG 18:02 · LAX 03:02 · JFK 06:02
    ♥ Do have faith in what you're doing.