全部指南

Windows 上的 Codex CLI 通知(PowerShell 与 WSL)

更新于 2026年11月19日 · 阅读约 5 分钟

在 Windows Terminal、PowerShell 和 VS Code 终端中,Codex CLI 的内置提醒只是终端响铃,所以要获得真正的 Windows 通知,需要自己添加。在 %USERPROFILE%\.codex\hooks.json 中放入一个 Stop hook(用于“已完成”)和一个 PermissionRequest hook(用于“需要批准”),让它们运行 PowerShell,然后用 /hooks 信任它们。BurntToast 模块能显示正规的 toast 通知。如果 Codex 运行在 WSL 中,hook 会在 Linux 中运行,因此需要通过 Windows 互操作调用 powershell.exe 才能到达 Windows 桌面。

01Codex 在 Windows 上的默认行为

Codex 的内置通知默认开启,在一轮完成或有批准请求在等待、且终端不在前台时触发。在 Windows Terminal 中它使用响铃字符,因为 Codex 只向已知支持 OSC 9 的终端(Ghostty、iTerm2、Kitty、Warp 和 WezTerm)发送桌面通知。Windows Terminal 对响铃的反应按配置文件设置:在“设置 > 配置文件 > 高级”中,响铃通知样式可以是发出声音、闪烁窗口或闪烁任务栏。Windows 上的 WezTerm 能收到 OSC 9 通知。

内置通知指南介绍了 [tui] 设置。

02hook 文件的位置

对于在 Windows 上原生运行的 Codex,用户 hook 文件是 %USERPROFILE%\.codex\hooks.json,例如 C:\Users\you\.codex\hooks.json。如果你设置了 CODEX_HOME,则位于该文件夹中。在 WSL 中,它是 Linux 主目录下的 ~/.codex/hooks.json。

03原生 Windows:用 BurntToast 显示 toast 通知

在 PowerShell 中安装一次模块:

Install-Module BurntToast -Scope CurrentUser
New-BurntToastNotification -Text 'Codex', 'Test'

如果测试 toast 出现了,就添加 hook:

{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "powershell -NoProfile -Command \"New-BurntToastNotification -Text 'Codex','Codex has finished' | Out-Null\""
          }
        ]
      }
    ],
    "PermissionRequest": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "powershell -NoProfile -Command \"New-BurntToastNotification -Text 'Codex','Codex wants your approval' | Out-Null\""
          }
        ]
      }
    ]
  }
}

然后启动 codex,输入 /hooks 并信任这两个 hook。Codex 会跳过未被信任的 hook。

让命令保持静默:Codex 会把 Stop hook 输出的纯文本视为无效。PermissionRequest hook 不做任何决定,所以批准提示仍会出现在终端里。

启动 PowerShell 需要一点时间。如果它拖慢了每轮的结束,在 handler 中加上 "async": true,这样 Codex 就不会等待它。

04原生 Windows,无需安装任何东西

不用 BurntToast 时,一个简短的脚本就能通过 Windows Forms 显示气泡提示。将它保存为 %USERPROFILE%\.codex\hooks\notify.ps1:

param([string]$Message = "Codex has finished")
Add-Type -AssemblyName System.Windows.Forms
$n = New-Object System.Windows.Forms.NotifyIcon
$n.Icon = [System.Drawing.SystemIcons]::Information
$n.Visible = $true
$n.ShowBalloonTip(5000, "Codex", $Message, "Info")
Start-Sleep -Seconds 6
$n.Dispose()

然后这样调用:

"command": "powershell -NoProfile -ExecutionPolicy Bypass -File C:\\Users\\you\\.codex\\hooks\\notify.ps1",
"async": true

JSON 中的反斜杠需要写两遍。async 让 Codex 在气泡显示期间不必等待。不要在 hook 中使用消息框:它会一直阻塞,直到有人点击“确定”。

05在 WSL 中运行 Codex

在 WSL 中运行 codex 时,hook 在 Linux 中运行。那里通常没有 Linux 通知守护进程,所以改为调用 Windows:

"command": "powershell.exe -NoProfile -Command \"New-BurntToastNotification -Text 'Codex','Codex has finished' | Out-Null\""

这需要启用 Windows 互操作(WSL 中默认开启)以便找到 powershell.exe,并且需要在 Windows 一侧安装 BurntToast。如果 powershell.exe 不在 WSL 的 PATH 中,请使用完整路径:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe。

06notify 设置

如果只需要“已完成”提醒,Codex 在 config.toml 中的 notify 设置可以运行一个脚本,而且无需信任步骤。notify 指南中有一个包含 Windows 分支的跨平台 Python 脚本。

07或者使用 codex-notifier

Notifier for Codex 的免费 codex-notifier 工具会替你安装 hook,并在 Codex 完成、需要批准或提问时显示 Windows 通知。在 PowerShell 中运行(Windows 支持目前为 beta 版):

irm https://notifierforcodex.com/install.ps1 | iex; codex-notifier pair

codex-notifier pair 会先向 %USERPROFILE%\.codex\hooks.json 添加六个条目,并在 config.toml 中标记为受信任,所以无需 /hooks 步骤。然后它会与 iPhone 或 Android app 配对,同样的时刻也会推送到你的手机,你可以在手机上批准或拒绝、回答或发送下一条指令。它也能在 WSL 中使用,行为与在 Linux 上相同。Notifier for Codex 是独立产品,与 OpenAI 无关联;app 价格见价格。

08常见问题

为什么 Codex 的内置通知没有弹出 toast?

Windows Terminal 和 VS Code 终端收到的是响铃,而不是桌面通知。把配置文件的响铃样式设为闪烁任务栏,或者使用 hook。

我的 hook 命令由哪个 shell 运行?

编写 hook 命令时,要让它无论由谁启动都能运行:像上面那样显式调用 powershell -NoProfile -Command "..." 或 -File script.ps1,而不要在顶层直接依赖 PowerShell 语法。如果某条命令在 Windows 上必须与其他机器不同,请使用 handler 的 commandWindows 字段。

toast 在 PowerShell 中能显示,从 Codex 运行就不行,哪里出了问题?

检查 /hooks 是否显示该 hook 已受信任、hooks.json 是否为有效 JSON 且反斜杠已写两遍,以及“专注助手”(勿扰模式)是否隐藏了通知。

在 Windows 上的 VS Code 终端中运行 Codex 时也能用吗?

能。hook 由 Codex 运行,而不是由终端运行,所以同样的 hook 在任何运行 codex 的终端中都有效。

Notifier for Codex Codex 完成任务或需要你时,手机会收到 push,你可以直接在手机上批准、拒绝或回复。codex-notifier 命令行工具在 Mac、Windows 和 Linux 上免费使用。