ccusage 15.9.4 → 15.9.5
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/dist/calculate-cost.d.ts +1 -1
- package/dist/{data-loader-B2FL7oh0.d.ts → data-loader-BPepPoPg.d.ts} +99 -1
- package/dist/{data-loader-CY2f8ZBq.js → data-loader-Plh5X-UR.js} +57 -3
- package/dist/data-loader.d.ts +2 -2
- package/dist/data-loader.js +4 -4
- package/dist/{debug-mIvd8kZa.js → debug-C4f2zPfQ.js} +3 -3
- package/dist/debug.js +4 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +20 -9
- package/dist/{logger-QcakA1fc.js → logger-dT_AJeHG.js} +1 -1
- package/dist/logger.js +1 -1
- package/dist/{mcp-COJ_l32e.js → mcp-DfY3l9w7.js} +3 -3
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +4 -4
- package/dist/{pricing-fetcher-DzkXdtDF.js → pricing-fetcher-CTYPN13Y.js} +6 -3
- package/dist/pricing-fetcher.js +2 -2
- package/package.json +1 -1
package/dist/calculate-cost.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./pricing-fetcher-B5m_kEpz.js";
|
|
2
|
-
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-
|
|
2
|
+
import { DailyUsage, MonthlyUsage, SessionUsage, WeeklyUsage } from "./data-loader-BPepPoPg.js";
|
|
3
3
|
|
|
4
4
|
//#region src/_token-utils.d.ts
|
|
5
5
|
|
|
@@ -62,6 +62,16 @@ type SessionBlock = {
|
|
|
62
62
|
* @returns Array of valid Claude data directory paths
|
|
63
63
|
*/
|
|
64
64
|
declare function getClaudePaths(): string[];
|
|
65
|
+
/**
|
|
66
|
+
* Get context usage percentage thresholds for color coding
|
|
67
|
+
* Can be configured via environment variables or uses defaults
|
|
68
|
+
* Validates and clamps values to 0-100 range and enforces LOW < MEDIUM ordering
|
|
69
|
+
* @returns Context usage thresholds with LOW and MEDIUM percentages
|
|
70
|
+
*/
|
|
71
|
+
declare function getContextUsageThresholds(): {
|
|
72
|
+
readonly LOW: number;
|
|
73
|
+
readonly MEDIUM: number;
|
|
74
|
+
};
|
|
65
75
|
/**
|
|
66
76
|
* Extract project name from Claude JSONL file path
|
|
67
77
|
* @param jsonlPath - Absolute path to JSONL file
|
|
@@ -173,6 +183,83 @@ declare const usageDataSchema: z.ZodObject<{
|
|
|
173
183
|
requestId?: string | undefined;
|
|
174
184
|
isApiErrorMessage?: boolean | undefined;
|
|
175
185
|
}>;
|
|
186
|
+
/**
|
|
187
|
+
* Zod schema for transcript usage data from Claude messages
|
|
188
|
+
*/
|
|
189
|
+
declare const transcriptUsageSchema: z.ZodObject<{
|
|
190
|
+
input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
191
|
+
cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
192
|
+
cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
193
|
+
output_tokens: z.ZodOptional<z.ZodNumber>;
|
|
194
|
+
}, "strip", z.ZodTypeAny, {
|
|
195
|
+
input_tokens?: number | undefined;
|
|
196
|
+
cache_creation_input_tokens?: number | undefined;
|
|
197
|
+
cache_read_input_tokens?: number | undefined;
|
|
198
|
+
output_tokens?: number | undefined;
|
|
199
|
+
}, {
|
|
200
|
+
input_tokens?: number | undefined;
|
|
201
|
+
cache_creation_input_tokens?: number | undefined;
|
|
202
|
+
cache_read_input_tokens?: number | undefined;
|
|
203
|
+
output_tokens?: number | undefined;
|
|
204
|
+
}>;
|
|
205
|
+
/**
|
|
206
|
+
* Zod schema for transcript message data
|
|
207
|
+
*/
|
|
208
|
+
declare const transcriptMessageSchema: z.ZodObject<{
|
|
209
|
+
type: z.ZodOptional<z.ZodString>;
|
|
210
|
+
message: z.ZodOptional<z.ZodObject<{
|
|
211
|
+
usage: z.ZodOptional<z.ZodObject<{
|
|
212
|
+
input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
213
|
+
cache_creation_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
214
|
+
cache_read_input_tokens: z.ZodOptional<z.ZodNumber>;
|
|
215
|
+
output_tokens: z.ZodOptional<z.ZodNumber>;
|
|
216
|
+
}, "strip", z.ZodTypeAny, {
|
|
217
|
+
input_tokens?: number | undefined;
|
|
218
|
+
cache_creation_input_tokens?: number | undefined;
|
|
219
|
+
cache_read_input_tokens?: number | undefined;
|
|
220
|
+
output_tokens?: number | undefined;
|
|
221
|
+
}, {
|
|
222
|
+
input_tokens?: number | undefined;
|
|
223
|
+
cache_creation_input_tokens?: number | undefined;
|
|
224
|
+
cache_read_input_tokens?: number | undefined;
|
|
225
|
+
output_tokens?: number | undefined;
|
|
226
|
+
}>>;
|
|
227
|
+
}, "strip", z.ZodTypeAny, {
|
|
228
|
+
usage?: {
|
|
229
|
+
input_tokens?: number | undefined;
|
|
230
|
+
cache_creation_input_tokens?: number | undefined;
|
|
231
|
+
cache_read_input_tokens?: number | undefined;
|
|
232
|
+
output_tokens?: number | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
}, {
|
|
235
|
+
usage?: {
|
|
236
|
+
input_tokens?: number | undefined;
|
|
237
|
+
cache_creation_input_tokens?: number | undefined;
|
|
238
|
+
cache_read_input_tokens?: number | undefined;
|
|
239
|
+
output_tokens?: number | undefined;
|
|
240
|
+
} | undefined;
|
|
241
|
+
}>>;
|
|
242
|
+
}, "strip", z.ZodTypeAny, {
|
|
243
|
+
type?: string | undefined;
|
|
244
|
+
message?: {
|
|
245
|
+
usage?: {
|
|
246
|
+
input_tokens?: number | undefined;
|
|
247
|
+
cache_creation_input_tokens?: number | undefined;
|
|
248
|
+
cache_read_input_tokens?: number | undefined;
|
|
249
|
+
output_tokens?: number | undefined;
|
|
250
|
+
} | undefined;
|
|
251
|
+
} | undefined;
|
|
252
|
+
}, {
|
|
253
|
+
type?: string | undefined;
|
|
254
|
+
message?: {
|
|
255
|
+
usage?: {
|
|
256
|
+
input_tokens?: number | undefined;
|
|
257
|
+
cache_creation_input_tokens?: number | undefined;
|
|
258
|
+
cache_read_input_tokens?: number | undefined;
|
|
259
|
+
output_tokens?: number | undefined;
|
|
260
|
+
} | undefined;
|
|
261
|
+
} | undefined;
|
|
262
|
+
}>;
|
|
176
263
|
/**
|
|
177
264
|
* Type definition for Claude usage data entries from JSONL files
|
|
178
265
|
*/
|
|
@@ -696,6 +783,17 @@ declare function loadSessionUsageById(sessionId: string, options?: {
|
|
|
696
783
|
entries: UsageData[];
|
|
697
784
|
} | null>;
|
|
698
785
|
declare function loadBucketUsageData(groupingFn: (data: DailyUsage) => Bucket, options?: LoadOptions): Promise<BucketUsage[]>;
|
|
786
|
+
/**
|
|
787
|
+
* Calculate context tokens from transcript file using improved JSONL parsing
|
|
788
|
+
* Based on the Python reference implementation for better accuracy
|
|
789
|
+
* @param transcriptPath - Path to the transcript JSONL file
|
|
790
|
+
* @returns Object with context tokens info or null if unavailable
|
|
791
|
+
*/
|
|
792
|
+
declare function calculateContextTokens(transcriptPath: string): Promise<{
|
|
793
|
+
inputTokens: number;
|
|
794
|
+
percentage: number;
|
|
795
|
+
contextLimit: number;
|
|
796
|
+
} | null>;
|
|
699
797
|
/**
|
|
700
798
|
* Loads usage data and organizes it into session blocks (typically 5-hour billing periods)
|
|
701
799
|
* Processes all usage data and groups it into time-based blocks for billing analysis
|
|
@@ -704,4 +802,4 @@ declare function loadBucketUsageData(groupingFn: (data: DailyUsage) => Bucket, o
|
|
|
704
802
|
*/
|
|
705
803
|
declare function loadSessionBlockData(options?: LoadOptions): Promise<SessionBlock[]>;
|
|
706
804
|
//#endregion
|
|
707
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema, weeklyUsageSchema };
|
|
805
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, require_usingCtx } from "./pricing-fetcher-
|
|
1
|
+
import { CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, CONTEXT_LIMIT, CONTEXT_LOW_THRESHOLD_ENV, CONTEXT_MEDIUM_THRESHOLD_ENV, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_CONTEXT_USAGE_THRESHOLDS, DEFAULT_RECENT_DAYS, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, __commonJSMin, __require, __toESM, isFailure, isPromise, require_usingCtx } from "./pricing-fetcher-CTYPN13Y.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import { activityDateSchema, arrayType, booleanType, createBucket, createDailyDate, createMonthlyDate, createProjectPath, createSessionId, createWeeklyDate, dailyDateSchema, isoTimestampSchema, messageIdSchema, modelNameSchema, monthlyDateSchema, numberType, objectType, projectPathSchema, requestIdSchema, sessionIdSchema, stringType, unionType, versionSchema, weeklyDateSchema } from "./_types-C0oFKDO-.js";
|
|
4
|
-
import { logger } from "./logger-
|
|
4
|
+
import { logger } from "./logger-dT_AJeHG.js";
|
|
5
5
|
import a, { readFile } from "node:fs/promises";
|
|
6
6
|
import path, { posix } from "node:path";
|
|
7
7
|
import process$1 from "node:process";
|
|
@@ -2201,6 +2201,23 @@ function getClaudePaths() {
|
|
|
2201
2201
|
- Or set ${CLAUDE_CONFIG_DIR_ENV} environment variable to valid directory path(s) containing a '${CLAUDE_PROJECTS_DIR_NAME}' subdirectory`.trim());
|
|
2202
2202
|
return paths;
|
|
2203
2203
|
}
|
|
2204
|
+
function getContextUsageThresholds() {
|
|
2205
|
+
const lowThresholdStr = process$1.env[CONTEXT_LOW_THRESHOLD_ENV], mediumThresholdStr = process$1.env[CONTEXT_MEDIUM_THRESHOLD_ENV];
|
|
2206
|
+
let lowThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.LOW, mediumThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.MEDIUM;
|
|
2207
|
+
if (lowThresholdStr != null) {
|
|
2208
|
+
const parsed = Number.parseInt(lowThresholdStr, 10);
|
|
2209
|
+
if (!Number.isNaN(parsed)) lowThreshold = Math.max(0, Math.min(100, parsed));
|
|
2210
|
+
}
|
|
2211
|
+
if (mediumThresholdStr != null) {
|
|
2212
|
+
const parsed = Number.parseInt(mediumThresholdStr, 10);
|
|
2213
|
+
if (!Number.isNaN(parsed)) mediumThreshold = Math.max(0, Math.min(100, parsed));
|
|
2214
|
+
}
|
|
2215
|
+
if (lowThreshold >= mediumThreshold) lowThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.LOW, mediumThreshold = DEFAULT_CONTEXT_USAGE_THRESHOLDS.MEDIUM;
|
|
2216
|
+
return {
|
|
2217
|
+
LOW: lowThreshold,
|
|
2218
|
+
MEDIUM: mediumThreshold
|
|
2219
|
+
};
|
|
2220
|
+
}
|
|
2204
2221
|
function extractProjectFromPath(jsonlPath) {
|
|
2205
2222
|
const normalizedPath = jsonlPath.replace(/[/\\]/g, path.sep), segments = normalizedPath.split(path.sep), projectsIndex = segments.findIndex((segment) => segment === CLAUDE_PROJECTS_DIR_NAME);
|
|
2206
2223
|
if (projectsIndex === -1 || projectsIndex + 1 >= segments.length) return "unknown";
|
|
@@ -2226,6 +2243,14 @@ const usageDataSchema = objectType({
|
|
|
2226
2243
|
costUSD: numberType().optional(),
|
|
2227
2244
|
requestId: requestIdSchema.optional(),
|
|
2228
2245
|
isApiErrorMessage: booleanType().optional()
|
|
2246
|
+
}), transcriptUsageSchema = objectType({
|
|
2247
|
+
input_tokens: numberType().optional(),
|
|
2248
|
+
cache_creation_input_tokens: numberType().optional(),
|
|
2249
|
+
cache_read_input_tokens: numberType().optional(),
|
|
2250
|
+
output_tokens: numberType().optional()
|
|
2251
|
+
}), transcriptMessageSchema = objectType({
|
|
2252
|
+
type: stringType().optional(),
|
|
2253
|
+
message: objectType({ usage: transcriptUsageSchema.optional() }).optional()
|
|
2229
2254
|
}), modelBreakdownSchema = objectType({
|
|
2230
2255
|
modelName: modelNameSchema,
|
|
2231
2256
|
inputTokens: numberType(),
|
|
@@ -2644,6 +2669,35 @@ async function loadBucketUsageData(groupingFn, options) {
|
|
|
2644
2669
|
}
|
|
2645
2670
|
return sortByDate(buckets, (item) => item.bucket, options?.order);
|
|
2646
2671
|
}
|
|
2672
|
+
async function calculateContextTokens(transcriptPath) {
|
|
2673
|
+
let content;
|
|
2674
|
+
try {
|
|
2675
|
+
content = await readFile(transcriptPath, "utf-8");
|
|
2676
|
+
} catch (error) {
|
|
2677
|
+
return logger.debug(`Failed to read transcript file: ${String(error)}`), null;
|
|
2678
|
+
}
|
|
2679
|
+
const lines = content.split("\n").reverse();
|
|
2680
|
+
for (const line of lines) {
|
|
2681
|
+
const trimmedLine = line.trim();
|
|
2682
|
+
if (trimmedLine === "") continue;
|
|
2683
|
+
try {
|
|
2684
|
+
const parsed = JSON.parse(trimmedLine), result = transcriptMessageSchema.safeParse(parsed);
|
|
2685
|
+
if (!result.success) continue;
|
|
2686
|
+
const obj = result.data;
|
|
2687
|
+
if (obj.type === "assistant" && obj.message != null && obj.message.usage != null && obj.message.usage.input_tokens != null) {
|
|
2688
|
+
const usage = obj.message.usage, inputTokens = usage.input_tokens + (usage.cache_creation_input_tokens ?? 0) + (usage.cache_read_input_tokens ?? 0), percentage = Math.min(100, Math.max(0, Math.round(inputTokens / CONTEXT_LIMIT * 100)));
|
|
2689
|
+
return {
|
|
2690
|
+
inputTokens,
|
|
2691
|
+
percentage,
|
|
2692
|
+
contextLimit: CONTEXT_LIMIT
|
|
2693
|
+
};
|
|
2694
|
+
}
|
|
2695
|
+
} catch {
|
|
2696
|
+
continue;
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
return logger.debug("No usage information found in transcript"), null;
|
|
2700
|
+
}
|
|
2647
2701
|
async function loadSessionBlockData(options) {
|
|
2648
2702
|
try {
|
|
2649
2703
|
var _usingCtx5 = (0, import_usingCtx.default)();
|
|
@@ -2694,4 +2748,4 @@ async function loadSessionBlockData(options) {
|
|
|
2694
2748
|
_usingCtx5.d();
|
|
2695
2749
|
}
|
|
2696
2750
|
}
|
|
2697
|
-
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, glob, globUsageFiles, identifySessionBlocks, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, projectBlockUsage, sessionUsageSchema, sortFilesByTimestamp, uniq, unwrap, usageDataSchema, weeklyUsageSchema };
|
|
2751
|
+
export { DEFAULT_SESSION_DURATION_HOURS, bucketUsageSchema, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, filterRecentBlocks, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, glob, globUsageFiles, identifySessionBlocks, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, projectBlockUsage, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, uniq, unwrap, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./pricing-fetcher-B5m_kEpz.js";
|
|
2
|
-
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema, weeklyUsageSchema } from "./data-loader-
|
|
3
|
-
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema, weeklyUsageSchema };
|
|
2
|
+
import { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-BPepPoPg.js";
|
|
3
|
+
export { BucketUsage, DailyUsage, DateFilter, GlobResult, LoadOptions, ModelBreakdown, MonthlyUsage, SessionUsage, UsageData, WeeklyUsage, bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
package/dist/data-loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CTYPN13Y.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import "./_types-C0oFKDO-.js";
|
|
4
|
-
import { bucketUsageSchema, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema, weeklyUsageSchema } from "./data-loader-
|
|
5
|
-
import "./logger-
|
|
6
|
-
export { bucketUsageSchema, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, usageDataSchema, weeklyUsageSchema };
|
|
4
|
+
import { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema } from "./data-loader-Plh5X-UR.js";
|
|
5
|
+
import "./logger-dT_AJeHG.js";
|
|
6
|
+
export { bucketUsageSchema, calculateContextTokens, calculateCostForEntry, createUniqueHash, dailyUsageSchema, extractProjectFromPath, formatDate, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, loadBucketUsageData, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, modelBreakdownSchema, monthlyUsageSchema, sessionUsageSchema, sortFilesByTimestamp, transcriptMessageSchema, transcriptUsageSchema, usageDataSchema, weeklyUsageSchema };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-
|
|
2
|
-
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-
|
|
3
|
-
import { logger } from "./logger-
|
|
1
|
+
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, PricingFetcher, USAGE_DATA_GLOB_PATTERN, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-CTYPN13Y.js";
|
|
2
|
+
import { getClaudePaths, glob, unwrap, usageDataSchema } from "./data-loader-Plh5X-UR.js";
|
|
3
|
+
import { logger } from "./logger-dT_AJeHG.js";
|
|
4
4
|
import { readFile } from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
var import_usingCtx = /* @__PURE__ */ __toESM(require_usingCtx(), 1);
|
package/dist/debug.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CTYPN13Y.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import "./_types-C0oFKDO-.js";
|
|
4
|
-
import "./data-loader-
|
|
5
|
-
import "./logger-
|
|
6
|
-
import { detectMismatches, printMismatchReport } from "./debug-
|
|
4
|
+
import "./data-loader-Plh5X-UR.js";
|
|
5
|
+
import "./logger-dT_AJeHG.js";
|
|
6
|
+
import { detectMismatches, printMismatchReport } from "./debug-C4f2zPfQ.js";
|
|
7
7
|
export { detectMismatches, printMismatchReport };
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, WEEK_DAYS, __commonJSMin, __require, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-
|
|
2
|
+
import { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, WEEK_DAYS, __commonJSMin, __require, __toESM, isFailure, require_usingCtx, try_ } from "./pricing-fetcher-CTYPN13Y.js";
|
|
3
3
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
4
4
|
import { CostModes, SortOrders, filterDateSchema, statuslineHookJsonSchema } from "./_types-C0oFKDO-.js";
|
|
5
5
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
6
|
-
import { DEFAULT_SESSION_DURATION_HOURS, calculateBurnRate, calculateCostForEntry, createUniqueHash, filterRecentBlocks, formatDateCompact, getClaudePaths, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, identifySessionBlocks, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, projectBlockUsage, sortFilesByTimestamp, uniq, usageDataSchema } from "./data-loader-
|
|
7
|
-
import { description, log, logger, name, version } from "./logger-
|
|
8
|
-
import { detectMismatches, printMismatchReport } from "./debug-
|
|
9
|
-
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-
|
|
6
|
+
import { DEFAULT_SESSION_DURATION_HOURS, calculateBurnRate, calculateContextTokens, calculateCostForEntry, createUniqueHash, filterRecentBlocks, formatDateCompact, getClaudePaths, getContextUsageThresholds, getEarliestTimestamp, getUsageLimitResetTime, globUsageFiles, identifySessionBlocks, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData, loadSessionUsageById, loadWeeklyUsageData, projectBlockUsage, sortFilesByTimestamp, uniq, usageDataSchema } from "./data-loader-Plh5X-UR.js";
|
|
7
|
+
import { description, log, logger, name, version } from "./logger-dT_AJeHG.js";
|
|
8
|
+
import { detectMismatches, printMismatchReport } from "./debug-C4f2zPfQ.js";
|
|
9
|
+
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-DfY3l9w7.js";
|
|
10
10
|
import a, { readFile } from "node:fs/promises";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
@@ -815,7 +815,7 @@ var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
815
815
|
};
|
|
816
816
|
};
|
|
817
817
|
module.exports = createColors(), module.exports.createColors = createColors;
|
|
818
|
-
}));
|
|
818
|
+
})), import_picocolors$8 = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
819
819
|
const getContext = (raw) => ({
|
|
820
820
|
start: process$1.hrtime.bigint(),
|
|
821
821
|
command: raw.map((part) => getCommandPart(stripVTControlCharacters(part))).join(" "),
|
|
@@ -2320,7 +2320,7 @@ var require_debug$1 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
2320
2320
|
module.exports = Table$1;
|
|
2321
2321
|
})), require_cli_table3 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2322
2322
|
module.exports = require_table();
|
|
2323
|
-
}));
|
|
2323
|
+
})), import_cli_table3 = /* @__PURE__ */ __toESM(require_cli_table3(), 1);
|
|
2324
2324
|
function ansiRegex({ onlyFirst = false } = {}) {
|
|
2325
2325
|
const ST = "(?:\\u0007|\\u001B\\u005C|\\u009C)", pattern = [`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?${ST})`, "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
|
|
2326
2326
|
return new RegExp(pattern, onlyFirst ? void 0 : "g");
|
|
@@ -2369,7 +2369,7 @@ function stringWidth(string, options = {}) {
|
|
|
2369
2369
|
}
|
|
2370
2370
|
return width;
|
|
2371
2371
|
}
|
|
2372
|
-
var
|
|
2372
|
+
var ResponsiveTable = class {
|
|
2373
2373
|
head;
|
|
2374
2374
|
rows = [];
|
|
2375
2375
|
colAligns;
|
|
@@ -4276,7 +4276,17 @@ const statuslineCommand = define({
|
|
|
4276
4276
|
} catch (error) {
|
|
4277
4277
|
logger.error("Failed to load block data:", error), blockInfo = "No active block";
|
|
4278
4278
|
}
|
|
4279
|
-
|
|
4279
|
+
let contextInfo = "";
|
|
4280
|
+
try {
|
|
4281
|
+
const contextData = await calculateContextTokens(hookData.transcript_path);
|
|
4282
|
+
if (contextData != null) {
|
|
4283
|
+
const p$1 = contextData.percentage, thresholds = getContextUsageThresholds(), color = p$1 < thresholds.LOW ? import_picocolors$1.default.green : p$1 < thresholds.MEDIUM ? import_picocolors$1.default.yellow : import_picocolors$1.default.red, coloredPercentage = color(`${p$1}%`), tokenDisplay = contextData.inputTokens.toLocaleString();
|
|
4284
|
+
contextInfo = ` | 🧠 ${tokenDisplay} (${coloredPercentage})`;
|
|
4285
|
+
}
|
|
4286
|
+
} catch (error) {
|
|
4287
|
+
logger.debug(`Failed to calculate context tokens: ${error instanceof Error ? error.message : String(error)}`);
|
|
4288
|
+
}
|
|
4289
|
+
const modelName = hookData.model.display_name, sessionDisplay = sessionCost !== null ? formatCurrency(sessionCost) : "N/A", statusLine = `🤖 ${modelName} | 💰 ${sessionDisplay} session / ${formatCurrency(todayCost)} today / ${blockInfo}${burnRateInfo}${contextInfo}`;
|
|
4280
4290
|
log(statusLine);
|
|
4281
4291
|
}
|
|
4282
4292
|
});
|
|
@@ -4432,3 +4442,4 @@ await cli(process$1.argv.slice(2), mainCommand, {
|
|
|
4432
4442
|
subCommands,
|
|
4433
4443
|
renderHeader: null
|
|
4434
4444
|
});
|
|
4445
|
+
export {};
|
|
@@ -761,7 +761,7 @@ function _getDefaultLogLevel() {
|
|
|
761
761
|
return g ? LogLevels.debug : R ? LogLevels.warn : LogLevels.info;
|
|
762
762
|
}
|
|
763
763
|
const consola = createConsola$1();
|
|
764
|
-
var name = "ccusage", version = "15.9.
|
|
764
|
+
var name = "ccusage", version = "15.9.5", description = "Usage analysis tool for Claude Code";
|
|
765
765
|
const logger = consola.withTag(name);
|
|
766
766
|
if (process$1.env.LOG_LEVEL != null) {
|
|
767
767
|
const level = Number.parseInt(process$1.env.LOG_LEVEL, 10);
|
package/dist/logger.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { log, logger } from "./logger-
|
|
1
|
+
import { log, logger } from "./logger-dT_AJeHG.js";
|
|
2
2
|
export { log, logger };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { __commonJSMin, __toESM, require_usingCtx } from "./pricing-fetcher-
|
|
1
|
+
import { __commonJSMin, __toESM, require_usingCtx } from "./pricing-fetcher-CTYPN13Y.js";
|
|
2
2
|
import { getTotalTokens } from "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import { ZodFirstPartyTypeKind, ZodOptional, ZodType, arrayType, booleanType, discriminatedUnionType, enumType, filterDateSchema, literalType, numberType, objectType, optionalType, recordType, stringType, unionType, unknownType } from "./_types-C0oFKDO-.js";
|
|
4
4
|
import { calculateTotals, createTotalsObject } from "./calculate-cost-BDqO4yWA.js";
|
|
5
|
-
import { getClaudePaths, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData } from "./data-loader-
|
|
6
|
-
import { name, version } from "./logger-
|
|
5
|
+
import { getClaudePaths, loadDailyUsageData, loadMonthlyUsageData, loadSessionBlockData, loadSessionData } from "./data-loader-Plh5X-UR.js";
|
|
6
|
+
import { name, version } from "./logger-dT_AJeHG.js";
|
|
7
7
|
import process from "node:process";
|
|
8
8
|
const LATEST_PROTOCOL_VERSION = "2025-06-18", SUPPORTED_PROTOCOL_VERSIONS = [
|
|
9
9
|
LATEST_PROTOCOL_VERSION,
|
package/dist/mcp.d.ts
CHANGED
package/dist/mcp.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import "./pricing-fetcher-
|
|
1
|
+
import "./pricing-fetcher-CTYPN13Y.js";
|
|
2
2
|
import "./_token-utils-WjkbrjKv.js";
|
|
3
3
|
import "./_types-C0oFKDO-.js";
|
|
4
4
|
import "./calculate-cost-BDqO4yWA.js";
|
|
5
|
-
import "./data-loader-
|
|
6
|
-
import "./logger-
|
|
7
|
-
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-
|
|
5
|
+
import "./data-loader-Plh5X-UR.js";
|
|
6
|
+
import "./logger-dT_AJeHG.js";
|
|
7
|
+
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from "./mcp-DfY3l9w7.js";
|
|
8
8
|
export { createMcpHttpApp, createMcpServer, startMcpServerStdio };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { modelPricingSchema } from "./_types-C0oFKDO-.js";
|
|
2
|
-
import { logger } from "./logger-
|
|
2
|
+
import { logger } from "./logger-dT_AJeHG.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import F, { homedir } from "node:os";
|
|
@@ -94,7 +94,10 @@ if (xdgConfig) xdgConfigDirectories.unshift(xdgConfig);
|
|
|
94
94
|
const LITELLM_PRICING_URL = "https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json", DEFAULT_RECENT_DAYS = 3, BLOCKS_WARNING_THRESHOLD = .8, BLOCKS_COMPACT_WIDTH_THRESHOLD = 120, BLOCKS_DEFAULT_TERMINAL_WIDTH = 120, DEBUG_MATCH_THRESHOLD_PERCENT = .1, USER_HOME_DIR = homedir(), XDG_CONFIG_DIR = xdgConfig ?? `${USER_HOME_DIR}/.config`, DEFAULT_CLAUDE_CODE_PATH = ".claude", DEFAULT_CLAUDE_CONFIG_PATH = `${XDG_CONFIG_DIR}/claude`, CLAUDE_CONFIG_DIR_ENV = "CLAUDE_CONFIG_DIR", PROJECT_ALIASES_ENV = "CCUSAGE_PROJECT_ALIASES", CLAUDE_PROJECTS_DIR_NAME = "projects", USAGE_DATA_GLOB_PATTERN = "**/*.jsonl", MCP_DEFAULT_PORT = 8080, DEFAULT_REFRESH_INTERVAL_SECONDS = 1, MIN_REFRESH_INTERVAL_SECONDS = 1, MAX_REFRESH_INTERVAL_SECONDS = 60, MIN_RENDER_INTERVAL_MS = 16, BURN_RATE_THRESHOLDS = {
|
|
95
95
|
HIGH: 1e3,
|
|
96
96
|
MODERATE: 500
|
|
97
|
-
},
|
|
97
|
+
}, CONTEXT_LIMIT = 2e5, DEFAULT_CONTEXT_USAGE_THRESHOLDS = {
|
|
98
|
+
LOW: 50,
|
|
99
|
+
MEDIUM: 80
|
|
100
|
+
}, CONTEXT_LOW_THRESHOLD_ENV = "CCUSAGE_CONTEXT_LOW_THRESHOLD", CONTEXT_MEDIUM_THRESHOLD_ENV = "CCUSAGE_CONTEXT_MEDIUM_THRESHOLD", WEEK_DAYS = [
|
|
98
101
|
"sunday",
|
|
99
102
|
"monday",
|
|
100
103
|
"tuesday",
|
|
@@ -339,4 +342,4 @@ var require_usingCtx = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
339
342
|
return cost;
|
|
340
343
|
}
|
|
341
344
|
};
|
|
342
|
-
export { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, WEEK_DAYS, __commonJSMin, __require, __toESM, isFailure, isPromise, require_usingCtx, try_ };
|
|
345
|
+
export { BLOCKS_COMPACT_WIDTH_THRESHOLD, BLOCKS_DEFAULT_TERMINAL_WIDTH, BLOCKS_WARNING_THRESHOLD, BURN_RATE_THRESHOLDS, CLAUDE_CONFIG_DIR_ENV, CLAUDE_PROJECTS_DIR_NAME, CONTEXT_LIMIT, CONTEXT_LOW_THRESHOLD_ENV, CONTEXT_MEDIUM_THRESHOLD_ENV, DEBUG_MATCH_THRESHOLD_PERCENT, DEFAULT_CLAUDE_CODE_PATH, DEFAULT_CLAUDE_CONFIG_PATH, DEFAULT_CONTEXT_USAGE_THRESHOLDS, DEFAULT_RECENT_DAYS, DEFAULT_REFRESH_INTERVAL_SECONDS, MAX_REFRESH_INTERVAL_SECONDS, MCP_DEFAULT_PORT, MIN_REFRESH_INTERVAL_SECONDS, MIN_RENDER_INTERVAL_MS, PROJECT_ALIASES_ENV, PricingFetcher, USAGE_DATA_GLOB_PATTERN, USER_HOME_DIR, WEEK_DAYS, __commonJSMin, __require, __toESM, isFailure, isPromise, require_usingCtx, try_ };
|
package/dist/pricing-fetcher.js
CHANGED