Import Codex sessions into `clai2` with their harness context, compacted history, encrypted reasoning, and sub-agents as tasks
Why we make these changes
Douwe wants to move his Codex sessions into clai2 without losing anything. The importer read Codex rollouts as a flat list and threw away a lot of what Codex's model actually saw. I compared it with the open-source Codex source (rollout_reconstruction.rs, ResponseItem, context_manager, agent/control) and with his 305 local rollouts. Before this change, 7,580 of the 17,231 model-visible texts were missing from the import. Now 0 of 15,899 are missing, and 0 of 1,851 for sub-agents.
What the importer now keeps:
- Harness context. Developer instructions,
<environment_context>, AGENTS.md and the other context Codex added are imported asimported_context, as Claude Code's are. Codex'scontent_item_kindsset thekind; older versions fall back to tag prefixes. Typed prompts keep their images in order. - Compaction. The history before each compaction is now kept. An encrypted
compactionitem becomesCompactionPart(provider_name='openai-codex'), which acts as a wire boundary:openai-codex:models continue from the summary, as Codex did, and other models read the whole history, since they can't read the summary. The items compaction retained (messages, agent messages, tool outputs) follow it as context. A readable local summary is tagged as such. - OpenAI's encrypted round-trip data. Reasoning keeps its
encrypted_contentas theThinkingPartsignature. Text keepsphase, and function calls keepnamespaceand ids, all mirroringOpenAIResponsesModel. - Sub-agents. Every descendant thread becomes a finished task of the session, under ids derived from the session and thread ids. Default sub-agents are imported as resumable tasks named
self.FINAL_ANSWERmessages become<task_output>reports, and agent messages Codex encrypted are marked. Sub-agent sessions are no longer listed on their own. - Codex semantics.
thread_rolled_backdrops turns the way Codex counts them, keeping the session's opening context. Legacyinter_agent_communicationrecords are read. Delivered-message records are skipped. - Framing. The opening and closing notes about the change of harness are shared with Claude Code's importer, through
framedandfinal_answerinimported_history.py. /resumelisting. Sessions run bycodex execare no longer listed, but--resume-codex IDstill imports them. These were 252 of 272 of Douwe's sessions.
Maintainer decisions:
- Keep the pre-compaction history rather than match Codex exactly.
- Hide exec sessions.
New public surface
None. These are clai2 internals: HistoryBuilder.rollback, imported_kind, framed, final_answer, Header.listed and codex_sessions.tasks. Two module constants change value, and both are waived in the API-compatibility allowlist:
codex_sessions.PROVIDERgoes from'openai'to'openai-codex'.codex_sessions.CONTEXT_PREFIXESgains entries.
User-visible behavior
Codex imports now carry the context, compaction history, reasoning and sub-agents listed above. codex exec runs are hidden from /resume.
Verification
tests/clai2passes (4,565). The new tests cover context kinds, encrypted round-trip parts, compaction (encrypted, local and legacy), rollbacks, sub-agents as tasks, and the exec listing.codex_sessions.pyandimported_history.pyhave 100% coverage.- Corpus check over all of Douwe's local rollouts: no errors, 0 model-visible texts missing, and all 33 sub-agents mapped to tasks.
- I ran two live requests via
openai-codex:on the account Codex used, one on a compacted session and one on a session with reasoning and namespaced calls. Both continued correctly. A custom tool call'sctc_id is rejected as a function-call id, so custom calls carry no id.
What changes for existing users
Re-importing a Codex session that hasn't been continued in CLAI yet refreshes it with the fuller history. Copies already continued in CLAI are unchanged.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.