Inputs
- Accept a session file name or full path from the user.
- Default session root to
~/.codex/sessions when only a file name is provided.
- Confirm the resolved file exists before running search commands.
Search Strategy
Each event is a single long JSON line. Avoid raw full-line searches that flood output.
- Count matches first.
- Pull short snippets around matches.
- Narrow snippets with a second filter.
- Open full context only after locating a precise target.
Always use at least one output limiter:
-c for counts
-o '.{0,60}pattern.{0,60}' for snippets
-M 200 or -M 500 to truncate long lines
| head -20 to cap result count
Core Commands
# 1) Count first
rg -c 'search_term' ~/.codex/sessions/<session-file>.jsonl
# 2) Snippets with local context
rg -o '.{0,60}search_term.{0,60}' ~/.codex/sessions/<session-file>.jsonl | head -20
# 3) Narrow further
rg -o '.{0,60}search_term.{0,60}' ~/.codex/sessions/<session-file>.jsonl | rg 'new_string'
# 4) Full context only when needed
rg '"name":"Edit".*search_term' ~/.codex/sessions/<session-file>.jsonl -M 500
Never run:
rg 'pattern' ~/.codex/sessions/<session-file>.jsonl
Useful Patterns
# Human user inputs
rg -o '.{0,40}"type":"user".{0,80}"userType":"external".{0,40}' <session.jsonl> | head -10
# Tool edits
rg -c '"name":"Edit"' <session.jsonl>
rg -o '.{0,60}"name":"Edit".{0,60}' <session.jsonl> | head -10
# Commands run by shell tools
rg -o '.{0,100}"command":"[^"]*".{0,40}' <session.jsonl> | head -20
# Mentions tied to file edits
rg -o '.{0,60}auth.{0,60}' <session.jsonl> | rg 'file_path'
JSONL Reference
Use these keys when filtering:
- Message roles:
"type":"user", "type":"assistant", "type":"tool_result"
- Human messages:
"userType":"external"
- Tool blocks:
"type":"tool_use"
- Common tool names:
"name":"Edit", "name":"Write", "name":"Bash", "name":"Task"
- Useful fields:
"timestamp", "agentId", "input"
Workflow
- Resolve session path from user input (
<name>.jsonl or full path).
- Ask for a target term if none is provided.
- Run count, then snippets, then narrowed snippets.
- Run full-context grep only for promising matches.
- Report concise findings with quoted snippets and exact command(s) used.
Safety
- Keep searches read-only.
- Redact secrets if surfaced in snippets.
- Prefer targeted patterns over broad regex to reduce accidental disclosure.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: y-search-codex3description: Search Codex session history stored in JSONL logs with ripgrep. Use when you need to find earlier user messages, assistant responses, tool calls, file edits, commands, or decisions from previous Codex sessions, especially when a session filename is provided. Use when this capability is needed.4---56## Inputs78- Accept a session file name or full path from the user.9- Default session root to `~/.codex/sessions` when only a file name is provided.10- Confirm the resolved file exists before running search commands.1112## Search Strategy1314Each event is a single long JSON line. Avoid raw full-line searches that flood output.15161. Count matches first.172. Pull short snippets around matches.183. Narrow snippets with a second filter.194. Open full context only after locating a precise target.2021Always use at least one output limiter:2223- `-c` for counts24- `-o '.{0,60}pattern.{0,60}'` for snippets25- `-M 200` or `-M 500` to truncate long lines26- `| head -20` to cap result count2728## Core Commands2930```bash31# 1) Count first32rg -c 'search_term' ~/.codex/sessions/<session-file>.jsonl3334# 2) Snippets with local context35rg -o '.{0,60}search_term.{0,60}' ~/.codex/sessions/<session-file>.jsonl | head -203637# 3) Narrow further38rg -o '.{0,60}search_term.{0,60}' ~/.codex/sessions/<session-file>.jsonl | rg 'new_string'3940# 4) Full context only when needed41rg '"name":"Edit".*search_term' ~/.codex/sessions/<session-file>.jsonl -M 50042```4344Never run:4546```bash47rg 'pattern' ~/.codex/sessions/<session-file>.jsonl48```4950## Useful Patterns5152```bash53# Human user inputs54rg -o '.{0,40}"type":"user".{0,80}"userType":"external".{0,40}' <session.jsonl> | head -105556# Tool edits57rg -c '"name":"Edit"' <session.jsonl>58rg -o '.{0,60}"name":"Edit".{0,60}' <session.jsonl> | head -105960# Commands run by shell tools61rg -o '.{0,100}"command":"[^"]*".{0,40}' <session.jsonl> | head -206263# Mentions tied to file edits64rg -o '.{0,60}auth.{0,60}' <session.jsonl> | rg 'file_path'65```6667## JSONL Reference6869Use these keys when filtering:7071- Message roles: `"type":"user"`, `"type":"assistant"`, `"type":"tool_result"`72- Human messages: `"userType":"external"`73- Tool blocks: `"type":"tool_use"`74- Common tool names: `"name":"Edit"`, `"name":"Write"`, `"name":"Bash"`, `"name":"Task"`75- Useful fields: `"timestamp"`, `"agentId"`, `"input"`7677## Workflow78791. Resolve session path from user input (`<name>.jsonl` or full path).802. Ask for a target term if none is provided.813. Run count, then snippets, then narrowed snippets.824. Run full-context grep only for promising matches.835. Report concise findings with quoted snippets and exact command(s) used.8485## Safety8687- Keep searches read-only.88- Redact secrets if surfaced in snippets.89- Prefer targeted patterns over broad regex to reduce accidental disclosure.9091---92> Converted and distributed by [TomeVault](https://tomevault.io/claim/eqtylab) — claim your Tome and manage your conversions.93<!-- tomevault:4.0:skill_md:2026-04-11 -->