All skills
Skillintermediate
CLAUDE.md - ccusage Package
This is the main ccusage CLI package that provides usage analysis for Claude Code.
Claude Code Knowledge Pack7/10/2026
Overview
CLAUDE.md - ccusage Package
This is the main ccusage CLI package that provides usage analysis for Claude Code.
Package Overview
Name: ccusage
Description: Usage analysis tool for Claude Code
Type: CLI tool and library with TypeScript exports
Development Commands
Testing and Quality:
pnpm run test- Run all tests (using vitest via pnpm, watch mode disabled)pnpm run lint- Lint code using ESLintpnpm run format- Format and auto-fix code with ESLintpnpm typecheck- Type check with TypeScript
Build and Release:
pnpm run build- Build distribution files with tsdown (includes schema generation)pnpm run generate:schema- Generate JSON schema for configurationpnpm run prerelease- Full release workflow (lint + typecheck + build)
Development Usage:
pnpm run start daily- Show daily usage reportpnpm run start monthly- Show monthly usage reportpnpm run start session- Show session-based usage reportpnpm run start blocks- Show 5-hour billing blocks usage reportpnpm run start statusline- Show compact status line (Beta)- Add
--jsonflag for JSON output format - Add
--mode <mode>for cost calculation control (auto/calculate/display) - Add
--activeflag for blocks to show only active block with projections - Add
--recentflag for blocks to show last 3 days including active
CLI Testing:
pnpm run test:statusline- Test statusline with default test datapnpm run test:statusline:all- Test statusline with all model variantspnpm run test:statusline:sonnet4- Test with Sonnet 4 datapnpm run test:statusline:opus4- Test with Opus 4 datapnpm run test:statusline:sonnet41- Test with Sonnet 4.1 data
Architecture
This package contains the core ccusage functionality:
Key Modules:
src/index.ts- CLI entry point with Gunshi-based command routingsrc/data-loader.ts- Parses JSONL files from Claude data directoriessrc/calculate-cost.ts- Token aggregation and cost calculation utilitiessrc/commands/- CLI subcommands (daily, monthly, session, blocks, statusline)src/logger.ts- Logging utilities (use instead of console.log)
Data Flow:
- Loads JSONL files from
~/.claude/projects/and~/.config/claude/projects/ - Aggregates usage data by time periods or sessions
- Calculates costs using LiteLLM pricing database
- Outputs formatted tables or JSON
Testing Guidelines
- In-Source Testing: Tests are written in the same files using
if (import.meta.vitest != null)blocks - Vitest Globals Enabled: Use
describe,it,expectdirectly without imports - Model Testing: Use current Claude 4 models (sonnet-4, opus-4) in tests
- Mock Data: Uses
fs-fixturewithcreateFixture()for Claude data simulation - CRITICAL: NEVER use
await import()dynamic imports anywhere, especially in test blocks
Code Style
- Error Handling: Prefer
@praha/byethrow Resulttype over try-catch for functional error handling - Imports: Use
.tsextensions for local imports (e.g.,import { foo } from './utils.ts') - Exports: Only export what's actually used by other modules
- Dependencies: Add as
devDependenciesunless explicitly requested otherwise - No console.log: Use
logger.tsinstead
Post-Change Workflow: Always run these commands in parallel after code changes:
pnpm run format- Auto-fix and formatpnpm typecheck- Type checkingpnpm run test- Run tests
Environment Variables
LOG_LEVEL- Control logging verbosity (0=silent, 1=warn, 2=log, 3=info, 4=debug, 5=trace)CLAUDE_CONFIG_DIR- Custom Claude data directory paths (supports multiple comma-separated paths)
Dependencies
Because ccusage is distributed as a bundled CLI, keep all runtime libraries in devDependencies so the bundler captures them.
Key Runtime Dependencies:
gunshi- CLI frameworkcli-table3- Table formattingvalibot- Schema validation@praha/byethrow- Functional error handling
Key Dev Dependencies:
vitest- Testing frameworktsdown- TypeScript build tooleslint- Linting and formattingfs-fixture- Test fixture creation
Package Exports
The package provides multiple exports for library usage:
.- Main CLI entry point./calculate-cost- Cost calculation utilities./data-loader- Data loading functions./debug- Debug utilities./logger- Logging utilities./pricing-fetcher- LiteLLM pricing integration