ccusage 0.8.0 → 9.0.1

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.
Files changed (37) hide show
  1. package/README.md +41 -6
  2. package/dist/calculate-cost.d.ts +2 -2
  3. package/dist/chunk-BLXvPPr8.js +30 -0
  4. package/dist/{data-loader-Bz6Vemxw.js → data-loader-CotJGlGF.js} +235 -294
  5. package/dist/{data-loader-amTZCtBR.d.ts → data-loader-OGaMjZTD.d.ts} +8 -80
  6. package/dist/data-loader.d.ts +3 -3
  7. package/dist/data-loader.js +5 -5
  8. package/dist/{debug-DQXeZIjf.js → debug-DH_5GWYh.js} +5 -4
  9. package/dist/debug.js +5 -5
  10. package/dist/{dist-DAarI-SJ.js → dist-BZzwBtZs.js} +1 -1
  11. package/dist/{effect-WSjEuzC9-ChJ5OQQf.js → effect-WSjEuzC9-DHMVzzyB.js} +1 -1
  12. package/dist/{esm-Dqsc1zmX.js → esm-BU3FhOe-.js} +1 -1
  13. package/dist/{index-CISmcbXk-x9eVmhGM.js → index-CISmcbXk-CW1Gj6Ab.js} +5 -5
  14. package/dist/index.js +199 -1760
  15. package/dist/{logger-DN-RT9jL.js → logger-BgKOQAEs.js} +3 -3
  16. package/dist/logger.js +1 -1
  17. package/dist/{mcp-DZXbfmbs.js → mcp-BUmEAQZm.js} +42 -50
  18. package/dist/mcp.d.ts +2 -2
  19. package/dist/mcp.js +7 -7
  20. package/dist/pricing-fetcher-1KHPTXC3.js +205 -0
  21. package/dist/{pricing-fetcher-Dq-OLBp4.d.ts → pricing-fetcher-BkSZh4lR.d.ts} +83 -3
  22. package/dist/pricing-fetcher.d.ts +2 -2
  23. package/dist/pricing-fetcher.js +3 -3
  24. package/dist/{sury-DmrZ3_Oj-l0qqtY-f.js → sury-DmrZ3_Oj-Cpjsc2Lm.js} +1 -1
  25. package/dist/utils.table-DRzF8vZJ.js +1838 -0
  26. package/dist/utils.table.d.ts +24 -0
  27. package/dist/utils.table.js +3 -0
  28. package/dist/valibot-CQk-M5rL-BcaCeUrF.js +10 -0
  29. package/dist/{zod-Db63SLXj-N1oN-yiY.js → zod-Db63SLXj-BIXn64AP.js} +3 -3
  30. package/package.json +2 -1
  31. package/dist/pricing-fetcher-DMNBE90M.js +0 -79
  32. package/dist/valibot-CQk-M5rL-BNHzwpA0.js +0 -10
  33. /package/dist/{arktype-C-GObzDh-Bx7Fdrqj.js → arktype-C-GObzDh-CNoBqQrr.js} +0 -0
  34. /package/dist/{core-B0ovMhJe.js → core-DHCbAXJf.js} +0 -0
  35. /package/dist/{dist-BEQ1tJCL.js → dist-DCvt9hEv.js} +0 -0
  36. /package/dist/{prompt-CUbwSrjo.js → prompt-DtZgx4wU.js} +0 -0
  37. /package/dist/{types-DS8M8QF_.js → types-BlyCnKwN.js} +0 -0
package/README.md CHANGED
@@ -45,10 +45,12 @@ This tool helps you understand the value you're getting from your subscription b
45
45
  - 📊 **Model Breakdown**: View per-model cost breakdown with `--breakdown` flag
46
46
  - 📅 **Date Filtering**: Filter reports by date range using `--since` and `--until`
47
47
  - 📁 **Custom Path**: Support for custom Claude data directory locations
48
- - 🎨 **Beautiful Output**: Colorful table-formatted display
48
+ - 🎨 **Beautiful Output**: Colorful table-formatted display with responsive width adjustment
49
49
  - 📄 **JSON Output**: Export data in structured JSON format with `--json`
50
50
  - 💰 **Cost Tracking**: Shows costs in USD for each day/month/session
51
51
  - 🔄 **Cache Token Support**: Tracks and displays cache creation and cache read tokens separately
52
+ - 🌐 **Offline Mode**: Use pre-cached pricing data without network connectivity with `--offline` (Claude models only)
53
+ - 📏 **Responsive Tables**: Automatic table width adjustment for narrow terminals with intelligent word wrapping
52
54
 
53
55
  ## Important Disclaimer
54
56
 
@@ -129,8 +131,9 @@ ccusage daily
129
131
  # Filter by date range
130
132
  ccusage daily --since 20250525 --until 20250530
131
133
 
132
- # Use custom Claude data directory
133
- ccusage daily --path /custom/path/to/.claude
134
+ # Set CLAUDE_CONFIG_DIR environment variable for custom data directory
135
+ export CLAUDE_CONFIG_DIR="/custom/path/to/.claude"
136
+ ccusage daily
134
137
 
135
138
  # Output in JSON format
136
139
  ccusage daily --json
@@ -146,6 +149,10 @@ ccusage daily --order desc # Show newest dates first (default)
146
149
 
147
150
  # Show per-model cost breakdown
148
151
  ccusage daily --breakdown # Show cost breakdown by model (opus-4, sonnet-4, etc.)
152
+
153
+ # Use offline mode (no network required)
154
+ ccusage daily --offline # Use pre-cached pricing data
155
+ ccusage daily -O # Short alias for --offline
149
156
  ```
150
157
 
151
158
  `ccusage` is an alias for `ccusage daily`, so you can run it without specifying the subcommand.
@@ -164,6 +171,10 @@ ccusage monthly --since 20250101 --until 20250531
164
171
  # Use custom Claude data directory
165
172
  ccusage monthly --path /custom/path/to/.claude
166
173
 
174
+ # Or set CLAUDE_CONFIG_DIR environment variable
175
+ export CLAUDE_CONFIG_DIR="/custom/path/to/.claude"
176
+ ccusage monthly
177
+
167
178
  # Output in JSON format
168
179
  ccusage monthly --json
169
180
 
@@ -178,6 +189,10 @@ ccusage monthly --order desc # Show newest months first (default)
178
189
 
179
190
  # Show per-model cost breakdown
180
191
  ccusage monthly --breakdown # Show cost breakdown by model
192
+
193
+ # Use offline mode (no network required)
194
+ ccusage monthly --offline # Use pre-cached pricing data
195
+ ccusage monthly -O # Short alias for --offline
181
196
  ```
182
197
 
183
198
  ### Session Report
@@ -191,8 +206,9 @@ ccusage session
191
206
  # Filter sessions by last activity date
192
207
  ccusage session --since 20250525
193
208
 
194
- # Combine filters
195
- ccusage session --since 20250525 --until 20250530 --path /custom/path
209
+ # Combine filters with environment variable
210
+ export CLAUDE_CONFIG_DIR="/custom/path"
211
+ ccusage session --since 20250525 --until 20250530
196
212
 
197
213
  # Output in JSON format
198
214
  ccusage session --json
@@ -208,6 +224,10 @@ ccusage session --order desc # Show newest sessions first (default)
208
224
 
209
225
  # Show per-model cost breakdown
210
226
  ccusage session --breakdown # Show cost breakdown by model
227
+
228
+ # Use offline mode (no network required)
229
+ ccusage session --offline # Use pre-cached pricing data
230
+ ccusage session -O # Short alias for --offline
211
231
  ```
212
232
 
213
233
  ### Options
@@ -216,11 +236,11 @@ All commands support the following options:
216
236
 
217
237
  - `-s, --since <date>`: Filter from date (YYYYMMDD format)
218
238
  - `-u, --until <date>`: Filter until date (YYYYMMDD format)
219
- - `-p, --path <path>`: Custom path to Claude data directory (default: `~/.claude`)
220
239
  - `-j, --json`: Output results in JSON format instead of table
221
240
  - `-m, --mode <mode>`: Cost calculation mode: `auto` (default), `calculate`, or `display`
222
241
  - `-o, --order <order>`: Sort order: `desc` (newest first, default) or `asc` (oldest first).
223
242
  - `-b, --breakdown`: Show per-model cost breakdown (splits usage by Opus, Sonnet, etc.)
243
+ - `-O, --offline`: Use pre-cached pricing data for Claude models (no network connection required)
224
244
  - `-d, --debug`: Show pricing mismatch information for debugging
225
245
  - `--debug-samples <number>`: Number of sample discrepancies to show in debug output (default: 5)
226
246
  - `-h, --help`: Display help message
@@ -232,6 +252,21 @@ All commands support the following options:
232
252
  - **`calculate`**: Always calculates costs from token counts using model pricing, ignores any pre-calculated `costUSD` values
233
253
  - **`display`**: Always uses pre-calculated `costUSD` values only, shows $0.00 for entries without pre-calculated costs
234
254
 
255
+ #### Environment Variable Support
256
+
257
+ The tool supports the `CLAUDE_CONFIG_DIR` environment variable to specify the Claude data directory:
258
+
259
+ ```bash
260
+ # Set the environment variable to use a custom Claude directory
261
+ export CLAUDE_CONFIG_DIR="/path/to/custom/claude/directory"
262
+ ccusage daily
263
+
264
+ # The environment variable determines the Claude data directory
265
+ ccusage daily
266
+ ```
267
+
268
+ 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.
269
+
235
270
  ### MCP (Model Context Protocol) Support
236
271
 
237
272
  Exposes usage data through Model Context Protocol for integration with other tools:
@@ -1,5 +1,5 @@
1
- import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-amTZCtBR.js";
2
- import "./pricing-fetcher-Dq-OLBp4.js";
1
+ import "./pricing-fetcher-BkSZh4lR.js";
2
+ import { DailyUsage, MonthlyUsage, SessionUsage } from "./data-loader-OGaMjZTD.js";
3
3
 
4
4
  //#region src/calculate-cost.d.ts
5
5
  type TokenData = {
@@ -0,0 +1,30 @@
1
+ import { createRequire } from "node:module";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __commonJS = (cb, mod) => function() {
11
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
28
+
29
+ //#endregion
30
+ export { __commonJS, __require, __toESM };