---
name: session-history
description: Search and summarize Claude Code, Codex, and opencode session history. Use when the user wants to look at past conversations, find sessions about a topic, or reconstruct a debugging narrative.
user_invocable: true
title: session-history
canonical_url: https://skilld.dev/gh/david-crespo/dotfiles/session-history
last_updated: 2026-10-27T15:12:45.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: [claude-sessions.sh](https://skilld.dev/api/skills-raw/david-crespo/dotfiles/session-history/claude-sessions.sh).
>
> If the user asked to install this Skill, run `npx skilld install david-crespo/dotfiles/session-history`. 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/session-history`, 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/david-crespo/dotfiles/session-history) 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/session-history`. 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/session-history --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/session-history --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.

# Session History

Search and summarize conversations from Claude Code, Codex, and opencode sessions.

If invoked with an argument, treat it as the search term, topic, or date to find across sessions.

## Helper script

This skill includes `claude-sessions.sh` for common operations on Claude Code,
Codex, and opencode sessions. Use it instead of writing ad hoc jq/rg/sqlite
pipelines. Run it without arguments for usage. The script auto-detects session
format by the identifier (file path vs. `opencode:` prefix).

```
claude-sessions.sh dir [path]                              # session dir for a project
claude-sessions.sh list [--all | path] [--days N]          # recent sessions
claude-sessions.sh search <term> [--all | path] [--days N] # find sessions by content
claude-sessions.sh bash <session> [filter]                  # extract Bash commands
claude-sessions.sh extract <session> <type>                 # type: user, assistant, bash, tools
claude-sessions.sh search-bash <term> [--all | path] [--days N]
                                                            # search + extract matching Bash commands
claude-sessions.sh search-extract <term> <type> [--all | path] [--days N]
                                                            # search + extract content by type
claude-sessions.sh summary [--all | path] [--days N]       # per-session user-msg & tool-call counts, first user message
claude-sessions.sh tools-audit <session> [--mode M] [--summary|--json|--truncate N]
                                                            # per-tool-call audit with permissionMode & outcome (Claude Code only)
```

The script lives next to this skill file. Run it with its full path:

    ~/.claude/skills/session-history/claude-sessions.sh

## Session file locations

**Claude Code** sessions are JSONL files stored per-project:

    ~/.claude/projects/-Users-david-oxide-<repo>/*.jsonl
    ~/.claude/projects/-Users-david-repos-<repo>/*.jsonl

The directory name is the absolute project path with all `/` replaced by `-`
(including the leading one, so it starts with `-`).

Sessions under the personal account (`CLAUDE_CONFIG_DIR=~/.claude-personal`)
live in the same layout under `~/.claude-personal/projects/`. The script
searches both: `dir` prints one line per account that has sessions for the
project, and summary/header output labels personal sessions `personal:`.

**Codex** sessions are JSONL files stored by date:

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

Codex also writes a sibling rollout for its approval-judge model ("guardian",
`session_meta.payload.source` is an object rather than `"cli"`) next to each
real session; the script drops those from `list`/`search`/`summary`. Since
about 2026-08-10, user turns exist only as `response_item` messages with
`role: user` (no `user_message` events), and shell commands are embedded as
`tools.exec_command({cmd: "..."})` calls inside `custom_tool_call` JavaScript.
The script handles both the old and new shapes.

**opencode** sessions are rows in a SQLite DB (not per-session files):

    ~/.local/share/opencode/opencode.db   (tables: session, message, part)

Since they have no file path, they flow through the pipeline as a synthetic
`opencode:<session_id>` identifier. The DB is the single source of truth — it
holds the full history, including sessions from before opencode migrated off
its old JSON file storage, so the legacy `storage/` JSON files are ignored.

With `--all`, commands include Claude Code, Codex, and opencode sessions.
Codex and opencode rows are distinguished by `codex:` / `opencode:` prefixes in
summary and header output. Like Codex, opencode sessions surface only with
`--all`, not when listing/searching a specific project path. `tools-audit` is
Claude Code only (no permissionMode concept in Codex/opencode).

## Process

1. **Use the helper script** for all three session formats. Only fall back to
   raw jq/sqlite for unusual extraction needs.

2. **Triage efficiently.** Use `claude-sessions.sh search` to narrow down
   candidates before extracting full content.

3. **Summarize selectively.** Extract only user messages first to understand
   the arc. Only extract assistant messages for the specific sessions the user
   cares about.

   For counting questions ("how many user messages today?", "how active
   was I in this repo?"), `summary` already emits `(U N, T M)` per session —
   sum those columns rather than writing ad hoc jq. The `U` count excludes
   tool-result messages; naive `type == "user"` filters conflate the two.

4. **For multi-session narratives**, establish chronological order using file
   timestamps or `session_meta` entries, then read sessions in order to build
   the story.

5. For large session files (>256KB), always use the helper script or `jq` via
   Bash rather than the Read tool.

## Auditing tool calls by permission mode

When asked to audit auto-mode (or acceptEdits / bypassPermissions) tool calls —
typically "what got approved under auto mode recently?" or "which commands did
auto mode reject?" — use `tools-audit`.

Transcripts record `permissionMode` on user-message entries and on
`permission-mode` events, so the script can tag every tool call with the mode
in effect at that moment. Outcomes come from the matching `tool_result`:
`denied-user` is an interactive rejection, `denied-rule` is a sandbox/allowlist
block, `error` is a tool-level failure, `ok` is anything that ran cleanly.
Caveat: within a mode the transcript does not distinguish "allowed by rule" from
"user clicked approve" — only that the call wasn't denied.

Typical recipe for "audit yesterday's auto-mode calls in repo X":

```bash
> /tmp/audit.jsonl
for DIR in $(claude-sessions.sh dir ~/oxide/X); do
  for f in "$DIR"/*.jsonl; do
    d=$(stat -f '%Sm' -t '%Y-%m-%d' "$f")
    [[ "$d" != "YYYY-MM-DD" ]] && continue
    claude-sessions.sh tools-audit "$f" --mode auto --json >> /tmp/audit.jsonl
  done
done

# Rejections and errors first:
jq -c 'select(.outcome != "ok")' /tmp/audit.jsonl

# Then audit the Bash stream for dubiousness:
jq -r 'select(.outcome == "ok" and .tool == "Bash") | .input.command' /tmp/audit.jsonl \
  | rg 'rm -rf|git push|--force|--no-verify|gh pr (create|edit|merge|close)|gh issue (create|edit|close)|npm publish|curl .*-X (POST|PUT|DELETE|PATCH)|sudo|chmod|chown|jj (abandon|squash|rebase)|killall|pkill'

# And Writes/Edits outside the project:
jq -r 'select(.outcome == "ok" and (.tool == "Write" or .tool == "Edit")) | [.tool, .input.file_path] | @tsv' /tmp/audit.jsonl \
  | rg -v 'oxide/X'
```

Always use `--json` when piping to another tool — the default TSV double-escapes
backslashes in the input column (it's meant for human reading), so downstream
`jq` on the input field will fail. Read the current CLAUDE.md and memory for
user-specific preferences (e.g. rules against plain `git`, squashing unprompted,
browsing neighboring repos speculatively) and call those out as soft violations
in addition to the hard-destructive patterns above.
