Use sessions analyze --provider cursor|codex --include-turns --extract-only
as a local session extraction tool. It returns transcript snippets, artifacts,
and provenance; keep interpretation separate from extraction.
Workflow
- Start narrow. Choose
--days,--workspace,--query, or repeatable--turn-querybefore scanning transcript evidence. - Use
--turn-queryfor user-turn text. Starter terms by goal: references/turn-queries.md. - Use
--extract-onlyfor investigation so index metadata does not bury the matching turns. - Scan table output first. Use
--evidence-limitto keep the table small. Use--format jsonwhen handing extracted evidence to another agent. - Inspect
matches,matchedQueries,artifacts,sessionId, andturnIndex. - Open the source only when snippets are not enough:
sessions cursor show <sessionId>orsessions codex show <sessionId>. - Report extracted facts first; label any interpretation separately.
Modes
- Targeted lookup:
--extract-only --turn-query <term>returns matching user turns without index-analysis sections. - Related terms: repeat
--turn-query; matching uses OR semantics andmatchedQueriesrecords the exact terms that hit. - Broad scan: omit
--turn-queryto get groupedpatterns; use this when you do not yet know the terms to search. - Metadata filter: use
--queryfor title, id, workspace, or first user query; it does not search all transcript turns. - Diagnostics: add
--include-automationonly when worker/subagent sessions are part of the question.
Command Patterns
Recent workspace scan:
sessions analyze --provider cursor --include-turns --extract-only --days 30 --workspace /path/to/repo
Use Codex history:
sessions codex reindex
sessions analyze --provider codex --include-turns --extract-only --turn-query "verify"
Find turns mentioning verification:
sessions analyze --provider cursor --include-turns --extract-only --turn-query "verify"
Find how-to questions:
sessions analyze --provider cursor --include-turns --extract-only --turn-query "how to" --days 30
Find related exact terms:
sessions analyze --provider cursor --include-turns --extract-only --turn-query "verify" --turn-query "validate" --turn-query "check"
JSON handoff:
sessions analyze --provider cursor --include-turns --extract-only --turn-query "review" --format json
Small table preview:
sessions analyze --provider cursor --include-turns --extract-only --turn-query "review" --evidence-limit 5
--query filters sessions by indexed metadata: title, id, workspace, or first
user query. --turn-query searches user-turn transcript text.
Running --include-turns without --days, --workspace, --query, or
--turn-query scans all matching cached transcripts and prints a warning.
Recommendations
- Turn-query categories and examples: references/turn-queries.md.
- Prefer exact words and short phrases. Try adjacent terms in the same category when a phrase returns zero matches.
- Use repeatable
--turn-queryfor synonyms instead of broadening into fuzzy or semantic search. - Keep table output small with
--evidence-limit; JSON keeps the fullmatchesand artifact arrays for agent handoff. - Use
sessions cursor show <sessionId>orsessions codex show <sessionId>for the 1-2 most relevant matches instead of opening every result. - Codex indexing uses
~/.codex/state_5.sqliteas the source of truth and only falls back to~/.codex/sqlite/state_5.sqliteif the root DB is missing. - Codex metadata/evidence may clean a leading injected first-turn preamble
using the DB first user message. Use
sessions codex show <sessionId>when raw rollout transcript fidelity matters. - Treat
patternsas recurrence hints only. Do not treat output as a recommendation.
Useful Questions
- What user turns match this term?
- Which snippets show the repeated request?
- Which files, commands, PRs, branches, plans, or URLs appear?
- Which session ids and turn indexes should be opened for more context?
- Which requested information is missing from snippets and needs
sessions cursor showorsessions codex show? - Did planning or review workflows route to the expected skills?
- Which skills have zero invokes over 90 days?
Evaluation
Workflow and skill audits: references/audit-examples.md. Exploration turn queries: references/turn-queries.md. Coordinator fixtures (e.g. planning-workflow/references/routing.md) define expected routing.
Reading Output
matches: flat turn-query hits with snippets, artifacts, and provenance.matchedQueries: exact query terms that matched that user turn.patterns: grouped broad-scan evidence; treat support as recurrence, not importance.artifacts: extracted paths, commands, PRs, branches, plans, and URLs.turnIndex: full transcript turn index, including assistant and tool turns.--evidence-limit: caps table match rows and pattern examples/artifacts; it does not truncate JSONmatches.
Keep privacy boundaries: summarize sensitive snippets; do not quote secrets, tokens, or private transcript text.
Report
Include:
Commands runFilters usedMatching snippetsArtifacts foundSession ids / turn indexesMissing context