Claude to Codex import guide
This reveals a technical compatibility issue between two AI coding assistants that affects workflow continuity. Developers who use both platforms need this specific process to maintain conversation history and project context. The guide provides concrete steps to preserve chat IDs and complete conversation history during the transition between systems.
Users face context window issues when importing Claude Code conversations to Codex.
The official import method often fails with 'Your input exceeds the context window' due to conversation compression differences.
A proper workflow has been developed to detect, backup, and rebuild context during the import process.The solution handles both short and long conversations differently, using compression summaries when available.
亲测claude 导入codex:发现事情没这么简单,如果按codex 官方的做法导入,继续对话大概率是有问题的,因为我们在Claude 里对话会有压缩,但是到了codex 它是把全对话吃进去,直接触发:Your input exceeds the context window
那么正确做法我们也找到了,分享给大家,把如下提示词给codex即可:
``` 请把本机 Claude Code 会话导入 Codex,并修复导入后可能出现的: “Your input exceeds the context window of this model”。
目标:能在原导入聊天里继续工作,保留聊天 ID、项目归属、完整历史及已有需求。请完成检测、备份、导入、修复和验证,最后报告实际结果。
按以下流程执行:
1. 检测与确定范围 自动识别本机 Claude Code、Codex 数据目录和当前 Codex 运行时版本。 优先使用 Codex 原生导入功能,导入范围限定为会话及项目关联。 默认处理原生导入器可发现的全部会话;说明数量或日期限制,以及未覆盖范围。 根据源会话路径、会话 ID 和导入映射识别已导入会话,复用原聊天 ID,避免重复导入。
2. 完整备份 修改前,备份目标 Codex 会话的完整 JSONL、相关元数据和导入映射,记录 SHA-256。 将备份、修复计划和验证结果保存到当前工作目录的 outputs 中。 Claude 原始记录保持不变;读取活动源记录时优先使用快照。
3. 检查有效上下文 核对 Claude 原会话的压缩边界、最近一次压缩摘要及其后续对话。 检查 Codex 导入结果是否重新带入了压缩前的旧历史。 核对当前模型实际窗口和指令、工具开销,给恢复上下文留足空间。 token 数量注明是估算还是实际请求统计。
4. 重建上下文 较短会话保留全部模型消息。 较长会话优先使用 Claude 已有压缩摘要,加上后续关键需求、决定、完成情况、待办和限制。 没有可靠摘要时,分段读取并整理,避免一次加载全部历史。 核对 Codex first_user_message、近期用户输入和聊天元数据,补回只登记在元数据中的需求。 历史完成声明保留来源,不直接当作当前验证结果;历史授权不自动授权新的操作。
5. 修复原会话 优先使用当前版本支持的原生接口。 需要修改 JSONL 时,先确认当前运行时支持对应格式,再追加原生上下文检查点。 如使用 compacted / replacement_history,确认它真正改变下一次模型请求使用的历史数组。 保留完整旧历史正文,并更新与新上下文对应的 token 估算快照,保留累计用量。 通过目标会话的卸载、重新加载清除旧内存缓存。 只操作目标会话;正在运行的会话暂缓处理,继续修复其余会话。 写入前检查锁和文件哈希,避免覆盖并发产生的新内容。
6. 验证 逐个检查原聊天 ID、项目归属、用户命名、模型和权限设置。 核对完整旧历史仍被保留,Claude 源文件未被修改。 使用当前安装的 Codex 运行时实际读回,确认压缩检查点能被识别。 抽样在临时会话中载入相同恢复上下文,调用真实模型验证它能识别项目、已有进展和继续需求。 验证仅回答检查问题,不执行历史项目任务。
7. 收尾 给出成功、失败、暂缓和未覆盖的数量。 分别说明文件修改、运行时读回和真实模型验证的结果。 提供备份及修复报告路径,并告诉我如何继续使用原聊天。 未经验证的部分明确标注,不提前宣称全部完成。
在本任务已授权范围内自主完成常规操作,不反复询问已经明确的执行步骤。 ```
This report is categorized under AITOP's "How-to" desk, focusing on US frontier AI labs and Silicon Valley technology leaders. Within our cross-regional analytical framework, it directly maps to AI developer toolchains, coding agents, and engineering workflows. Key entities and technical topics under continuous tracking include Claude Code, Codex, context window, prompt engineering.
Source attribution: curated from 岚叔 (@lufzzliz).