Skill 65 · Extracting Session Data
Subchapter 65.5
README.mdMarkdown12 KBView on GitHub
Locates, lists, filters, and extracts structured data from Claude Code session logs. Designed for efficient access to single or multiple sessions.
This skill provides programmatic access to Claude Code’s native session logs stored in:
~/.claude/projects/{project-dir}/{session-id}.jsonlIt can:
You typically won’t invoke this skill directly. Other skills (like retrospecting) use it behind the scenes to access session data efficiently.
However, you might invoke it directly when you want to:
Can you list all my Claude sessions from the last week?
Show me which sessions had errors
What sessions are available for this project?
Extract tool usage statistics from my last sessionWhen you request session data, the skill will:
This skill returns raw data rather than analyzed insights:
Session: abc123-def456-ghi789
Total Lines: 450
User Messages: 12
Assistant Messages: 23
Tool Calls: 45
Errors: 2Other skills (like retrospecting) interpret this data to generate insights.
See all available sessions for your project:
Output formats: table (default), json, csv
Sort options: date (default), size, lines
# List all sessions (table format)
scripts/list-sessions.sh
# List with JSON output
scripts/list-sessions.sh --format json
# List sorted by size
scripts/list-sessions.sh --sort size
# List for specific project
scripts/list-sessions.sh /path/to/project --sort dateFind sessions matching specific criteria:
Available filter options:
--since DATE - Sessions modified since date (e.g., “2 days ago”, “2025-10-20”)--until DATE - Sessions modified until date--branch NAME - Sessions on specific git branch--min-size SIZE - Minimum file size (e.g., “1M”, “500K”)--max-size SIZE - Maximum file size--min-lines N - Minimum line count--max-lines N - Maximum line count--has-errors - Only sessions with failed tool calls--keyword WORD - Sessions containing keywordOutput formats: list (default), paths, json
# Recent sessions
scripts/filter-sessions.sh --since "2 days ago"
# Sessions with errors
scripts/filter-sessions.sh --has-errors
# Sessions on specific branch
scripts/filter-sessions.sh --branch main
# Large sessions with errors
scripts/filter-sessions.sh --min-lines 500 --has-errors
# Sessions on main branch in last week
scripts/filter-sessions.sh --branch main --since "7 days ago"
# Sessions containing specific keyword
scripts/filter-sessions.sh --keyword "authentication"
# Get paths only (for piping to other commands)
scripts/filter-sessions.sh --since "1 day ago" --format pathsPull specific information from sessions:
Available extraction types:
metadata - Session info (ID, timestamps, branch, working dir)user-prompts - All user messagestool-usage - Tool call statistics (which tools, how many times)errors - Failed tool calls with timestampsthinking - Thinking blocks (if extended thinking enabled)text-responses - Assistant text responses onlystatistics - Session metrics (message counts, tool calls, errors)all - Combined extraction of key data# Session metadata
scripts/extract-data.sh --type metadata --session SESSION_ID
# Statistics (message counts, tool calls, errors)
scripts/extract-data.sh --type statistics --session SESSION_ID
# All errors
scripts/extract-data.sh --type errors --session SESSION_ID
# Tool usage statistics
scripts/extract-data.sh --type tool-usage --session SESSION_ID
# User prompts (with optional limit)
scripts/extract-data.sh --type user-prompts --session SESSION_ID --limit 10
# Extract from all sessions (omit --session flag)
scripts/extract-data.sh --type statistics
# Extract from different project
scripts/extract-data.sh --type metadata --project /path/to/projectplugins/claude-retrospective/skills/extracting-session-data/
├── README.md # This file (user documentation)
├── SKILL.md # Instructions for Claude
└── scripts/
├── locate-logs.sh # Find log directories and files
├── list-sessions.sh # Enumerate sessions with metadata
├── extract-data.sh # Extract structured data from logs
└── filter-sessions.sh # Filter sessions by criteriaSession logs themselves are stored by Claude Code in:
~/.claude/projects/{project-dir}/{session-id}.jsonlClaude Code calculates the log directory from your working directory:
/ with -~/.claude/projects/{transformed-path}/Example:
Working Directory: /Users/you/projects/myapp
Project Identifier: -Users-you-projects-myapp
Logs Directory: ~/.claude/projects/-Users-you-projects-myapp/All scripts in this skill handle this transformation automatically.
“What sessions are available?”
List all sessions: scripts/list-sessions.sh“Show me recent sessions with errors”
scripts/filter-sessions.sh --since "7 days ago" --has-errors“How much data is in my last session?”
scripts/extract-data.sh --type statistics --session SESSION_IDRetrospective Skill uses this skill to:
Future Skills could use it to:
brew install jqIf jq is not installed, scripts will display installation instructions.
This skill requires Claude Code’s native session logs. These are automatically created by Claude Code when you use it. No manual setup needed.
~/.claude/projects/If your sessions contained sensitive data:
~/.claude/projects/ directoryAll scripts exit with non-zero status on errors and output messages to stderr. You can check exit status in bash:
# Check if logs exist before processing
if ! scripts/locate-logs.sh /path/to/project &>/dev/null; then
echo "Project has no session logs"
fiCommon errors:
# Logs directory doesn't exist
scripts/locate-logs.sh /nonexistent/project
# Error: Logs directory not found: ~/.claude/projects/-nonexistent-project
# Session file not found
scripts/extract-data.sh --type metadata --session invalid-id
# Error: Session file not found: ~/.claude/projects/-path/invalid-id.jsonl
# Missing required argument
scripts/extract-data.sh --session abc123
# Error: --type is required
# jq not installed
scripts/extract-data.sh --type metadata --session abc123
# Error: jq is required but not installed. Install with: brew install jqCause: No sessions exist for the current project yet, or you’re in a different directory.
Solution:
ls ~/.claude/projects/Cause: Session ID doesn’t exist or is incorrect.
Solution:
scripts/list-sessions.shCause: The jq JSON parser is not installed.
Solution:
# macOS
brew install jq
# Linux (Ubuntu/Debian)
sudo apt-get install jq
# Linux (Fedora/RHEL)
sudo dnf install jqCause: Filter criteria are too restrictive.
Solution:
scripts/list-sessions.shscripts/filter-sessions.sh --helpGoal: See what you’ve worked on in the last 3 days
scripts/filter-sessions.sh --since "3 days ago"Output:
Found 5 matching session(s):
Session: abc123...
Size: 2.5M
Lines: 1250
Modified: 2025-10-24 14:30:00
Branch: feature/auth
Session: def456...
Size: 1.2M
Lines: 600
Modified: 2025-10-23 09:15:00
Branch: main
...Goal: Find all sessions with errors and see what failed
# Find sessions with errors
scripts/filter-sessions.sh --has-errors --since "7 days ago"
# Extract errors from specific session
scripts/extract-data.sh --type errors --session abc123Goal: See which tools you use most often
# Get tool usage from multiple recent sessions
for session in $(scripts/filter-sessions.sh --since "7 days ago" --format paths | xargs -n1 basename -s .jsonl); do
echo "Session: $session"
scripts/extract-data.sh --type tool-usage --session $session
echo ""
doneThis skill is designed as a utility skill for other skills to use:
Uses extracting-session-data to:
Could use extracting-session-data to:
Be specific with filters to reduce processing:
# Good: Narrow scope
scripts/filter-sessions.sh --branch main --since "2 days ago" --has-errors
# Less efficient: Processes all sessions
scripts/filter-sessions.shBefore extracting from multiple sessions, check sizes:
scripts/list-sessions.sh --sort sizeThis helps you understand how much data you’re working with.
Don’t extract everything if you only need specific data:
# Good: Targeted extraction
scripts/extract-data.sh --type statistics
# Less efficient: Extract all data
scripts/extract-data.sh --type allPlanned improvements:
Found an issue or have a suggestion?
scripts/ directoryNearby