---
name: codex-history-traversal
description: Traverse Codex rollout/session JSONL history from local Codex installations and filter sessions by project folder path. Use when asked to retrieve "all history" for a directory from Codex, extract tool usage and `apply_patch` operations, replay patch operations in chronological order, or export folder-scoped Codex timeline JSON.
title: codex-history-traversal
canonical_url: https://skilld.dev/gh/geocine/skills/codex-history-traversal
last_updated: 2026-09-26T00:54:16.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/run_traversal_via_git_bash.ps1](https://skilld.dev/api/skills-raw/geocine/skills/codex-history-traversal/scripts/run_traversal_via_git_bash.ps1), [scripts/traverse_codex_history.py](https://skilld.dev/api/skills-raw/geocine/skills/codex-history-traversal/scripts/traverse_codex_history.py).
>
> If the user asked to install this Skill, run `npx skilld install geocine/skills/codex-history-traversal`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/codex-history-traversal`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/geocine/skills/codex-history-traversal) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/codex-history-traversal`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/codex-history-traversal --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/codex-history-traversal --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# 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):

```powershell
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
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`:
1. `--folder` (required)
2. `--out`
3. `--contains`
4. `--limit`
5. `--brief` (metadata-only output, no transcripts)
6. `--cursor-root` (for compatibility; also accepts `--codex-root`)

## What The Script Traverses

1. Auto-discovered Codex installation roots (for example `.codex`, `codex`, `.codex-local`).
2. Session files under `sessions/**/rollout-*.jsonl`.
3. Optional project-style JSONL under `projects/**/*.jsonl`.
4. Event schemas including:
`session_meta`
`turn_context`
`message`
`response_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:
1. Select matched sessions/files after folder filtering.
2. Extract all `custom_tool_call` entries where `name == "apply_patch"`.
3. Also detect `apply_patch` embedded in `function_call` arguments (e.g. shell arrays).
4. Parse patch operations:
`Add File`
`Update File`
`Delete File`
5. Build top-level `patch_replay` ordered by timestamp and operation order.

## Command Patterns

Folder history export:

```powershell
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):

```powershell
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):

```powershell
python scripts/traverse_codex_history.py --folder "D:\" --contains "refactor" --out ".\refactor-history.json"
```

Limit the number of returned sessions:

```powershell
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --limit 50
```

Use custom Codex root (auto-discovery finds `%USERPROFILE%\.codex` and similar locations by default):

```powershell
python scripts/traverse_codex_history.py --folder "D:\Projects\my-app" --codex-root "$env:USERPROFILE\.codex"
```

## Output

The script prints:
1. Number of total sessions scanned.
2. Number of sessions matching the folder filter.
3. Number of replayable patch operations.
4. A per-session timeline line (`date | messages | session_id | project_root | db_path`).
5. JSON written to `--out` with matched sessions plus top-level `patch_replay` (or compact metadata with `--brief`).

## Notes

1. Path matching is prefix-based and normalized (`D:\Projects\my-app` matches subfolders; `D:\` matches the whole drive).
2. If no sessions match, the script still writes an empty JSON result with scan metadata.
3. Patch replay order is deterministic: timestamp first, then operation appearance order.
4. Full-session output JSON can be tens of MB. Use `--brief` for surveys, and query large JSON files with a small script instead of reading them whole.
5. Console output is forced to UTF-8, and the `--out` parent directory is created automatically.
6. Full scans read every rollout JSONL under `sessions/` — with a large history this takes about a minute; allow for that in command timeouts.
