Codex History Manager
Use codex-history-manager when the task is about local Codex history, not general ChatGPT or web chat history.
Codex stores local history in two places:
- -
~/.codex/state_5.sqlite for thread metadata - INLINECODE2 and
~/.codex/archived_sessions/... for event logs
The bundled CLI is the source of truth for reading and mutating that state:
Default workflow
- 1. For discovery, start with
search. - For context, use
show-thread or handoff. - For exports, use
export-thread. - For cross-workspace reuse, prefer
clone-thread over move-thread. - For writes, run a dry run first, then rerun with
--apply. - For history body rewrites, always do
plan-dangerous-edit, show the warning and change list to the user, get explicit approval in chat, then run apply-dangerous-edit.
Core commands
./codex-history-manager search --query "payments"
./codex-history-manager show-thread --id <thread-id>
./codex-history-manager export-thread --id <thread-id> --format markdown --output /tmp/thread.md
./codex-history-manager handoff --id <thread-id> --output /tmp/handoff.md
- - Plan a dangerous history content rewrite:
./codex-history-manager plan-dangerous-edit --id <thread-id> --find "old" --replace "new" --output /tmp/edit-plan.json
- - Clone a thread into another workspace:
./codex-history-manager clone-thread --id <thread-id> --to-cwd /abs/path --dry-run
- - Move all threads in one workspace:
./codex-history-manager move-workspace --cwd /abs/src --to-cwd /abs/dst --dry-run
- - Clone all threads in one workspace:
./codex-history-manager clone-workspace --cwd /abs/src --to-cwd /abs/dst --dry-run
- - Move a thread to another workspace:
./codex-history-manager move-thread --id <thread-id> --to-cwd /abs/path --dry-run
- - Rebind provider metadata:
./codex-history-manager change-provider --id <thread-id> --provider openai1 --dry-run
- - Rebind provider metadata for one workspace:
./codex-history-manager change-provider-workspace --cwd /abs/path --provider openai1 --dry-run
- - Rebind provider metadata for all local threads:
INLINECODE25
Safety rules
- - Never perform a write first. Use the default dry run or pass
--dry-run. - Only use
--apply after reviewing the plan. - Prefer cloning over moving unless the user explicitly wants to change ownership.
- Do not hand edit
state_5.sqlite or rollout files if the CLI can do the job. - If the user asks to modify message content, stop and confirm. You must first produce a dangerous edit plan, present the warning and change list in the conversation, and wait for explicit user approval before running
apply-dangerous-edit.
Read these references only when needed:
Codex 历史管理器
当任务涉及本地 Codex 历史记录(而非通用 ChatGPT 或网页聊天历史)时,请使用 codex-history-manager。
Codex 在以下两个位置存储本地历史记录:
- - ~/.codex/state5.sqlite:存储线程元数据
- ~/.codex/sessions/.../rollout-*.jsonl 和 ~/.codex/archivedsessions/...:存储事件日志
内置 CLI 是读取和修改该状态的权威工具:
- - ./codex-history-manager ...
默认工作流程
- 1. 发现阶段:从 search 开始。
- 上下文获取:使用 show-thread 或 handoff。
- 导出操作:使用 export-thread。
- 跨工作区复用:优先使用 clone-thread 而非 move-thread。
- 写入操作:先执行试运行,再使用 --apply 重新运行。
- 历史内容重写:始终先执行 plan-dangerous-edit,向用户展示警告和变更列表,在聊天中获取明确批准后,再运行 apply-dangerous-edit。
核心命令
./codex-history-manager search --query payments
./codex-history-manager show-thread --id
./codex-history-manager export-thread --id --format markdown --output /tmp/thread.md
./codex-history-manager handoff --id --output /tmp/handoff.md
./codex-history-manager plan-dangerous-edit --id --find old --replace new --output /tmp/edit-plan.json
./codex-history-manager clone-thread --id --to-cwd /abs/path --dry-run
./codex-history-manager move-workspace --cwd /abs/src --to-cwd /abs/dst --dry-run
./codex-history-manager clone-workspace --cwd /abs/src --to-cwd /abs/dst --dry-run
./codex-history-manager move-thread --id --to-cwd /abs/path --dry-run
./codex-history-manager change-provider --id --provider openai1 --dry-run
./codex-history-manager change-provider-workspace --cwd /abs/path --provider openai1 --dry-run
./codex-history-manager change-provider-all --provider openai1 --dry-run
安全规则
- - 切勿直接执行写入操作。请使用默认的试运行模式或传递 --dry-run 参数。
- 仅在审查计划后使用 --apply。
- 除非用户明确要求更改所有权,否则优先使用克隆而非移动。
- 如果 CLI 能够完成任务,请勿手动编辑 state_5.sqlite 或 rollout 文件。
- 如果用户要求修改消息内容,请暂停并确认。您必须首先生成危险编辑计划,在对话中展示警告和变更列表,并在获得用户明确批准后,才能运行 apply-dangerous-edit。
仅在需要时参考以下文档: