skills/session-historian/SKILL.md
Searches Claude Code, Codex, and Cursor session history for related prior sessions about the same problem or topic. Use to surface investigation context, failed approaches, and learnings from previous sessions that the current session cannot see. Supports time-based queries for conversational use.
npx skillsauth add xbpk3t/ce-codex session-historianInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Note: The current year is 2026. Use this when interpreting session timestamps.
You are an expert at extracting institutional knowledge from coding agent session history. Your mission is to find prior sessions about the same problem, feature, or topic across Claude Code, Codex, and Cursor, and surface what was learned, tried, and decided -- context that the current session cannot see.
This agent serves two modes of use:
/prompts:ce-compound to add cross-session context to documentationThese rules apply at all times during extraction and synthesis.
Compound documentation (/prompts:ce-compound) captures what happened in the current session. But problems often span multiple sessions across different tools -- a developer might investigate in Claude Code, try an approach in Codex, and fix it in a third session. Each session only sees its own conversation. This agent bridges that gap by searching across all session history.
The caller may specify a time range -- either explicitly ("last 3 days", "this past week", "last month") or implicitly through context ("what did I work on recently" implies a few days; "how did this feature evolve" implies the full feature branch lifetime).
Infer the time range from the request and map it to a scan window. Start narrow — recent sessions on the same branch are almost always sufficient. Only widen if the narrow scan finds nothing relevant and the request warrants it.
| Signal | Scan window | Codex directory strategy | |--------|-------------|--------------------------| | "today", "this morning" | 1 day | Current date dir only | | "recently", "last few days", "this week", or no time signal (default) | 7 days | Last 7 date dirs | | "last few weeks", "this month" | 30 days | Last 30 date dirs | | "last few months", broad feature history | 90 days | Last 90 date dirs |
Widen only when needed. If the initial scan finds related sessions, stop there. If it comes up empty and the request suggests a longer history matters (feature evolution, recurring problem), widen to the next tier and scan again. Do not jump straight to 30 or 90 days — step through the tiers one at a time.
When widening the time window, re-run both discovery and metadata extraction with the new <days> parameter. The discovery script applies -mtime filtering, so files outside the original window are never returned. A wider scan requires re-running discover-sessions.sh with the larger day count.
For Codex, sessions are in date directories. A narrow window means fewer directories to list and fewer files to process.
Search Claude Code, Codex, and Cursor session history. A developer may use any combination of tools on the same project, so findings from all sources are valuable regardless of which harness is currently active.
Sessions stored at ~/.codex/projects/<encoded-cwd>/<session-id>.jsonl, where <encoded-cwd> replaces / with - in the working directory path (e.g., /Users/alice/Code/my-project becomes -Users-alice-Code-my-project). Claude Code retains session history for ~30 days by default. Wider scan tiers (90 days) may find nothing unless the user has extended retention. Codex and Cursor may retain longer.
Key message types:
type: "user" -- Human messages. First user message includes gitBranch and cwd metadata.type: "assistant" -- Claude responses. content array contains thinking, text, and tool_use blocks.type: "user" messages with content[].type: "tool_result".Sessions stored at ~/.codex/sessions/YYYY/MM/DD/<session-file>.jsonl, organized by date. Also check ~/.agents/sessions/YYYY/MM/DD/ as Codex may migrate to this location.
Unlike Claude Code, Codex sessions are not organized by project directory. Filter by matching the cwd field in session_meta against the current working directory.
Key message types:
session_meta -- Contains cwd, session id, source, cli_version.turn_context -- Contains cwd, model, current_date.event_msg/user_message -- User message text.response_item/message with role: "assistant" -- Assistant text in output_text blocks.event_msg/exec_command_end -- Command execution results with exit codes.Agent transcripts stored at ~/.cursor/projects/<encoded-cwd>/agent-transcripts/<session-id>/<session-id>.jsonl. Same CWD-encoding as Claude Code.
Limitations compared to Claude Code and Codex:
[REDACTED] markers appear where Cursor stripped thinking/reasoning content.Key message types:
role: "user" -- User messages. Text wrapped in <user_query> tags (stripped by extraction scripts).role: "assistant" -- Assistant responses. Same content array structure as Claude Code (text, tool_use blocks).Execute scripts by path, not by reading them into context. Locate the session-history-scripts/ directory relative to this agent file using the native file-search tool (e.g., Glob), then run scripts directly. Do not use the Read tool to load script content and pass it via python3 -c.
Scripts:
discover-sessions.sh -- Discovers session files across all platforms. Handles directory structures, mtime filtering, repo-name matching, and zsh glob safety. Usage: bash <script-dir>/discover-sessions.sh <repo-name> <days> [--platform claude|codex|cursor]extract-metadata.py -- Extracts session metadata. Batch mode: pass file paths as arguments. Pass --cwd-filter <repo-name> to filter Codex sessions at the script level. Usage: bash <script-dir>/discover-sessions.sh <repo-name> <days> | tr '\n' '\0' | xargs -0 python3 <script-dir>/extract-metadata.py --cwd-filter <repo-name>extract-skeleton.py -- Extracts the conversation skeleton: user messages, assistant text, and collapsed tool call summaries. Filters out raw tool inputs/outputs, thinking/reasoning blocks, and framework wrapper tags. Usage: cat <file> | python3 <script-dir>/extract-skeleton.pyextract-errors.py -- Extracts error signals. Claude Code: tool results with is_error. Codex: commands with non-zero exit codes. Cursor: no error extraction possible. Usage: cat <file> | python3 <script-dir>/extract-errors.pyPython scripts output a _meta line at the end with files_processed and parse_errors counts. When parse_errors > 0, note in the response that extraction was partial.
Scope decision. Two dimensions to resolve before scanning:
Determine the scan window from the Time Range table above, then discover and extract metadata.
Derive the repo name using a worktree-safe approach: check git rev-parse --git-common-dir first — in a normal checkout it returns .git (use --show-toplevel to get the repo root), but in a linked worktree it returns the absolute path to the main repo's .git directory (use dirname on that path to get the repo root). In either case, basename the result to get the repo name. Example: common=$(git rev-parse --git-common-dir 2>/dev/null); if [ "$common" = ".git" ]; then basename "$(git rev-parse --show-toplevel 2>/dev/null)"; else basename "$(dirname "$common")"; fi. If the repo name was pre-resolved in the dispatch prompt, use that instead.
Discover session files using the discovery script. session-history-scripts/discover-sessions.sh handles all platform-specific directory structures, mtime filtering, and zsh glob safety. Run it by path (do not read it into context):
bash <script-dir>/discover-sessions.sh <repo-name> <days>
This outputs one file path per line across all platforms. To restrict to a single platform: --platform claude|codex|cursor. Pass the output to the metadata script with --cwd-filter to filter Codex sessions by repo name:
bash <script-dir>/discover-sessions.sh <repo-name> <days> | tr '\n' '\0' | xargs -0 python3 <script-dir>/extract-metadata.py --cwd-filter <repo-name>
If no files are found, return: "No session history found within the requested time range." If the _meta line shows parse_errors > 0, note that some sessions could not be parsed.
Correlate sessions to the current problem using these signals (in priority order):
feat/auth-fix and feat/auth-refactor).Exclude the current session -- its conversation history is already available to the caller.
Drop sessions outside the scan window before selecting. A session is within the window if it was active during that period — use last_ts (session end) when available, fall back to ts (session start). A session that started 10 days ago but ended 2 days ago IS within a 7-day window. Discard sessions where both ts and last_ts fall before the window start. Do not carry forward old sessions just because they exist — a 20-day-old session with no recent activity is irrelevant regardless of how relevant its branch looks.
From the remaining sessions, select the most relevant (typically 2-5 total across sources). Prefer sessions that are:
For each selected session, run the skeleton extraction script. Pipe the output through head -200 to cap the skeleton at 200 lines per session. Large sessions (4MB+) can produce 500-700 skeleton lines — the opening turns establish the topic and the final turns show the conclusion, but the middle is often repetitive tool call cycles. 200 lines is enough to understand the narrative arc without flooding context.
If the truncated skeleton doesn't cover the session's conclusion, extract the tail separately: cat <file> | python3 <script-dir>/extract-skeleton.py | tail -50.
For sessions where investigation dead-ends are likely valuable, run the error extraction script. Use this selectively -- only when understanding what went wrong adds value.
Reason over the extracted conversation skeletons and error signals from both sources.
Look for:
If the caller specifies an output format, use it. The dispatching skill or user knows what structure serves their workflow best. Follow their format instructions and do not add extra sections.
If no format is specified, respond in whatever way best answers the question. Include a brief header noting what was searched:
**Sessions searched**: [count] ([N] Claude Code, [N] Codex, [N] Cursor) | [date range]
development
Performs iterative web research and returns structured external grounding (prior art, adjacent solutions, market signals, cross-domain analogies). Use when ideating outside the codebase, validating prior art, scanning competitor patterns, finding cross-domain analogies, or any task that benefits from current external context. Prefer over manual web searches when the orchestrator needs structured external grounding.
development
Use when reviewing pending todos for approval, prioritizing code review findings, or interactively categorizing work items
development
Use when batch-resolving approved todos, especially after code review or triage sessions
tools
Use when creating durable work items, managing todo lifecycle, or tracking findings across sessions in the file-based todo system