Skip to content

hahahamid/claude-usage-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Claude Usage CLI

View your Claude Code API usage directly in your terminal πŸ“Š

A beautiful command-line tool to visualize Claude Code token usage, costs, and activity across all your projects.

Features

✨ Interactive Mode - Beautiful menu-driven interface with Claude branding πŸ“Š Token Breakdown - Input, Output, Cache Write, and Cache Read tokens by model πŸ“ Project Analytics - View usage breakdown by project πŸ’¬ Session Details - Drill down to individual session messages 🎨 Beautiful Output - Colorful tables with proper formatting and emojis ⚑ Fast & Lightweight - No external services, reads local Claude data

Quick Start

Using npx (Recommended)

Run instantly without installation:

npx claude-usage-cli

Installation

Install globally to use anywhere:

npm install -g claude-usage-cli

Then simply run:

claude-usage

Usage

Interactive Mode (Default)

Running claude-usage launches an interactive menu where you can explore your usage data:

claude-usage

The interactive mode features:

  • πŸ“Š Summary with total sessions, messages, tokens, and costs
  • πŸ“… Last 7 Days Activity
  • πŸ’Ž Token Usage by Model
  • πŸ“ All Projects view
  • πŸ”„ Refresh Data
  • Beautiful Claude ASCII art header in orange

Commands

Overview

Shows total usage statistics, token breakdown by model, and recent activity:

claude-usage overview

List Projects

View all projects with session counts and total costs:

claude-usage projects

View Project

See all sessions within a specific project:

claude-usage project /path/to/project

View Session

Get detailed message-level breakdown for a session:

claude-usage session <session-id>

# Or specify project
claude-usage session <session-id> --project /path/to/project

Configuration

Check current settings and data directory:

claude-usage config

Options

Custom Data Directory

By default, the tool reads from ~/.claude. To use a different location:

claude-usage --data-dir /custom/path/to/claude/data

Or set the CLAUDE_DATA_DIR environment variable:

export CLAUDE_DATA_DIR=/custom/path/to/claude/data
claude-usage

Example Output

Interactive Mode

   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•—      β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ•—   β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•”β•β•β•β•β•β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β•
  β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
  β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•‘     β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•
  β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—
   β•šβ•β•β•β•β•β•β•šβ•β•β•β•β•β•β•β•šβ•β•  β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•β•

           Usage Visualizer  ・  Track your AI costs

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

πŸ“Š Summary:
  πŸ’¬ Total Sessions:      32
  πŸ“¨ Total Messages:      5,393
  πŸ”’ Total Tokens Used:   141,115,796
  ⬆️  Total Input Tokens:  54,341,054
  ⬇️  Total Output Tokens: 12,326
  πŸ’° Estimated Cost:      $1063.1512

? What would you like to see? (Use arrow keys)
❯ πŸ“… Last 7 Days Activity
  πŸ’Ž Token Usage by Model
  πŸ“ All Projects
  ──────────────
  πŸ”„ Refresh Data
  ❌ Exit

Token Usage by Model

πŸ’Ž Token Usage by Model:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Model                 β”‚      Input β”‚ Output β”‚ Cache Write β”‚ Cache Read β”‚      Cost β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ opus-4-6              β”‚ 54,272,618 β”‚  4,678 β”‚     428,133 β”‚  1,735,051 β”‚ $825.0702 β”‚
β”‚ sonnet-4-5 (20250929) β”‚     17,478 β”‚    568 β”‚   1,852,448 β”‚ 21,403,174 β”‚  $13.4286 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

How It Works

Claude Usage CLI reads your local Claude Code data files:

  • stats-cache.json - Aggregated statistics
  • history.jsonl - Session metadata and names
  • projects/ - Individual session message logs

All data stays local. No external API calls or data transmission.

Development

Local Development

# Clone the repository
git clone <your-repo>
cd claude-usage-cli

# Install dependencies
npm install

# Build TypeScript
npm run build

# Run locally
node dist/index.js

# Or use tsx for development
npm run dev

Project Structure

src/
β”œβ”€β”€ index.ts          # Main CLI entry point
β”œβ”€β”€ types.ts          # TypeScript type definitions
β”œβ”€β”€ config.ts         # Configuration and data directory
β”œβ”€β”€ loader.ts         # Data loading from Claude files
β”œβ”€β”€ pricing.ts        # Token pricing and cost calculation
└── commands/         # CLI command implementations
    β”œβ”€β”€ interactive.ts # Interactive menu mode
    β”œβ”€β”€ overview.ts
    β”œβ”€β”€ projects.ts
    β”œβ”€β”€ project.ts
    β”œβ”€β”€ session.ts
    └── config.ts

Requirements

  • Node.js >= 18.0.0
  • Claude Code data directory (usually ~/.claude)

Publishing to npm

To make this available via npx for everyone:

  1. Create an npm account at npmjs.com
  2. Login locally: npm login
  3. Update package name to be unique (if needed)
  4. Publish: npm publish

Then users can run:

npx claude-usage-cli

License

MIT

Contributing

Contributions welcome! Please open an issue or PR.


Created by Hamid πŸ‘‹

Releases

No releases published

Packages

 
 
 

Contributors