Skip to main content

Module codex

Module codex 

Source
Expand description

Codex session discovery, from the rollout transcripts Codex writes.

§Why there is no process here

Claude Code writes ~/.claude/sessions/<pid>.json per session, so liveness is exact: the pid either exists or it does not. Codex has no such file, and — measured on a real machine — no usable process mapping either. The ChatGPT desktop app runs Codex as one long-lived codex … app-server process serving every session, alongside 27 Electron helpers. A terminal codex would be its own process, but nothing distinguishes which session a given process owns.

So a Codex session is discovered from its transcript, and the consequences are honest rather than papered over:

  • There is no pid, so ClaudeSession::pid is 0 and the session is not actionable — see ClaudeSession::is_actionable. Sending input to it or killing it is not merely unimplemented; with the app there is no process that would mean the right thing.
  • There is no cost. Codex is subscription-billed and rollouts record tokens only, so cost_usd stays 0 with usage_metrics_available false — absent, rather than a $0.00 that would understate a fleet total.
  • There is no session-end event. task_complete ends a turn, not a session, and a session the user closed is byte-identical to one sitting idle. Liveness is therefore a recency window, and a crashed session mid turn reads as working until that window expires. CODEX_SESSION_TTL_SECS is the whole of the liveness model, and that is a property of what Codex records, not a shortcut.

§Layout

~/.codex/sessions/YYYY/MM/DD/rollout-<ISO-ts>-<uuid>.jsonl

One JSON object per line: {timestamp, ordinal, type, payload}. The types this module reads are session_meta (identity and cwd), event_msg/token_count (usage and the context window), event_msg/{task_started,task_complete,turn_aborted} (status), and response_item/{function_call,custom_tool_call} (the pending tool).

Structs§

RolloutSummary
What one rollout transcript says about its session.

Enums§

Lifecycle
The lifecycle state the transcript last recorded.

Constants§

CODEX_SESSION_TTL_SECS
How long after its last write a rollout still counts as a live session.

Functions§

parse_rollout
Parse a rollout transcript. Pure, so it is testable without a filesystem.
scan
Every rollout whose last write is within ttl_secs of now_secs, parsed.
sessions_root
~/.codex/sessions.