Skip to content

Commit e2062be

Browse files
committed
fix!: replace deprecated getDefaultClaudePath with getClaudePaths
BREAKING CHANGE: getDefaultClaudePath() has been replaced with getClaudePaths() which returns an array of paths. - Replace getDefaultClaudePath with getClaudePaths in mcp.ts - Replace getDefaultClaudePath with getClaudePaths in commands/mcp.ts - Replace getDefaultClaudePath with getClaudePaths in blocks.ts - Replace getDefaultClaudePath with getClaudePaths in debug.ts - Add proper error handling for empty path arrays
1 parent 7a65661 commit e2062be

4 files changed

Lines changed: 30 additions & 8 deletions

File tree

src/commands/blocks.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from '../_session-blocks.ts';
1313
import { sharedCommandConfig } from '../_shared-args.ts';
1414
import { formatCurrency, formatModelsDisplayMultiline, formatNumber, ResponsiveTable } from '../_utils.ts';
15-
import { getDefaultClaudePath, loadSessionBlockData } from '../data-loader.ts';
15+
import { getClaudePaths, loadSessionBlockData } from '../data-loader.ts';
1616
import { log, logger } from '../logger.ts';
1717
import { startLiveMonitoring } from './_blocks.live.ts';
1818

@@ -232,8 +232,14 @@ export const blocksCommand = define({
232232
}
233233

234234
// Start live monitoring
235+
const paths = getClaudePaths();
236+
if (paths.length === 0) {
237+
logger.error('No valid Claude data directory found');
238+
throw new Error('No valid Claude data directory found');
239+
}
240+
235241
await startLiveMonitoring({
236-
claudePath: getDefaultClaudePath(),
242+
claudePath: paths[0]!,
237243
tokenLimit: parseTokenLimit(tokenLimitValue, maxTokensFromAll),
238244
refreshInterval: refreshInterval * 1000, // Convert to milliseconds
239245
sessionDurationHours: ctx.values.sessionLength,

src/commands/mcp.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { serve } from '@hono/node-server';
22
import { define } from 'gunshi';
33
import { MCP_DEFAULT_PORT } from '../_consts.ts';
44
import { sharedArgs } from '../_shared-args.ts';
5-
import { getDefaultClaudePath } from '../data-loader.ts';
5+
import { getClaudePaths } from '../data-loader.ts';
66
import { logger } from '../logger.ts';
77
import { createMcpHttpApp, createMcpServer, startMcpServerStdio } from '../mcp.ts';
88

@@ -35,8 +35,14 @@ export const mcpCommand = define({
3535
logger.level = 0;
3636
}
3737

38+
const paths = getClaudePaths();
39+
if (paths.length === 0) {
40+
logger.error('No valid Claude data directory found');
41+
throw new Error('No valid Claude data directory found');
42+
}
43+
3844
const options = {
39-
claudePath: getDefaultClaudePath(),
45+
claudePath: paths[0]!,
4046
mode,
4147
};
4248

src/debug.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import path from 'node:path';
1212
import { createFixture } from 'fs-fixture';
1313
import { glob } from 'tinyglobby';
1414
import { CLAUDE_PROJECTS_DIR_NAME, DEBUG_MATCH_THRESHOLD_PERCENT, USAGE_DATA_GLOB_PATTERN } from './_consts.ts';
15-
import { getDefaultClaudePath, usageDataSchema } from './data-loader.ts';
15+
import { getClaudePaths, usageDataSchema } from './data-loader.ts';
1616
import { logger } from './logger.ts';
1717
import { PricingFetcher } from './pricing-fetcher.ts';
1818

@@ -73,7 +73,17 @@ type MismatchStats = {
7373
export async function detectMismatches(
7474
claudePath?: string,
7575
): Promise<MismatchStats> {
76-
const claudeDir = claudePath ?? path.join(getDefaultClaudePath(), CLAUDE_PROJECTS_DIR_NAME);
76+
let claudeDir: string;
77+
if (claudePath != null && claudePath !== '') {
78+
claudeDir = claudePath;
79+
}
80+
else {
81+
const paths = getClaudePaths();
82+
if (paths.length === 0) {
83+
throw new Error('No valid Claude data directory found');
84+
}
85+
claudeDir = path.join(paths[0]!, CLAUDE_PROJECTS_DIR_NAME);
86+
}
7787
const files = await glob([USAGE_DATA_GLOB_PATTERN], {
7888
cwd: claudeDir,
7989
absolute: true,

src/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { z } from 'zod';
2121
import { name, version } from '../package.json';
2222
import { filterDateSchema } from './_types.ts';
2323
import {
24-
getDefaultClaudePath,
24+
getClaudePaths,
2525
loadDailyUsageData,
2626
loadMonthlyUsageData,
2727
loadSessionBlockData,
@@ -30,7 +30,7 @@ import {
3030

3131
/** Default options for the MCP server */
3232
const defaultOptions = {
33-
claudePath: getDefaultClaudePath(),
33+
claudePath: getClaudePaths()[0] ?? '',
3434
} as const satisfies LoadOptions;
3535

3636
/**

0 commit comments

Comments
 (0)