﻿---
title: "桌面提醒用顶层 notify，JSON 在 argv，别塞进 [tui]"
summary: "目前只在 agent-turn-complete 时跑外部命令。项目 .codex 写了会被忽略。写在所有 [table] 之前，否则 TOML 会当成表里的键。"
category: config
level: starter
surfaces: [cli]
tags: ["notify", "通知", "config.toml"]
canonical: /tips/notify-external-command/
---

# 桌面提醒用顶层 notify，JSON 在 argv，别塞进 [tui]

目前只在 agent-turn-complete 时跑外部命令。项目 .codex 写了会被忽略。写在所有 [table] 之前，否则 TOML 会当成表里的键。

TUI 内置通知管失焦终端；要响铃、Webhook、`notify-send`，用用户级顶层键：

```toml
notify = ["python3", "/home/you/.codex/notify.py"]

[tui]
notifications = ["agent-turn-complete", "approval-requested"]
```

`notify` 必须出现在任何 `[tui]` / `[mcp_servers]` 之前。写在表后面，TOML 会把它收进上一张表，看起来像「配了没反应」。项目 `.codex/config.toml` 里的 `notify` 会被忽略，启动时有警告。

Codex 把**一整段 JSON 字符串**当作第一个参数传给命令，不是 stdin。目前官方只保证 `type = "agent-turn-complete"`。脚本先解析再过滤：

```python
import json, subprocess, sys
event = json.loads(sys.argv[1])
if event.get("type") != "agent-turn-complete":
    raise SystemExit(0)
msg = event.get("last-assistant-message") or "turn complete"
subprocess.run(["notify-send", "Codex", msg], check=False)
```

这不是 `tui.notifications`，也不是 Stop 钩子里自己调的 `notify-send`。`codex cloud exec` 不会打这条本地命令。改完新开会话，跑一轮短任务确认弹窗，不要只看 `/debug-config` 里有没有这个数组。

## 来源

- [OpenAI · Advanced configuration](https://learn.chatgpt.com/docs/config-file/config-advanced)
- [samwize · macOS notify](https://samwize.com/2026/02/05/setup-codex-cli-notifications-on-macos-iterm2-terminal-notifier/)
