ccusage 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -0
- package/dist/index.js +7086 -0
- package/dist/prompt-CYpzkwkf.js +852 -0
- package/docs/screenshot.png +0 -0
- package/package.json +22 -0
package/README.md
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# ccusage
|
|
2
|
+
|
|
3
|
+
> **ccusage(claude-code-usage)**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/ccusage)
|
|
6
|
+
|
|
7
|
+
<div align="center">
|
|
8
|
+
<img src="./docs/screenshot.png">
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
A CLI tool for analyzing Claude Code usage from local JSONL files.
|
|
12
|
+
|
|
13
|
+
Inspired by [this article](https://note.com/milliondev/n/n1d018da2d769) about tracking Claude Code usage costs.
|
|
14
|
+
|
|
15
|
+
## Features
|
|
16
|
+
|
|
17
|
+
- 📊 **Daily Report**: View token usage and costs aggregated by date
|
|
18
|
+
- 💬 **Session Report**: View usage grouped by conversation sessions
|
|
19
|
+
- 📅 **Date Filtering**: Filter reports by date range using `--since` and `--until`
|
|
20
|
+
- 📁 **Custom Path**: Support for custom Claude data directory locations
|
|
21
|
+
- 🎨 **Beautiful Output**: Colorful table-formatted display
|
|
22
|
+
- 📄 **JSON Output**: Export data in structured JSON format with `--json`
|
|
23
|
+
- 💰 **Cost Tracking**: Shows costs in USD for each day/session
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
### Quick Start (Recommended)
|
|
28
|
+
|
|
29
|
+
Run directly without installation:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# Using npx
|
|
33
|
+
npx ccusage@latest report daily
|
|
34
|
+
|
|
35
|
+
# Using bunx
|
|
36
|
+
bunx ccusage report daily
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Local Installation
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Install globally with npm
|
|
43
|
+
npm install -g ccusage
|
|
44
|
+
|
|
45
|
+
# Install globally with bun
|
|
46
|
+
bun install -g ccusage
|
|
47
|
+
|
|
48
|
+
# Then run
|
|
49
|
+
ccusage report daily
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Development Setup
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Clone the repository
|
|
56
|
+
git clone https://github.com/ryoppippi/ccusage.git
|
|
57
|
+
cd ccusage
|
|
58
|
+
|
|
59
|
+
# Install dependencies
|
|
60
|
+
bun install
|
|
61
|
+
|
|
62
|
+
# Run the tool
|
|
63
|
+
bun run report [subcommand] [options]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
### Daily Report (Default)
|
|
69
|
+
|
|
70
|
+
Shows token usage and costs aggregated by date:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
# Show all daily usage
|
|
74
|
+
ccusage report daily
|
|
75
|
+
# or: npx ccusage@latest report daily
|
|
76
|
+
# or: bunx ccusage report daily
|
|
77
|
+
|
|
78
|
+
# Filter by date range
|
|
79
|
+
ccusage report daily --since 20250525 --until 20250530
|
|
80
|
+
|
|
81
|
+
# Use custom Claude data directory
|
|
82
|
+
ccusage report daily --path /custom/path/to/.claude
|
|
83
|
+
|
|
84
|
+
# Output in JSON format
|
|
85
|
+
ccusage report daily --json
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Session Report
|
|
89
|
+
|
|
90
|
+
Shows usage grouped by conversation sessions, sorted by cost:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Show all sessions
|
|
94
|
+
ccusage report session
|
|
95
|
+
|
|
96
|
+
# Filter sessions by last activity date
|
|
97
|
+
ccusage report session --since 20250525
|
|
98
|
+
|
|
99
|
+
# Combine filters
|
|
100
|
+
ccusage report session --since 20250525 --until 20250530 --path /custom/path
|
|
101
|
+
|
|
102
|
+
# Output in JSON format
|
|
103
|
+
ccusage report session --json
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Options
|
|
107
|
+
|
|
108
|
+
All commands support the following options:
|
|
109
|
+
|
|
110
|
+
- `-s, --since <date>`: Filter from date (YYYYMMDD format)
|
|
111
|
+
- `-u, --until <date>`: Filter until date (YYYYMMDD format)
|
|
112
|
+
- `-p, --path <path>`: Custom path to Claude data directory (default: `~/.claude`)
|
|
113
|
+
- `-j, --json`: Output results in JSON format instead of table
|
|
114
|
+
- `-h, --help`: Display help message
|
|
115
|
+
- `-v, --version`: Display version
|
|
116
|
+
|
|
117
|
+
## Output Example
|
|
118
|
+
|
|
119
|
+
### Daily Report
|
|
120
|
+
```
|
|
121
|
+
╭──────────────────────────────────────────╮
|
|
122
|
+
│ │
|
|
123
|
+
│ Claude Code Token Usage Report - Daily │
|
|
124
|
+
│ │
|
|
125
|
+
╰──────────────────────────────────────────╯
|
|
126
|
+
|
|
127
|
+
┌──────────────────┬──────────────┬───────────────┬──────────────┬────────────┐
|
|
128
|
+
│ Date │ Input Tokens │ Output Tokens │ Total Tokens │ Cost (USD) │
|
|
129
|
+
├──────────────────┼──────────────┼───────────────┼──────────────┼────────────┤
|
|
130
|
+
│ 2025-05-30 │ 277 │ 31,456 │ 31,733 │ $17.45 │
|
|
131
|
+
│ 2025-05-29 │ 959 │ 39,662 │ 40,621 │ $16.37 │
|
|
132
|
+
│ 2025-05-28 │ 155 │ 21,693 │ 21,848 │ $8.33 │
|
|
133
|
+
├──────────────────┼──────────────┼───────────────┼──────────────┼────────────┤
|
|
134
|
+
│ Total │ 11,174 │ 720,366 │ 731,540 │ $336.17 │
|
|
135
|
+
└──────────────────┴──────────────┴───────────────┴──────────────┴────────────┘
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### Session Report
|
|
139
|
+
```
|
|
140
|
+
╭───────────────────────────────────────────────╮
|
|
141
|
+
│ │
|
|
142
|
+
│ Claude Code Token Usage Report - By Session │
|
|
143
|
+
│ │
|
|
144
|
+
╰───────────────────────────────────────────────╯
|
|
145
|
+
|
|
146
|
+
┌──────────────────────────────┬──────────────┬───────────────┬──────────────┬────────────┬───────────────┐
|
|
147
|
+
│ Project / Session │ Input Tokens │ Output Tokens │ Total Tokens │ Cost (USD) │ Last Activity │
|
|
148
|
+
├──────────────────────────────┼──────────────┼───────────────┼──────────────┼────────────┼───────────────┤
|
|
149
|
+
│ my-project │ 2,775 │ 186,645 │ 189,420 │ $98.40 │ 2025-05-26 │
|
|
150
|
+
│ └─ session-abc123... │ │ │ │ │ │
|
|
151
|
+
│ another-project │ 1,063 │ 41,421 │ 42,484 │ $20.08 │ 2025-05-29 │
|
|
152
|
+
│ └─ session-def456... │ │ │ │ │ │
|
|
153
|
+
├──────────────────────────────┼──────────────┼───────────────┼──────────────┼────────────┼───────────────┤
|
|
154
|
+
│ Total │ 11,174 │ 720,445 │ 731,619 │ $336.38 │ │
|
|
155
|
+
└──────────────────────────────┴──────────────┴───────────────┴──────────────┴────────────┴───────────────┘
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Requirements
|
|
159
|
+
|
|
160
|
+
- [Bun](https://bun.sh) runtime
|
|
161
|
+
- Claude Code usage history files (`~/.claude/projects/**/*.jsonl`)
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
# Run tests
|
|
167
|
+
bun test
|
|
168
|
+
|
|
169
|
+
# Type check
|
|
170
|
+
bun run typecheck
|
|
171
|
+
|
|
172
|
+
# Lint
|
|
173
|
+
bun run lint
|
|
174
|
+
|
|
175
|
+
# Format code
|
|
176
|
+
bun run format
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Project Structure
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
ccusage/
|
|
183
|
+
├── commands/
|
|
184
|
+
│ ├── daily.ts # Daily report command
|
|
185
|
+
│ └── session.ts # Session report command
|
|
186
|
+
├── data-loader.ts # JSONL data loading logic
|
|
187
|
+
├── index.ts # CLI entry point
|
|
188
|
+
├── logger.ts # Logger configuration
|
|
189
|
+
├── utils.ts # Shared utilities
|
|
190
|
+
└── package.json
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## License
|
|
194
|
+
|
|
195
|
+
MIT
|
|
196
|
+
|
|
197
|
+
## Author
|
|
198
|
+
|
|
199
|
+
[@ryoppippi](https://github.com/ryoppippi)
|
|
200
|
+
|
|
201
|
+
## Inspiration
|
|
202
|
+
|
|
203
|
+
This tool was inspired by [this excellent article](https://note.com/milliondev/n/n1d018da2d769) by [@milliondev](https://note.com/milliondev) about tracking Claude Code usage costs. The article demonstrates how to analyze Claude Code's local JSONL files using DuckDB to understand token usage patterns and costs.
|
|
204
|
+
|
|
205
|
+
While the original approach uses DuckDB for analysis, this tool provides a more accessible CLI interface with the same core functionality - analyzing the same JSONL files that Claude Code stores locally to give you insights into your usage patterns and costs.
|
|
206
|
+
|
|
207
|
+
## Acknowledgments
|
|
208
|
+
|
|
209
|
+
Thanks to [@milliondev](https://note.com/milliondev) for the original concept and approach to Claude Code usage analysis.
|