read-codex-history
Reads, searches, and exports local OpenAI Codex history without continuing the old task. Lists recent Codex sessions, extracts exact prompt-ledger inputs by Session, locates a rollout by verified session_meta identity, reconstructs one chronological user/assistant timeline with fork and compaction lineage, and performs bounded keyword search across live and archived rollouts. Use whenever the user asks what they told Codex, wants recent original inputs, a Codex Session ID, full prior context, fork ancestry, or evidence of what a Codex run did. For Claude Code history use read-claude-code-history.
1How It Works & Mechanism
Reads across three non-interchangeable Codex history surfaces: history.jsonl (prompt ledger, raw user submissions), state_*.sqlite (manifest metadata), and rollout-*.jsonl under sessions|archived_sessions (full event streams); routes each query to dedicated scripts and forbids ad-hoc join re-inventions.
| `<codex-home>/history.jsonl` | What the user submitted, keyed by Session ID and internal epoch timestamp | Exact recent user-input tables |
Identity and lineage gating: before establishing any behavioral conclusion, the agent must (1) verify prompt-ledger Session IDs, (2) locate rollouts by internal session_meta.id rather than filename, (3) require parsed session_meta.id == requested ID, and (4) require declared parent IDs + exact history_base.end_byte_offset on fork edges, rejecting missing, ambiguous, cyclic, or mismatched ancestors.
Locate rollout candidates by their internal `session_meta.id`, not filename alone.
SQLite reads are enforced as read-only: _core/codex.py connects using file: URI ?mode=ro and sets PRAGMA query_only=ON, falling back to raw rollout JSONL scans if schemas are incompatible.
return "file:" + quote(path.resolve().as_posix(), safe="/:@") + "?mode=ro"
Writer-lock observations are positive-only: performs non-blocking reads of the .coordination.lock file; holding a lock only proves that a process held a Codex canonical thread lock at snapshot time, without identifying processes or proving ongoing liveness.
A held lock proves only that some process owns the advisory lock; it does not
Input reconciliation (reconcile_codex_inputs.py): combines the existing ledger and a strict lineage reader to produce raw input counts and citations for an entire session, preserving occurrence, verbatim text, and source coordinates; exit 2 or complete:false is treated as incomplete, and scope_input_count: null ≠ 0.
Use the reconciler to compose the existing ledger and strict lineage readers. It preserves occurrences, original strings, and source coordinates.
Context budget discipline for oversized briefings: when a full briefing exceeds model context, it is materialized once to a private temporary file with recorded SHA-256 and line count; reads are performed in bounded intervals by header/coordinate, unread sections are explicitly reported as gaps, and piecing together a false 'complete' view via fragmented reruns is forbidden.
materialize it once to a private temporary file and record its SHA-256 plus line count before reading
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| cli | git(工作区状态上下文,read_codex_session 中 subprocess) |
| cli | rg/grep(text.py 可选路径预过滤,与 claude 版共享 core) |
4Recommended Governance & Evidence
- scripts/: Local script or command execution: runs 5 bundled scripts via python3 (pure standard library)
5Second-Pass Verification
- [ok] sqlite 只读强制 — _core/codex.py: sqlite_uri 加 ?mode=ro;inspect/collect 均 PRAGMA query_only=ON。
- [ok] 无任何网络外发 — 全 scripts 目录扫描无 requests/urllib/socket/curl/wget;本 skill 不含 history_index 类下载器。
- [ok] 凭证读取检查 — 全目录无 auth.json/API key/.env/密钥 env 访问;只读 rollout 与 ledger。
- [ok] SKILL 声明的 flag 与脚本存在性 — reconcile --through-record/--omit-first/--omit-last、list_codex_user_inputs --recent/--session-id/--per-session、analyze_sessions search --codex-only、read_codex_session --full 均核对到 argparse。
- [unlocatable] rollout 格式跨版本声明(0.142.2–0.149.0) — codex_rollout_format.md 自述 'Verified against ~2,600 real rollouts';源码内无法复核该实测声明,未运行 Codex 验证。
- [ok] writer-lock 观测语义 — list_local_history.py 251-283 非阻塞取协调锁 + 输出 positive-only 语义字符串,与 SKILL 描述一致。
6Verdict & Scenarios
c30dd57b4165452f…