Skip to content

ccusage / data-loader

data-loader

Fileoverview

Data loading utilities for Claude Code usage analysis

This 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, and session-based reporting.

Variables

VariableDescription
usageDataSchemaZod schema for validating Claude usage data from JSONL files
modelBreakdownSchemaZod schema for model-specific usage breakdown data
dailyUsageSchemaZod schema for daily usage aggregation data
sessionUsageSchemaZod schema for session-based usage aggregation data
monthlyUsageSchemaZod schema for monthly usage aggregation data

Functions

FunctionDescription
getClaudePathsGet all Claude data directories to search for usage data Supports multiple paths: environment variable (comma-separated), new default, and old default
formatDateFormats a date string to YYYY-MM-DD format
formatDateCompactFormats a date string to compact format with year on first line and month-day on second
createUniqueHashCreate a unique identifier for deduplication using message ID and request ID
getEarliestTimestampExtract the earliest timestamp from a JSONL file Scans through the file until it finds a valid timestamp
sortFilesByTimestampSort files by their earliest timestamp Files without valid timestamps are placed at the end
calculateCostForEntryCalculates cost for a single usage data entry based on the specified cost calculation mode
loadDailyUsageDataLoads and aggregates Claude usage data by day Processes all JSONL files in the Claude projects directory and groups usage by date
loadSessionDataLoads and aggregates Claude usage data by session Groups usage data by project path and session ID based on file structure
loadMonthlyUsageDataLoads and aggregates Claude usage data by month Uses daily usage data as the source and groups by month
loadSessionBlockDataLoads usage data and organizes it into session blocks (typically 5-hour billing periods) Processes all usage data and groups it into time-based blocks for billing analysis

Type Aliases

Type AliasDescription
UsageDataType definition for Claude usage data entries from JSONL files
ModelBreakdownType definition for model-specific usage breakdown
DailyUsageType definition for daily usage aggregation
SessionUsageType definition for session-based usage aggregation
MonthlyUsageType definition for monthly usage aggregation
DateFilterDate range filter for limiting usage data by date
LoadOptionsConfiguration options for loading usage data

Released under the MIT License.