ccusage 15.0.0 → 15.1.0
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 +29 -556
- package/dist/calculate-cost.d.ts +3 -2
- package/dist/{data-loader-B_ymgjWR.js → data-loader-BeaFK_sH.js} +14 -4
- package/dist/{data-loader-Bll0wMdK.d.ts → data-loader-DZczD-9E.d.ts} +1 -1
- package/dist/data-loader.d.ts +2 -2
- package/dist/data-loader.js +3 -3
- package/dist/{debug-2jwq04IT.js → debug-BmJuGBXC.js} +3 -3
- package/dist/debug.js +4 -4
- package/dist/index.js +6 -6
- package/dist/{logger-6I_KKR-u.js → logger-Cke8hliP.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-COnbPauf.js → mcp-DKqp_F9c.js} +312 -138
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +4 -4
- package/dist/{pricing-fetcher-CMyU5JUX.js → pricing-fetcher-Dm8hcn_h.js} +1 -1
- package/dist/pricing-fetcher.d.ts +1 -1
- package/dist/pricing-fetcher.js +2 -2
- package/package.json +1 -1
- /package/dist/{pricing-fetcher-CXnYw4TA.d.ts → pricing-fetcher-BZe7AafW.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<div align="center">
|
|
2
|
-
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/logo.svg" alt="ccusage logo" width="256" height="256">
|
|
2
|
+
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/public/logo.svg" alt="ccusage logo" width="256" height="256">
|
|
3
3
|
<h1>ccusage</h1>
|
|
4
4
|
</div>
|
|
5
5
|
|
|
@@ -7,44 +7,39 @@
|
|
|
7
7
|
<a href="https://npmjs.com/package/ccusage"><img src="https://img.shields.io/npm/v/ccusage?color=yellow" alt="npm version" /></a>
|
|
8
8
|
<a href="https://tanstack.com/stats/npm?packageGroups=%5B%7B%22packages%22:%5B%7B%22name%22:%22ccusage%22%7D%5D%7D%5D&range=30-days&transform=none&binType=daily&showDataMode=all&height=400"><img src="https://img.shields.io/npm/dy/ccusage" alt="NPM Downloads" /></a>
|
|
9
9
|
<a href="https://packagephobia.com/result?p=ccusage"><img src="https://packagephobia.com/badge?p=ccusage" alt="install size" /></a>
|
|
10
|
-
<a href="https://deepwiki.com/ryoppippi/ccusage"><img src="https://img.shields.io/badge/DeepWiki-ryoppippi%2Fccusage-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACwAAAAyCAYAAAAnWDnqAAAAAXNSR0IArs4c6QAAA05JREFUaEPtmUtyEzEQhtWTQyQLHNak2AB7ZnyXZMEjXMGeK/AIi+QuHrMnbChYY7MIh8g01fJoopFb0uhhEqqcbWTp06/uv1saEDv4O3n3dV60RfP947Mm9/SQc0ICFQgzfc4CYZoTPAswgSJCCUJUnAAoRHOAUOcATwbmVLWdGoH//PB8mnKqScAhsD0kYP3j/Yt5LPQe2KvcXmGvRHcDnpxfL2zOYJ1mFwrryWTz0advv1Ut4CJgf5uhDuDj5eUcAUoahrdY/56ebRWeraTjMt/00Sh3UDtjgHtQNHwcRGOC98BJEAEymycmYcWwOprTgcB6VZ5JK5TAJ+fXGLBm3FDAmn6oPPjR4rKCAoJCal2eAiQp2x0vxTPB3ALO2CRkwmDy5WohzBDwSEFKRwPbknEggCPB/imwrycgxX2NzoMCHhPkDwqYMr9tRcP5qNrMZHkVnOjRMWwLCcr8ohBVb1OMjxLwGCvjTikrsBOiA6fNyCrm8V1rP93iVPpwaE+gO0SsWmPiXB+jikdf6SizrT5qKasx5j8ABbHpFTx+vFXp9EnYQmLx02h1QTTrl6eDqxLnGjporxl3NL3agEvXdT0WmEost648sQOYAeJS9Q7bfUVoMGnjo4AZdUMQku50McDcMWcBPvr0SzbTAFDfvJqwLzgxwATnCgnp4wDl6Aa+Ax283gghmj+vj7feE2KBBRMW3FzOpLOADl0Isb5587h/U4gGvkt5v60Z1VLG8BhYjbzRwyQZemwAd6cCR5/XFWLYZRIMpX39AR0tjaGGiGzLVyhse5C9RKC6ai42ppWPKiBagOvaYk8lO7DajerabOZP46Lby5wKjw1HCRx7p9sVMOWGzb/vA1hwiWc6jm3MvQDTogQkiqIhJV0nBQBTU+3okKCFDy9WwferkHjtxib7t3xIUQtHxnIwtx4mpg26/HfwVNVDb4oI9RHmx5WGelRVlrtiw43zboCLaxv46AZeB3IlTkwouebTr1y2NjSpHz68WNFjHvupy3q8TFn3Hos2IAk4Ju5dCo8B3wP7VPr/FGaKiG+T+v+TQqIrOqMTL1VdWV1DdmcbO8KXBz6esmYWYKPwDL5b5FA1a0hwapHiom0r/cKaoqr+27/XcrS5UwSMbQAAAABJRU5ErkJggg==" alt="DeepWiki" /></a>
|
|
11
10
|
<a href="https://github.com/hesreallyhim/awesome-claude-code"><img src="https://awesome.re/mentioned-badge.svg" alt="Mentioned in Awesome Claude Code" /></a>
|
|
12
11
|
</p>
|
|
13
12
|
|
|
14
13
|
<div align="center">
|
|
15
|
-
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/screenshot.png">
|
|
14
|
+
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/public/screenshot.png">
|
|
16
15
|
</div>
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/blocks-live.png">
|
|
20
|
-
</div>
|
|
21
|
-
|
|
22
|
-
> **ccusage(claude-code-usage)**
|
|
23
|
-
|
|
24
|
-
A CLI tool for analyzing Claude Code usage from local JSONL files.
|
|
25
|
-
|
|
26
|
-
Inspired by [this article](https://note.com/milliondev/n/n1d018da2d769) about tracking Claude Code usage costs.
|
|
27
|
-
|
|
28
|
-
## What is `ccusage` (by NotebookLM)
|
|
29
|
-
|
|
30
|
-
<details>
|
|
31
|
-
<summary>Podcast</summary>
|
|
17
|
+
> Analyze your Claude Code token usage and costs from local JSONL files — incredibly fast and informative!
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<https://github.com/user-attachments/assets/7a00f2f3-82a7-41b6-a8da-e04b76b5e35a>
|
|
36
|
-
|
|
37
|
-
# 日本語
|
|
19
|
+
## Installation
|
|
38
20
|
|
|
39
|
-
|
|
21
|
+
```bash
|
|
22
|
+
npm i -g ccusage
|
|
23
|
+
```
|
|
40
24
|
|
|
41
|
-
|
|
25
|
+
## Usage
|
|
42
26
|
|
|
43
|
-
|
|
27
|
+
```bash
|
|
28
|
+
# Basic usage
|
|
29
|
+
ccusage # Show daily report (default)
|
|
30
|
+
ccusage daily # Daily token usage and costs
|
|
31
|
+
ccusage monthly # Monthly aggregated report
|
|
32
|
+
ccusage session # Usage by conversation session
|
|
33
|
+
ccusage blocks # 5-hour billing windows
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
# Live monitoring
|
|
36
|
+
ccusage blocks --live # Real-time usage dashboard
|
|
46
37
|
|
|
47
|
-
|
|
38
|
+
# Filters and options
|
|
39
|
+
ccusage daily --since 20250525 --until 20250530
|
|
40
|
+
ccusage daily --json # JSON output
|
|
41
|
+
ccusage daily --breakdown # Per-model cost breakdown
|
|
42
|
+
```
|
|
48
43
|
|
|
49
44
|
## Features
|
|
50
45
|
|
|
@@ -66,541 +61,15 @@ This tool helps you understand the value you're getting from your subscription b
|
|
|
66
61
|
- 🌐 **Offline Mode**: Use pre-cached pricing data without network connectivity with `--offline` (Claude models only)
|
|
67
62
|
- 🔌 **MCP Integration**: Built-in Model Context Protocol server for integration with other tools
|
|
68
63
|
|
|
69
|
-
##
|
|
70
|
-
|
|
71
|
-
⚠️ **This is NOT an official Claude tool** - it's an independent community project that analyzes locally stored usage data.
|
|
72
|
-
|
|
73
|
-
**Cost calculations are estimates only** and may not reflect actual billing:
|
|
74
|
-
|
|
75
|
-
- Costs shown are virtual/estimated based on token counts and model pricing data
|
|
76
|
-
- Actual costs may vary due to pricing changes, special rates, or billing adjustments
|
|
77
|
-
- We do not guarantee the accuracy of calculated costs
|
|
78
|
-
- For official billing information, always refer to your Claude account dashboard
|
|
79
|
-
|
|
80
|
-
## Limitations
|
|
81
|
-
|
|
82
|
-
- This tool only reads local JSONL files generated by Claude Code. If you use Claude Code with multiple devices, you need to ensure the JSONL files are synchronized across devices.
|
|
83
|
-
- API usage for tools like Web Search, Code Execution, and Image Analysis are not included in the token usage reports. The tool only tracks language model token usage.
|
|
84
|
-
|
|
85
|
-
## Installation
|
|
86
|
-
|
|
87
|
-
### Quick Start (Recommended)
|
|
88
|
-
|
|
89
|
-
Run directly without installation:
|
|
90
|
-
|
|
91
|
-
```bash
|
|
92
|
-
# Using npx
|
|
93
|
-
npx ccusage@latest
|
|
94
|
-
|
|
95
|
-
# Using bunx
|
|
96
|
-
bunx ccusage
|
|
97
|
-
|
|
98
|
-
# Using pnpm
|
|
99
|
-
pnpm dlx ccusage
|
|
100
|
-
|
|
101
|
-
# Using Deno with security flags
|
|
102
|
-
deno run -E -R=$HOME/.claude/projects/ -S=homedir -N='raw.githubusercontent.com:443' npm:ccusage@latest
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### Local Installation
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
# Install globally with npm
|
|
109
|
-
npm install -g ccusage
|
|
110
|
-
|
|
111
|
-
# Install globally with bun
|
|
112
|
-
bun install -g ccusage
|
|
113
|
-
|
|
114
|
-
# Then run
|
|
115
|
-
ccusage daily
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Development Setup
|
|
119
|
-
|
|
120
|
-
```bash
|
|
121
|
-
# Clone the repository
|
|
122
|
-
git clone https://github.com/ryoppippi/ccusage.git
|
|
123
|
-
cd ccusage
|
|
124
|
-
|
|
125
|
-
# Install dependencies
|
|
126
|
-
bun install
|
|
127
|
-
|
|
128
|
-
# Run the tool
|
|
129
|
-
bun run start [subcommand] [options]
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## Configuration
|
|
133
|
-
|
|
134
|
-
### Claude Data Directory Support
|
|
135
|
-
|
|
136
|
-
ccusage automatically detects and aggregates usage data from multiple Claude Code installation directories:
|
|
137
|
-
|
|
138
|
-
- **`~/.config/claude/projects/`** - New default location (Claude Code v1.0.30+)
|
|
139
|
-
- **`~/.claude/projects/`** - Legacy location (pre-v1.0.30)
|
|
140
|
-
|
|
141
|
-
> **Note**: The directory change from `~/.claude` to `~/.config/claude` in Claude Code v1.0.30 was an undocumented breaking change. ccusage handles both locations automatically to ensure compatibility across different Claude Code versions.
|
|
142
|
-
|
|
143
|
-
### Custom Paths
|
|
144
|
-
|
|
145
|
-
You can specify custom Claude data directories using the `CLAUDE_CONFIG_DIR` environment variable:
|
|
146
|
-
|
|
147
|
-
```bash
|
|
148
|
-
# Single custom path
|
|
149
|
-
export CLAUDE_CONFIG_DIR="/path/to/your/claude/data"
|
|
150
|
-
|
|
151
|
-
# Multiple paths (comma-separated)
|
|
152
|
-
export CLAUDE_CONFIG_DIR="/path/to/claude1,/path/to/claude2"
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
When `CLAUDE_CONFIG_DIR` is set, ccusage will use those paths instead of the default locations.
|
|
156
|
-
|
|
157
|
-
## Usage
|
|
158
|
-
|
|
159
|
-
### Daily Report (Default)
|
|
160
|
-
|
|
161
|
-
Shows token usage and costs aggregated by date:
|
|
162
|
-
|
|
163
|
-
```bash
|
|
164
|
-
# Show all daily usage
|
|
165
|
-
ccusage daily
|
|
166
|
-
# or: ccusage
|
|
167
|
-
# or: npx ccusage@latest daily
|
|
168
|
-
# or: bunx ccusage daily
|
|
169
|
-
|
|
170
|
-
# Filter by date range
|
|
171
|
-
ccusage daily --since 20250525 --until 20250530
|
|
172
|
-
|
|
173
|
-
# Set CLAUDE_CONFIG_DIR environment variable for custom data directory
|
|
174
|
-
export CLAUDE_CONFIG_DIR="/custom/path/to/.claude"
|
|
175
|
-
ccusage daily
|
|
176
|
-
|
|
177
|
-
# Output in JSON format
|
|
178
|
-
ccusage daily --json
|
|
179
|
-
|
|
180
|
-
# Control cost calculation mode
|
|
181
|
-
ccusage daily --mode auto # Use costUSD when available, calculate otherwise (default)
|
|
182
|
-
ccusage daily --mode calculate # Always calculate costs from tokens
|
|
183
|
-
ccusage daily --mode display # Always show pre-calculated costUSD values
|
|
184
|
-
|
|
185
|
-
# Control sort order
|
|
186
|
-
ccusage daily --order asc # Show oldest dates first
|
|
187
|
-
ccusage daily --order desc # Show newest dates first (default)
|
|
188
|
-
|
|
189
|
-
# Show per-model cost breakdown
|
|
190
|
-
ccusage daily --breakdown # Show cost breakdown by model (opus-4, sonnet-4, etc.)
|
|
191
|
-
|
|
192
|
-
# Use offline mode (no network required)
|
|
193
|
-
ccusage daily --offline # Use pre-cached pricing data
|
|
194
|
-
ccusage daily -O # Short alias for --offline
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
`ccusage` is an alias for `ccusage daily`, so you can run it without specifying the subcommand.
|
|
198
|
-
|
|
199
|
-
### Monthly Report
|
|
200
|
-
|
|
201
|
-
Shows token usage and costs aggregated by month:
|
|
202
|
-
|
|
203
|
-
```bash
|
|
204
|
-
# Show all monthly usage
|
|
205
|
-
ccusage monthly
|
|
206
|
-
|
|
207
|
-
# Filter by date range
|
|
208
|
-
ccusage monthly --since 20250101 --until 20250531
|
|
209
|
-
|
|
210
|
-
# Use custom Claude data directory
|
|
211
|
-
ccusage monthly --path /custom/path/to/.claude
|
|
212
|
-
|
|
213
|
-
# Or set CLAUDE_CONFIG_DIR environment variable
|
|
214
|
-
export CLAUDE_CONFIG_DIR="/custom/path/to/.claude"
|
|
215
|
-
ccusage monthly
|
|
216
|
-
|
|
217
|
-
# Output in JSON format
|
|
218
|
-
ccusage monthly --json
|
|
219
|
-
|
|
220
|
-
# Control cost calculation mode
|
|
221
|
-
ccusage monthly --mode auto # Use costUSD when available, calculate otherwise (default)
|
|
222
|
-
ccusage monthly --mode calculate # Always calculate costs from tokens
|
|
223
|
-
ccusage monthly --mode display # Always show pre-calculated costUSD values
|
|
224
|
-
|
|
225
|
-
# Control sort order
|
|
226
|
-
ccusage monthly --order asc # Show oldest months first
|
|
227
|
-
ccusage monthly --order desc # Show newest months first (default)
|
|
228
|
-
|
|
229
|
-
# Show per-model cost breakdown
|
|
230
|
-
ccusage monthly --breakdown # Show cost breakdown by model
|
|
231
|
-
|
|
232
|
-
# Use offline mode (no network required)
|
|
233
|
-
ccusage monthly --offline # Use pre-cached pricing data
|
|
234
|
-
ccusage monthly -O # Short alias for --offline
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### Session Report
|
|
238
|
-
|
|
239
|
-
Shows usage grouped by conversation sessions, sorted by cost:
|
|
240
|
-
|
|
241
|
-
```bash
|
|
242
|
-
# Show all sessions
|
|
243
|
-
ccusage session
|
|
244
|
-
|
|
245
|
-
# Filter sessions by last activity date
|
|
246
|
-
ccusage session --since 20250525
|
|
247
|
-
|
|
248
|
-
# Combine filters with environment variable
|
|
249
|
-
export CLAUDE_CONFIG_DIR="/custom/path"
|
|
250
|
-
ccusage session --since 20250525 --until 20250530
|
|
251
|
-
|
|
252
|
-
# Output in JSON format
|
|
253
|
-
ccusage session --json
|
|
254
|
-
|
|
255
|
-
# Control cost calculation mode
|
|
256
|
-
ccusage session --mode auto # Use costUSD when available, calculate otherwise (default)
|
|
257
|
-
ccusage session --mode calculate # Always calculate costs from tokens
|
|
258
|
-
ccusage session --mode display # Always show pre-calculated costUSD values
|
|
259
|
-
|
|
260
|
-
# Control sort order
|
|
261
|
-
ccusage session --order asc # Show oldest sessions first
|
|
262
|
-
ccusage session --order desc # Show newest sessions first (default)
|
|
263
|
-
|
|
264
|
-
# Show per-model cost breakdown
|
|
265
|
-
ccusage session --breakdown # Show cost breakdown by model
|
|
266
|
-
|
|
267
|
-
# Use offline mode (no network required)
|
|
268
|
-
ccusage session --offline # Use pre-cached pricing data
|
|
269
|
-
ccusage session -O # Short alias for --offline
|
|
270
|
-
```
|
|
271
|
-
|
|
272
|
-
### 5-Hour Blocks Report
|
|
273
|
-
|
|
274
|
-
Shows usage grouped by Claude's 5-hour billing windows:
|
|
275
|
-
|
|
276
|
-
```bash
|
|
277
|
-
# Show all 5-hour blocks
|
|
278
|
-
ccusage blocks
|
|
279
|
-
|
|
280
|
-
# Show only the active block with detailed projections
|
|
281
|
-
ccusage blocks --active
|
|
282
|
-
|
|
283
|
-
# Show blocks from the last 3 days (including active)
|
|
284
|
-
ccusage blocks --recent
|
|
64
|
+
## Documentation
|
|
285
65
|
|
|
286
|
-
|
|
287
|
-
ccusage blocks -t 500000
|
|
288
|
-
|
|
289
|
-
# Use the highest previous block as the token limit
|
|
290
|
-
ccusage blocks -t max
|
|
291
|
-
|
|
292
|
-
# Live monitoring dashboard with real-time updates
|
|
293
|
-
ccusage blocks --live # automatically uses highest previous session as token limit (-t max)
|
|
294
|
-
ccusage blocks --live -t 500000 # with explicit token limit (500,000 tokens)
|
|
295
|
-
ccusage blocks --live -t max # explicitly use highest previous session limit
|
|
296
|
-
ccusage blocks --live --refresh-interval 5 # update every 5 seconds (default: 1s)
|
|
297
|
-
ccusage blocks --live -t 1000000 --refresh-interval 2 # 1M token limit, 2s refresh
|
|
298
|
-
|
|
299
|
-
# Combine options
|
|
300
|
-
ccusage blocks --recent -t max
|
|
301
|
-
|
|
302
|
-
# Output in JSON format
|
|
303
|
-
ccusage blocks --json
|
|
304
|
-
|
|
305
|
-
# Control cost calculation mode
|
|
306
|
-
ccusage blocks --mode auto # Use costUSD when available, calculate otherwise (default)
|
|
307
|
-
ccusage blocks --mode calculate # Always calculate costs from tokens
|
|
308
|
-
ccusage blocks --mode display # Always show pre-calculated costUSD values
|
|
309
|
-
|
|
310
|
-
# Control sort order
|
|
311
|
-
ccusage blocks --order asc # Show oldest blocks first
|
|
312
|
-
ccusage blocks --order desc # Show newest blocks first (default)
|
|
313
|
-
```
|
|
314
|
-
|
|
315
|
-
The blocks report helps you understand Claude Code's 5-hour rolling session windows:
|
|
316
|
-
|
|
317
|
-
- Sessions start with your first message and last for 5 hours
|
|
318
|
-
- Shows active blocks with time remaining and burn rate projections
|
|
319
|
-
- Helps track if you're approaching token limits within a session
|
|
320
|
-
- The `-t max` option automatically uses your highest previous block as the limit
|
|
321
|
-
|
|
322
|
-
**Live Monitoring Features:**
|
|
323
|
-
|
|
324
|
-
- Real-time dashboard updates every 1 second (configurable 1-60s)
|
|
325
|
-
- Automatic token limit detection from your usage history
|
|
326
|
-
- Session progress bar with time remaining and burn rate
|
|
327
|
-
- Cost projections based on current usage patterns
|
|
328
|
-
- Colorful progress indicators (green/yellow/red for quota warnings)
|
|
329
|
-
- Graceful shutdown with Ctrl+C
|
|
330
|
-
|
|
331
|
-
#### Blocks-specific options
|
|
332
|
-
|
|
333
|
-
- `-t, --token-limit <number|max>`: Set token limit for quota warnings (use "max" for highest previous block)
|
|
334
|
-
- `-a, --active`: Show only active block with detailed projections
|
|
335
|
-
- `-r, --recent`: Show blocks from last 3 days (including active)
|
|
336
|
-
- `-l, --session-length <hours>`: Session block duration in hours (default: 5)
|
|
337
|
-
- `--live`: Live monitoring mode with real-time dashboard (automatically uses `-t max` and shows active block only)
|
|
338
|
-
- `--refresh-interval <seconds>`: Refresh interval for live mode (default: 1, range: 1-60)
|
|
339
|
-
|
|
340
|
-
### Options
|
|
341
|
-
|
|
342
|
-
All commands support the following options:
|
|
343
|
-
|
|
344
|
-
- `-s, --since <date>`: Filter from date (YYYYMMDD format)
|
|
345
|
-
- `-u, --until <date>`: Filter until date (YYYYMMDD format)
|
|
346
|
-
- `-j, --json`: Output results in JSON format instead of table
|
|
347
|
-
- `-m, --mode <mode>`: Cost calculation mode: `auto` (default), `calculate`, or `display`
|
|
348
|
-
- `-o, --order <order>`: Sort order: `desc` (newest first, default) or `asc` (oldest first).
|
|
349
|
-
- `-b, --breakdown`: Show per-model cost breakdown (splits usage by Opus, Sonnet, etc.)
|
|
350
|
-
- `-O, --offline`: Use pre-cached pricing data for Claude models (no network connection required)
|
|
351
|
-
- `-d, --debug`: Show pricing mismatch information for debugging
|
|
352
|
-
- `--debug-samples <number>`: Number of sample discrepancies to show in debug output (default: 5)
|
|
353
|
-
- `-h, --help`: Display help message
|
|
354
|
-
- `-v, --version`: Display version
|
|
355
|
-
|
|
356
|
-
#### Cost Calculation Modes
|
|
357
|
-
|
|
358
|
-
- **`auto`** (default): Uses pre-calculated `costUSD` values when available, falls back to calculating costs from token counts using model pricing
|
|
359
|
-
- **`calculate`**: Always calculates costs from token counts using model pricing, ignores any pre-calculated `costUSD` values
|
|
360
|
-
- **`display`**: Always uses pre-calculated `costUSD` values only, shows $0.00 for entries without pre-calculated costs
|
|
361
|
-
|
|
362
|
-
#### Environment Variable Support
|
|
363
|
-
|
|
364
|
-
The tool supports the `CLAUDE_CONFIG_DIR` environment variable to specify the Claude data directory:
|
|
365
|
-
|
|
366
|
-
```bash
|
|
367
|
-
# Set the environment variable to use a custom Claude directory
|
|
368
|
-
export CLAUDE_CONFIG_DIR="/path/to/custom/claude/directory"
|
|
369
|
-
ccusage daily
|
|
370
|
-
|
|
371
|
-
# The environment variable determines the Claude data directory
|
|
372
|
-
ccusage daily
|
|
373
|
-
```
|
|
374
|
-
|
|
375
|
-
The tool will use the path specified in the `CLAUDE_CONFIG_DIR` environment variable, or fall back to the default `~/.claude` directory if not set.
|
|
376
|
-
|
|
377
|
-
### MCP (Model Context Protocol) Support
|
|
378
|
-
|
|
379
|
-
Exposes usage data through Model Context Protocol for integration with other tools:
|
|
380
|
-
|
|
381
|
-
```bash
|
|
382
|
-
# Start MCP server with stdio transport (for local integration)
|
|
383
|
-
ccusage mcp
|
|
384
|
-
|
|
385
|
-
# Start MCP server with HTTP stream transport (for remote access)
|
|
386
|
-
ccusage mcp --type http --port 8080
|
|
387
|
-
|
|
388
|
-
# Control cost calculation mode
|
|
389
|
-
ccusage mcp --mode calculate
|
|
390
|
-
```
|
|
391
|
-
|
|
392
|
-
The MCP server supports both **stdio** and **HTTP stream** transports:
|
|
393
|
-
|
|
394
|
-
- **stdio** (default): Best for local integration where the client directly spawns the process
|
|
395
|
-
- **HTTP stream**: Best for remote access when you need to call the server from another machine or network location
|
|
396
|
-
|
|
397
|
-
Available MCP tools:
|
|
398
|
-
|
|
399
|
-
- `daily`: Returns daily usage reports (accepts `since`, `until`, `mode` parameters)
|
|
400
|
-
- `session`: Returns session usage reports (accepts `since`, `until`, `mode` parameters)
|
|
401
|
-
- `monthly`: Returns monthly usage reports (accepts `since`, `until`, `mode` parameters)
|
|
402
|
-
- `blocks`: Returns 5-hour billing blocks usage reports (accepts `since`, `until`, `mode` parameters)
|
|
403
|
-
|
|
404
|
-
#### Claude Desktop Configuration Example
|
|
405
|
-
|
|
406
|
-
<div align="center">
|
|
407
|
-
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/ccusage@main/docs/mcp-claude-desktop.avif">
|
|
408
|
-
</div>
|
|
409
|
-
|
|
410
|
-
To use ccusage MCP with Claude Desktop, add this to your Claude Desktop configuration file:
|
|
411
|
-
|
|
412
|
-
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
413
|
-
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
414
|
-
|
|
415
|
-
```json
|
|
416
|
-
{
|
|
417
|
-
"mcpServers": {
|
|
418
|
-
"ccusage": {
|
|
419
|
-
"command": "npx",
|
|
420
|
-
"args": ["ccusage@latest", "mcp"],
|
|
421
|
-
"env": {}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
```
|
|
426
|
-
|
|
427
|
-
Or if you have ccusage installed globally:
|
|
428
|
-
|
|
429
|
-
```json
|
|
430
|
-
{
|
|
431
|
-
"mcpServers": {
|
|
432
|
-
"ccusage": {
|
|
433
|
-
"command": "ccusage",
|
|
434
|
-
"args": ["mcp"],
|
|
435
|
-
"env": {}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
```
|
|
440
|
-
|
|
441
|
-
After adding this configuration, restart Claude Desktop. You'll then be able to use the ccusage tools within Claude to analyze your usage data.
|
|
442
|
-
|
|
443
|
-
#### Testing MCP Server
|
|
444
|
-
|
|
445
|
-
You can test the MCP server interactively using the MCP Inspector:
|
|
446
|
-
|
|
447
|
-
```bash
|
|
448
|
-
# Test the MCP server with interactive web UI
|
|
449
|
-
bun run mcp
|
|
450
|
-
# or: npm run mcp
|
|
451
|
-
|
|
452
|
-
# Test specific MCP server command directly
|
|
453
|
-
bunx @modelcontextprotocol/inspector bunx ccusage mcp
|
|
454
|
-
```
|
|
455
|
-
|
|
456
|
-
The MCP Inspector provides a web-based interface to:
|
|
457
|
-
|
|
458
|
-
- Test individual MCP tools (daily, monthly, session, blocks)
|
|
459
|
-
- Inspect tool schemas and parameters
|
|
460
|
-
- Debug server responses
|
|
461
|
-
- Export server configurations
|
|
462
|
-
|
|
463
|
-
## Responsive Display
|
|
464
|
-
|
|
465
|
-
ccusage automatically adapts its table layout based on your terminal width:
|
|
466
|
-
|
|
467
|
-
- **Wide terminals (≥100 characters)**: Shows all columns with bulleted model lists
|
|
468
|
-
- **Narrow terminals (<100 characters)**: Compact mode with essential columns only (Date, Models, Input, Output, Cost)
|
|
469
|
-
- **Smart formatting**: Model names displayed as clean bulleted lists (• opus-4, • sonnet-4) instead of comma-separated text
|
|
470
|
-
|
|
471
|
-
When in compact mode, ccusage displays a helpful message showing how to see the full data.
|
|
472
|
-
|
|
473
|
-
## Output Example
|
|
474
|
-
|
|
475
|
-
### Daily Report (Wide Terminal)
|
|
476
|
-
|
|
477
|
-
```
|
|
478
|
-
╭──────────────────────────────────────────╮
|
|
479
|
-
│ │
|
|
480
|
-
│ Claude Code Token Usage Report - Daily │
|
|
481
|
-
│ │
|
|
482
|
-
╰──────────────────────────────────────────╯
|
|
483
|
-
|
|
484
|
-
┌──────────────┬──────────────────┬────────┬─────────┬──────────────┬────────────┬──────────────┬────────────┐
|
|
485
|
-
│ Date │ Models │ Input │ Output │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
|
|
486
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
487
|
-
│ 2025-05-30 │ • opus-4 │ 277 │ 31,456 │ 512 │ 1,024 │ 33,269 │ $17.58 │
|
|
488
|
-
│ │ • sonnet-4 │ │ │ │ │ │ │
|
|
489
|
-
│ 2025-05-29 │ • sonnet-4 │ 959 │ 39,662 │ 256 │ 768 │ 41,645 │ $16.42 │
|
|
490
|
-
│ 2025-05-28 │ • opus-4 │ 155 │ 21,693 │ 128 │ 512 │ 22,488 │ $8.36 │
|
|
491
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
492
|
-
│ Total │ │ 11,174 │ 720,366 │ 896 │ 2,304 │ 734,740 │ $336.47 │
|
|
493
|
-
└──────────────┴──────────────────┴────────┴─────────┴──────────────┴────────────┴──────────────┴────────────┘
|
|
494
|
-
```
|
|
495
|
-
|
|
496
|
-
### Daily Report (Compact Mode - Narrow Terminal)
|
|
497
|
-
|
|
498
|
-
```
|
|
499
|
-
╭──────────────────────────────────────────╮
|
|
500
|
-
│ │
|
|
501
|
-
│ Claude Code Token Usage Report - Daily │
|
|
502
|
-
│ │
|
|
503
|
-
╰──────────────────────────────────────────╯
|
|
504
|
-
|
|
505
|
-
┌───────────┬──────────────────┬────────┬─────────┬────────────┐
|
|
506
|
-
│ Date │ Models │ Input │ Output │ Cost (USD) │
|
|
507
|
-
├───────────┼──────────────────┼────────┼─────────┼────────────┤
|
|
508
|
-
│ 2025 │ • opus-4 │ 277 │ 31,456 │ $17.58 │
|
|
509
|
-
│ 05-30 │ • sonnet-4 │ │ │ │
|
|
510
|
-
│ 2025 │ • sonnet-4 │ 959 │ 39,662 │ $16.42 │
|
|
511
|
-
│ 05-29 │ │ │ │ │
|
|
512
|
-
│ 2025 │ • opus-4 │ 155 │ 21,693 │ $8.36 │
|
|
513
|
-
│ 05-28 │ │ │ │ │
|
|
514
|
-
├───────────┼──────────────────┼────────┼─────────┼────────────┤
|
|
515
|
-
│ Total │ │ 11,174 │ 720,366 │ $336.47 │
|
|
516
|
-
└───────────┴──────────────────┴────────┴─────────┴────────────┘
|
|
517
|
-
|
|
518
|
-
Running in Compact Mode
|
|
519
|
-
Expand terminal width to see cache metrics and total tokens
|
|
520
|
-
```
|
|
521
|
-
|
|
522
|
-
With `--breakdown` flag:
|
|
523
|
-
|
|
524
|
-
```
|
|
525
|
-
╭──────────────────────────────────────────╮
|
|
526
|
-
│ │
|
|
527
|
-
│ Claude Code Token Usage Report - Daily │
|
|
528
|
-
│ │
|
|
529
|
-
╰──────────────────────────────────────────╯
|
|
530
|
-
|
|
531
|
-
┌──────────────┬──────────────────┬────────┬─────────┬──────────────┬────────────┬──────────────┬────────────┐
|
|
532
|
-
│ Date │ Models │ Input │ Output │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │
|
|
533
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
534
|
-
│ 2025-05-30 │ opus-4, sonnet-4 │ 277 │ 31,456 │ 512 │ 1,024 │ 33,269 │ $17.58 │
|
|
535
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
536
|
-
│ └─ opus-4 │ │ 100 │ 15,000 │ 256 │ 512 │ 15,868 │ $10.25 │
|
|
537
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
538
|
-
│ └─ sonnet-4│ │ 177 │ 16,456 │ 256 │ 512 │ 17,401 │ $7.33 │
|
|
539
|
-
├──────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┤
|
|
540
|
-
│ Total │ │ 11,174 │ 720,366 │ 896 │ 2,304 │ 734,740 │ $336.47 │
|
|
541
|
-
└──────────────┴──────────────────┴────────┴─────────┴──────────────┴────────────┴──────────────┴────────────┘
|
|
542
|
-
```
|
|
543
|
-
|
|
544
|
-
### Session Report
|
|
545
|
-
|
|
546
|
-
```
|
|
547
|
-
╭───────────────────────────────────────────────╮
|
|
548
|
-
│ │
|
|
549
|
-
│ Claude Code Token Usage Report - By Session │
|
|
550
|
-
│ │
|
|
551
|
-
╰───────────────────────────────────────────────╯
|
|
552
|
-
|
|
553
|
-
┌────────────┬──────────────────┬────────┬─────────┬──────────────┬────────────┬──────────────┬────────────┬───────────────┐
|
|
554
|
-
│ Session │ Models │ Input │ Output │ Cache Create │ Cache Read │ Total Tokens │ Cost (USD) │ Last Activity │
|
|
555
|
-
├────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┼───────────────┤
|
|
556
|
-
│ session-1 │ opus-4, sonnet-4 │ 4,512 │ 350,846 │ 512 │ 1,024 │ 356,894 │ $156.40 │ 2025-05-24 │
|
|
557
|
-
├────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┼───────────────┤
|
|
558
|
-
│ session-2 │ sonnet-4 │ 2,775 │ 186,645 │ 256 │ 768 │ 190,444 │ $98.45 │ 2025-05-25 │
|
|
559
|
-
├────────────┼──────────────────┼────────┼─────────┼──────────────┼────────────┼──────────────┼────────────┼───────────────┤
|
|
560
|
-
│ Total │ │ 11,174 │ 720,445 │ 768 │ 1,792 │ 734,179 │ $336.68 │ │
|
|
561
|
-
└────────────┴──────────────────┴────────┴─────────┴──────────────┴────────────┴──────────────┴────────────┴───────────────┘
|
|
562
|
-
```
|
|
563
|
-
|
|
564
|
-
## Requirements
|
|
565
|
-
|
|
566
|
-
- Claude Code usage history files (`~/.claude/projects/**/*.jsonl`)
|
|
567
|
-
|
|
568
|
-
## License
|
|
569
|
-
|
|
570
|
-
MIT
|
|
571
|
-
|
|
572
|
-
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
573
|
-
|
|
574
|
-
The logo and brand assets are also licensed under the MIT License. Created by [@nyatinte](https://github.com/nyatinte).
|
|
575
|
-
|
|
576
|
-
## Author
|
|
577
|
-
|
|
578
|
-
[@ryoppippi](https://github.com/ryoppippi)
|
|
579
|
-
|
|
580
|
-
## Inspiration
|
|
581
|
-
|
|
582
|
-
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.
|
|
583
|
-
|
|
584
|
-
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.
|
|
585
|
-
|
|
586
|
-
## Related Projects
|
|
587
|
-
|
|
588
|
-
some projects use `ccusage` internally and provide additional features:
|
|
589
|
-
|
|
590
|
-
- [claude-usage-tracker-for-mac](https://github.com/penicillin0/claude-usage-tracker-for-mac) – macOS menu bar app to visualize Claude Code usage costs by [@penicillin0](https://github.com/penicillin0).
|
|
591
|
-
- [ccusage Raycast Extension](https://www.raycast.com/nyatinte/ccusage) – Raycast extension to view Claude Code usage reports in Raycast by [@nyatinte](https://github.com/nyatinte).
|
|
592
|
-
- [claude-code-usage-monitor](https://github.com/Maciek-roboblog/Claude-Code-Usage-Monitor) – A real-time terminal-based tool for monitoring Claude Code token usage. It displays live token consumption, burn rate, and depletion predictions, with session-aware analytics, visual progress bars, and support for multiple subscription plans by [@Maciek-roboblog](https://github.com/Maciek-roboblog).
|
|
593
|
-
- [ClaudeCode_Dashboard](https://github.com/m-sigepon/ClaudeCode_Dashboard) – Web dashboard to visualize Claude Code usage with charts and USD/JPY conversion by [@m-sigepon](https://github.com/m-sigepon).
|
|
594
|
-
|
|
595
|
-
## Acknowledgments
|
|
596
|
-
|
|
597
|
-
Thanks to [@milliondev](https://note.com/milliondev) for the original concept and approach to Claude Code usage analysis.
|
|
66
|
+
Full documentation is available at **[ccusage.ryoppippi.com](https://ccusage.ryoppippi.com/)**
|
|
598
67
|
|
|
599
68
|
## Sponsors
|
|
600
69
|
|
|
601
70
|
<p align="center">
|
|
602
71
|
<a href="https://github.com/sponsors/ryoppippi">
|
|
603
|
-
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/sponsors/sponsors.svg">
|
|
72
|
+
<img src="https://cdn.jsdelivr.net/gh/ryoppippi/sponsors@main/sponsors.svg">
|
|
604
73
|
</a>
|
|
605
74
|
</p>
|
|
606
75
|
|
|
@@ -613,3 +82,7 @@ Thanks to [@milliondev](https://note.com/milliondev) for the original concept an
|
|
|
613
82
|
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=ryoppippi/ccusage&type=Date" />
|
|
614
83
|
</picture>
|
|
615
84
|
</a>
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
[MIT](LICENSE) © [@ryoppippi](https://github.com/ryoppippi)
|
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import "./
|
|
2
|
-
import
|
|
1
|
+
import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-DZczD-9E.js";
|
|
2
|
+
import "./pricing-fetcher-BZe7AafW.js";
|
|
3
3
|
|
|
4
4
|
//#region src/calculate-cost.d.ts
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Token usage data structure containing input, output, and cache token counts
|
|
7
8
|
*/
|