This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Testing and Quality:
bun test- Run all testsbun run lint- Lint code with Biomebun run format- Format code with Biome (writes changes)bun typecheck- Type check with TypeScript
Build and Release:
bun run build- Build distribution files with tsdownbun run release- Full release workflow (lint + typecheck + test + build + version bump)
Development Usage:
bun run start daily- Show daily usage reportbun run start monthly- Show monthly usage reportbun run start session- Show session-based usage reportbun run start daily --json- Show daily usage report in JSON formatbun run start monthly --json- Show monthly usage report in JSON formatbun run start session --json- Show session usage report in JSON formatbun run start daily --mode <mode>- Control cost calculation mode (auto/calculate/display)bun run start monthly --mode <mode>- Control cost calculation mode (auto/calculate/display)bun run start session --mode <mode>- Control cost calculation mode (auto/calculate/display)bun run ./src/index.ts- Direct execution for development
Cost Calculation Modes:
auto(default) - Use pre-calculated costUSD when available, otherwise calculate from tokenscalculate- Always calculate costs from token counts using model pricing, ignore costUSDdisplay- Always use pre-calculated costUSD values, show 0 for missing costs
This is a CLI tool that analyzes Claude Code usage data from local JSONL files stored in ~/.claude/projects/. The architecture follows a clear separation of concerns:
Core Data Flow:
- Data Loading (
data-loader.ts) - Parses JSONL files from Claude's local storage, including pre-calculated costs - Token Aggregation (
calculate-cost.ts) - Utility functions for aggregating token counts and costs - Command Execution (
commands/) - CLI subcommands that orchestrate data loading and presentation - CLI Entry (
index.ts) - Gunshi-based CLI setup with subcommand routing
Output Formats:
- Table format (default): Pretty-printed tables with colors for terminal display
- JSON format (
--json): Structured JSON output for programmatic consumption
Key Data Structures:
- Raw usage data is parsed from JSONL with timestamp, token counts, and pre-calculated costs
- Data is aggregated into daily summaries, monthly summaries, or session summaries
- Sessions are identified by directory structure:
projects/{project}/{session}/{file}.jsonl
External Dependencies:
- Uses local timezone for date formatting
- CLI built with
gunshiframework, tables withcli-table3 - LiteLLM Integration: Cost calculations depend on LiteLLM's pricing database for model pricing data
- Uses Biome for formatting with tab indentation and double quotes
- TypeScript with strict mode and bundler module resolution
- No console.log allowed except where explicitly disabled with biome-ignore
- Error handling: silently skips malformed JSONL lines during parsing
- File paths always use Node.js path utilities for cross-platform compatibility
Supported Claude 4 Models (as of 2025):
claude-sonnet-4-20250514- Latest Claude 4 Sonnet modelclaude-opus-4-20250514- Latest Claude 4 Opus model
Model Naming Convention:
- Pattern:
claude-{model-type}-{generation}-{date} - Example:
claude-sonnet-4-20250514(NOTclaude-4-sonnet-20250514) - The generation number comes AFTER the model type
Testing Guidelines:
- All test files must use current Claude 4 models, not outdated Claude 3 models
- Test coverage should include both Sonnet and Opus models for comprehensive validation
- Model names in tests must exactly match LiteLLM's pricing database entries
- When adding new model tests, verify the model exists in LiteLLM before implementation
- Tests depend on real pricing data from LiteLLM - failures may indicate model availability issues
LiteLLM Integration Notes:
- Cost calculations require exact model name matches with LiteLLM's database
- Test failures often indicate model names don't exist in LiteLLM's pricing data
- Future model updates require checking LiteLLM compatibility first
- The application cannot calculate costs for models not supported by LiteLLM
- gunshi
- do not use console.log. use logger.ts instead
Do what has been asked; nothing more, nothing less. NEVER create files unless they're absolutely necessary for achieving your goal. ALWAYS prefer editing an existing file to creating a new one. NEVER proactively create documentation files (*.md) or README files. Only create documentation files if explicitly requested by the User. Dependencies should always be added as devDependencies unless explicitly requested otherwise.