ccusage 0.3.2 → 0.4.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 CHANGED
@@ -46,6 +46,16 @@ This tool helps you understand the value you're getting from your subscription b
46
46
  - 💰 **Cost Tracking**: Shows costs in USD for each day/session
47
47
  - 🔄 **Cache Token Support**: Tracks and displays cache creation and cache read tokens separately
48
48
 
49
+ ## Important Disclaimer
50
+
51
+ ⚠️ **This is NOT an official Claude tool** - it's an independent community project that analyzes locally stored usage data.
52
+
53
+ **Cost calculations are estimates only** and may not reflect actual billing:
54
+ - Costs shown are virtual/estimated based on token counts and model pricing data
55
+ - Actual costs may vary due to pricing changes, special rates, or billing adjustments
56
+ - We do not guarantee the accuracy of calculated costs
57
+ - For official billing information, always refer to your Claude account dashboard
58
+
49
59
  ## Limitations
50
60
 
51
61
  - 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.
@@ -113,6 +123,11 @@ ccusage daily --path /custom/path/to/.claude
113
123
 
114
124
  # Output in JSON format
115
125
  ccusage daily --json
126
+
127
+ # Control cost calculation mode
128
+ ccusage daily --mode auto # Use costUSD when available, calculate otherwise (default)
129
+ ccusage daily --mode calculate # Always calculate costs from tokens
130
+ ccusage daily --mode display # Always show pre-calculated costUSD values
116
131
  ```
117
132
 
118
133
  `ccusage` is an alias for `ccusage daily`, so you can run it without specifying the subcommand.
@@ -133,6 +148,11 @@ ccusage session --since 20250525 --until 20250530 --path /custom/path
133
148
 
134
149
  # Output in JSON format
135
150
  ccusage session --json
151
+
152
+ # Control cost calculation mode
153
+ ccusage session --mode auto # Use costUSD when available, calculate otherwise (default)
154
+ ccusage session --mode calculate # Always calculate costs from tokens
155
+ ccusage session --mode display # Always show pre-calculated costUSD values
136
156
  ```
137
157
 
138
158
  ### Options
@@ -143,9 +163,18 @@ All commands support the following options:
143
163
  - `-u, --until <date>`: Filter until date (YYYYMMDD format)
144
164
  - `-p, --path <path>`: Custom path to Claude data directory (default: `~/.claude`)
145
165
  - `-j, --json`: Output results in JSON format instead of table
166
+ - `-m, --mode <mode>`: Cost calculation mode: `auto` (default), `calculate`, or `display`
167
+ - `-d, --debug`: Show pricing mismatch information for debugging
168
+ - `--debug-samples <number>`: Number of sample discrepancies to show in debug output (default: 5)
146
169
  - `-h, --help`: Display help message
147
170
  - `-v, --version`: Display version
148
171
 
172
+ #### Cost Calculation Modes
173
+
174
+ - **`auto`** (default): Uses pre-calculated `costUSD` values when available, falls back to calculating costs from token counts using model pricing
175
+ - **`calculate`**: Always calculates costs from token counts using model pricing, ignores any pre-calculated `costUSD` values
176
+ - **`display`**: Always uses pre-calculated `costUSD` values only, shows $0.00 for entries without pre-calculated costs
177
+
149
178
  ## Output Example
150
179
 
151
180
  ### Daily Report
@@ -1,21 +1,5 @@
1
- import { DailyUsage, SessionUsage } from "./data-loader-ToqWI8hT.js";
1
+ import { DailyUsage, SessionUsage, TokenData, TokenTotals } from "./data-loader-D1LHcGfa.js";
2
2
 
3
- //#region types.d.ts
4
-
5
- interface TokenTotals {
6
- inputTokens: number;
7
- outputTokens: number;
8
- cacheCreationTokens: number;
9
- cacheReadTokens: number;
10
- totalCost: number;
11
- }
12
- interface TokenData {
13
- inputTokens: number;
14
- outputTokens: number;
15
- cacheCreationTokens: number;
16
- cacheReadTokens: number;
17
- }
18
- //#endregion
19
3
  //#region calculate-cost.d.ts
20
4
  declare function calculateTotals(data: Array<DailyUsage | SessionUsage>): TokenTotals;
21
5
  declare function getTotalTokens(tokens: TokenData): number;
@@ -929,6 +929,71 @@ type PipeItemAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSch
929
929
  * Schema without pipe type.
930
930
  */
931
931
 
932
+ /**
933
+ * Array issue interface.
934
+ */
935
+ interface ArrayIssue extends BaseIssue<unknown> {
936
+ /**
937
+ * The issue kind.
938
+ */
939
+ readonly kind: 'schema';
940
+ /**
941
+ * The issue type.
942
+ */
943
+ readonly type: 'array';
944
+ /**
945
+ * The expected property.
946
+ */
947
+ readonly expected: 'Array';
948
+ }
949
+
950
+ /**
951
+ * Array schema interface.
952
+ */
953
+ interface ArraySchema<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TMessage extends ErrorMessage<ArrayIssue> | undefined> extends BaseSchema<InferInput<TItem>[], InferOutput<TItem>[], ArrayIssue | InferIssue<TItem>> {
954
+ /**
955
+ * The schema type.
956
+ */
957
+ readonly type: 'array';
958
+ /**
959
+ * The schema reference.
960
+ */
961
+ readonly reference: typeof array;
962
+ /**
963
+ * The expected property.
964
+ */
965
+ readonly expects: 'Array';
966
+ /**
967
+ * The array item schema.
968
+ */
969
+ readonly item: TItem;
970
+ /**
971
+ * The error message.
972
+ */
973
+ readonly message: TMessage;
974
+ }
975
+ /**
976
+ * Creates an array schema.
977
+ *
978
+ * @param item The item schema.
979
+ *
980
+ * @returns An array schema.
981
+ */
982
+ declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(item: TItem): ArraySchema<TItem, undefined>;
983
+ /**
984
+ * Creates an array schema.
985
+ *
986
+ * @param item The item schema.
987
+ * @param message The error message.
988
+ *
989
+ * @returns An array schema.
990
+ */
991
+ declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TMessage extends ErrorMessage<ArrayIssue> | undefined>(item: TItem, message: TMessage): ArraySchema<TItem, TMessage>;
992
+
993
+ /**
994
+ * Array schema interface.
995
+ */
996
+
932
997
  /**
933
998
  * Exact optional schema interface.
934
999
  */
@@ -1418,10 +1483,37 @@ declare function readonly<TInput>(): ReadonlyAction<TInput>;
1418
1483
  * Array action type.
1419
1484
  */
1420
1485
  //#endregion
1486
+ //#region pricing-fetcher.d.ts
1487
+ declare const ModelPricingSchema: ObjectSchema<{
1488
+ readonly input_cost_per_token: OptionalSchema<NumberSchema<undefined>, undefined>;
1489
+ readonly output_cost_per_token: OptionalSchema<NumberSchema<undefined>, undefined>;
1490
+ readonly cache_creation_input_token_cost: OptionalSchema<NumberSchema<undefined>, undefined>;
1491
+ readonly cache_read_input_token_cost: OptionalSchema<NumberSchema<undefined>, undefined>;
1492
+ }, undefined>;
1493
+ type ModelPricing = InferOutput<typeof ModelPricingSchema>;
1494
+ //#endregion
1495
+ //#region types.d.ts
1496
+ interface TokenTotals {
1497
+ inputTokens: number;
1498
+ outputTokens: number;
1499
+ cacheCreationTokens: number;
1500
+ cacheReadTokens: number;
1501
+ totalCost: number;
1502
+ }
1503
+ interface TokenData {
1504
+ inputTokens: number;
1505
+ outputTokens: number;
1506
+ cacheCreationTokens: number;
1507
+ cacheReadTokens: number;
1508
+ }
1509
+ declare const CostModes: readonly ["auto", "calculate", "display"];
1510
+ type CostMode = (typeof CostModes)[number];
1511
+ //#endregion
1421
1512
  //#region data-loader.d.ts
1422
1513
  declare const getDefaultClaudePath: () => string;
1423
1514
  declare const UsageDataSchema: ObjectSchema<{
1424
1515
  readonly timestamp: StringSchema<undefined>;
1516
+ readonly version: OptionalSchema<StringSchema<undefined>, undefined>;
1425
1517
  readonly message: ObjectSchema<{
1426
1518
  readonly usage: ObjectSchema<{
1427
1519
  readonly input_tokens: NumberSchema<undefined>;
@@ -1429,8 +1521,9 @@ declare const UsageDataSchema: ObjectSchema<{
1429
1521
  readonly cache_creation_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
1430
1522
  readonly cache_read_input_tokens: OptionalSchema<NumberSchema<undefined>, undefined>;
1431
1523
  }, undefined>;
1524
+ readonly model: OptionalSchema<StringSchema<undefined>, undefined>;
1432
1525
  }, undefined>;
1433
- readonly costUSD: NumberSchema<undefined>;
1526
+ readonly costUSD: OptionalSchema<NumberSchema<undefined>, undefined>;
1434
1527
  }, undefined>;
1435
1528
  type UsageData = InferOutput<typeof UsageDataSchema>;
1436
1529
  declare const DailyUsageSchema: ObjectSchema<{
@@ -1451,17 +1544,20 @@ declare const SessionUsageSchema: ObjectSchema<{
1451
1544
  readonly cacheReadTokens: NumberSchema<undefined>;
1452
1545
  readonly totalCost: NumberSchema<undefined>;
1453
1546
  readonly lastActivity: StringSchema<undefined>;
1547
+ readonly versions: ArraySchema<StringSchema<undefined>, undefined>;
1454
1548
  }, undefined>;
1455
1549
  type SessionUsage = InferOutput<typeof SessionUsageSchema>;
1456
1550
  declare const formatDate: (dateStr: string) => string;
1551
+ declare const calculateCostForEntry: (data: UsageData, mode: CostMode, modelPricing: Record<string, ModelPricing>) => number;
1457
1552
  interface DateFilter {
1458
1553
  since?: string;
1459
1554
  until?: string;
1460
1555
  }
1461
1556
  interface LoadOptions extends DateFilter {
1462
1557
  claudePath?: string;
1558
+ mode?: CostMode;
1463
1559
  }
1464
1560
  declare function loadUsageData(options?: LoadOptions): Promise<DailyUsage[]>;
1465
1561
  declare function loadSessionData(options?: LoadOptions): Promise<SessionUsage[]>;
1466
1562
  //#endregion
1467
- export { DailyUsage, DailyUsageSchema as DailyUsageSchema$1, DateFilter, LoadOptions, SessionUsage, SessionUsageSchema as SessionUsageSchema$1, UsageData, UsageDataSchema as UsageDataSchema$1, formatDate as formatDate$1, getDefaultClaudePath as getDefaultClaudePath$1, loadSessionData as loadSessionData$1, loadUsageData as loadUsageData$1 };
1563
+ export { DailyUsage, DailyUsageSchema as DailyUsageSchema$1, DateFilter, LoadOptions, SessionUsage, SessionUsageSchema as SessionUsageSchema$1, TokenData, TokenTotals, UsageData, UsageDataSchema as UsageDataSchema$1, calculateCostForEntry as calculateCostForEntry$1, formatDate as formatDate$1, getDefaultClaudePath as getDefaultClaudePath$1, loadSessionData as loadSessionData$1, loadUsageData as loadUsageData$1 };