Codex History Traversal
Overview
Use the prepackaged Python script in scripts/traverse_codex_history.py to scan Codex rollout JSONL files, merge messages and tool events by session, filter by folder path, and output timeline JSON compatible with the Cursor history traversal skill.
Required Environment
Any Python 3.8+ interpreter works; the script uses only the standard library. Plain python on PATH is enough — do NOT run conda activate base first (conda is often not initialized in PowerShell and the command fails):
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --out "D:\Projects\my-app-history.json"Only if python is missing from PATH, fall back to py -3 or the Git Bash wrapper:
powershell -ExecutionPolicy Bypass -File scripts\run_traversal_via_git_bash.ps1 -Folder "D:\Projects\my-app" -Out "D:\Projects\my-app-history.json"Interface Compatibility
The script keeps the same CLI pattern as cursor-history-traversal:
--folder(required)--out--contains--limit--brief(metadata-only output, no transcripts)--cursor-root(for compatibility; also accepts--codex-root)
What The Script Traverses
- Auto-discovered Codex installation roots (for example
.codex,codex,.codex-local). - Session files under
sessions/**/rollout-*.jsonl. - Optional project-style JSONL under
projects/**/*.jsonl. - Event schemas including:
session_metaturn_contextmessageresponse_item(message,function_call,function_call_output,custom_tool_call)event_msg(user_message,agent_message,tool_use,tool_result,diff)
Patch Extraction
The script extracts patch operations from apply_patch usage and replays them in strict chronological order:
- Select matched sessions/files after folder filtering.
- Extract all
custom_tool_callentries wherename == "apply_patch". - Also detect
apply_patchembedded infunction_callarguments (e.g. shell arrays). - Parse patch operations:
Add FileUpdate FileDelete File - Build top-level
patch_replayordered by timestamp and operation order.
Command Patterns
Folder history export:
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --out ".\my-app-history.json"Compact survey first (metadata only, no transcripts — start here, then re-run without --brief on a narrowed filter):
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --brief --out ".\my-app-brief.json"Search messages by text while filtering folder (a drive root like D:\ matches everything on that drive):
python scripts/traverse_codex_history.py --folder "D:\" --contains "refactor" --out ".\refactor-history.json"Limit the number of returned sessions:
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --limit 50Use custom Codex root (auto-discovery finds %USERPROFILE%\.codex and similar locations by default):
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --codex-root "$env:USERPROFILE\.codex"Output
The script prints:
- Number of total sessions scanned.
- Number of sessions matching the folder filter.
- Number of replayable patch operations.
- A per-session timeline line (
date | messages | session_id | project_root | db_path). - JSON written to
--outwith matched sessions plus top-levelpatch_replay(or compact metadata with--brief).
Notes
- Path matching is prefix-based and normalized (
D:\Projects\my-appmatches subfolders;D:\matches the whole drive). - If no sessions match, the script still writes an empty JSON result with scan metadata.
- Patch replay order is deterministic: timestamp first, then operation appearance order.
- Full-session output JSON can be tens of MB. Use
--brieffor surveys, and query large JSON files with a small script instead of reading them whole. - Console output is forced to UTF-8, and the
--outparent directory is created automatically. - Full scans read every rollout JSONL under
sessions/— with a large history this takes about a minute; allow for that in command timeouts.