# 历史记录与通知

> 配置本地历史持久化、终端通知和回合完成后的外部通知程序。

- 网址：https://funcoding.ai/agents/codex/configuration/history-notifications/
- 核实日期：2026-10-07（命令、配置和价格以官方文档为准）
- 官方来源：[Codex 官方文档：Advanced Configuration](https://learn.chatgpt.com/docs/config-file/config-advanced)

---
历史记录用于之后查找和继续讨论；通知让你在回合完成或需要审批时注意到当前任务。两者都可在用户级 `config.toml` 配置。

## 历史记录

Codex 默认在 `CODEX_HOME` 下保存本地历史。关闭历史持久化：

```toml
[history]
persistence = "none"
```

限制历史文件大小时使用 `history.max_bytes`。例如以下值表示 100 MiB，是可选配置示例，不是默认限制：

```toml
[history]
max_bytes = 104857600
```

文件超过上限后，Codex 丢弃较旧条目并压缩文件，保留较新的记录。恢复和归档入口见[会话管理](https://funcoding.ai/agents/codex/usage/sessions/)。

## TUI 通知

`tui.notifications` 可以启停通知，也能按事件类型筛选，例如 `agent-turn-complete` 或 `approval-requested`。

`tui.notification_method` 可选 `auto`、`osc9` 或 `bel`，默认 auto：终端看起来支持 OSC 9 时优先使用，否则回退到 BEL。`tui.notification_condition` 控制只在终端未聚焦时通知（`unfocused`），还是始终通知（`always`）。

通知显示依赖终端能否处理相应序列。未看到系统通知时，应先检查终端支持与通知条件。

## 外部程序通知

`notify` 可以在支持的事件发生时运行外部程序，目前支持 `agent-turn-complete`：

```toml
notify = ["python3", "/path/to/notify.py"]
```

脚本必须存在。它通过一个 JSON 命令行参数接收数据，常见字段有 `type`、`thread-id`、`turn-id`、`cwd`、`input-messages`、`last-assistant-message`。应解析 JSON 并检查事件类型，不要假定它从 stdin 接收事件。

`notify` 适合外部通知程序，`tui.notifications` 是终端内置路径。notify 属于机器本地配置，不能通过项目 `.codex/config.toml` 注入。
