Overview
The data loader module provides functions for loading and parsing Claude Code usage data from JSONL files stored in Claude data directories. It handles data aggregation for daily, monthly, weekly, session-based, and session block reporting.Core Functions
getClaudePaths()
Get Claude data directories to search for usage data.Array of valid Claude data directory paths
- When
CLAUDE_CONFIG_DIRis set: uses only those paths - When not set: uses default paths (
~/.config/claudeand~/.claude) - Throws error if no valid directories found
extractProjectFromPath()
Extract project name from Claude JSONL file path.Absolute path to JSONL file
Project name extracted from path, or “unknown” if malformed
loadDailyUsageData()
Loads and aggregates Claude usage data by day.Configuration for loading and filtering data
Array of daily usage summaries sorted by date
Custom path to Claude data directory
Cost calculation mode (default: ‘auto’)
Sort order for dates (default: ‘desc’)
Use offline mode for pricing (default: false)
Group data by project instead of aggregating (default: false)
Filter to specific project name
Start date filter (YYYYMMDD format)
End date filter (YYYYMMDD format)
Timezone for date grouping (e.g., ‘UTC’, ‘America/New_York’)
Locale for date/time formatting (e.g., ‘en-US’, ‘ja-JP’)
Date in YYYY-MM-DD format
Total input tokens for the day
Total output tokens for the day
Total cache creation tokens
Total cache read tokens
Total cost in USD
Array of unique model names used
Per-model usage breakdowns
Project name (when groupByProject is enabled)
loadMonthlyUsageData()
Loads and aggregates Claude usage data by month.Configuration for loading and filtering data
Array of monthly usage summaries sorted by month
Month in YYYY-MM format
Total input tokens for the month
Total output tokens for the month
Total cache creation tokens
Total cache read tokens
Total cost in USD
Array of unique model names used
Per-model usage breakdowns
Project name (when groupByProject is enabled)
loadWeeklyUsageData()
Loads and aggregates Claude usage data by week.Configuration including week start day
Array of weekly usage summaries sorted by week
Start of week for weekly aggregation (e.g., ‘sunday’, ‘monday’)
Week start date in YYYY-MM-DD format
Total input tokens for the week
Total output tokens for the week
Total cache creation tokens
Total cache read tokens
Total cost in USD
Array of unique model names used
Per-model usage breakdowns
loadSessionData()
Loads and aggregates Claude usage data by session.Configuration for loading and filtering data
Array of session usage summaries sorted by last activity
Unique session identifier
Project path for the session
Total input tokens for the session
Total output tokens for the session
Total cache creation tokens
Total cache read tokens
Total cost in USD
Date of last activity (YYYY-MM-DD)
Claude Code versions used in session
Array of unique model names used
Per-model usage breakdowns
loadSessionUsageById()
Load usage data for a specific session by sessionId.The session ID to load data for (matches JSONL filename)
Cost calculation mode (default: ‘auto’)
Use offline pricing data (default: false)
Usage data for the session or null if not found
Total cost for the session in USD
Array of raw usage data entries
loadSessionBlockData()
Loads usage data organized into session blocks (5-hour billing periods).Configuration including session duration
Array of session blocks with usage and cost information
Session block duration in hours (default: 5)
Block start time
Block end time
Total input tokens in block
Total output tokens in block
Total cache creation tokens
Total cache read tokens
Total cost in USD
Time when usage limit resets
calculateContextTokens()
Calculate context tokens from transcript file.Path to the transcript JSONL file
Model identifier for context limit lookup
Use offline mode (default: false)
Context token information or null if unavailable
Total input tokens used
Percentage of context limit used (0-100)
Model’s context limit
Utility Functions
createUniqueHash()
Create a unique identifier for deduplication using message ID and request ID.Usage data entry
Hash string or null if IDs are missing
getEarliestTimestamp()
Extract the earliest timestamp from a JSONL file.Path to JSONL file
Earliest timestamp or null if not found
sortFilesByTimestamp()
Sort files by their earliest timestamp.Array of file paths
Sorted array of file paths (oldest first)
globUsageFiles()
Glob files from multiple Claude paths in parallel.Array of Claude base paths
Array of file paths with their base directories
Absolute file path
Base directory path
Types
UsageData
Type definition for Claude usage data entries from JSONL files.ModelBreakdown
Type definition for model-specific usage breakdown.Cost Calculation Modes
auto (Default)
Uses pre-calculated costUSD when available, otherwise calculates from tokens using model pricing.
calculate
Always calculates costs from token counts using model pricing, ignoring costUSD.
display
Always uses pre-calculated costUSD values, shows 0 for missing costs.
Date Filtering
All date filters useYYYYMMDD format:
Environment Variables
CLAUDE_CONFIG_DIR
Custom Claude data directory paths (comma-separated):
~/.config/claude/projects/~/.claude/projects/