@@ -17,8 +17,7 @@ import type {
1717 Version ,
1818} from './_types.ts' ;
1919import { readFile } from 'node:fs/promises' ;
20- import { homedir } from 'node:os' ;
21- import path , { join } from 'node:path' ;
20+ import path from 'node:path' ;
2221import process from 'node:process' ;
2322import { toArray } from '@antfu/utils' ;
2423import { unreachable } from '@core/errorutil' ;
@@ -119,41 +118,6 @@ export function getClaudePaths(): string[] {
119118 return paths ;
120119}
121120
122- /**
123- * Default path for Claude data directory
124- * Uses environment variable CLAUDE_CONFIG_DIR if set, otherwise defaults to ~/.claude
125- * @deprecated Use getClaudePaths() instead for multiple path support
126- */
127- export function getDefaultClaudePath ( ) : string {
128- // Check environment variable first
129- const envPath = ( process . env [ CLAUDE_CONFIG_DIR_ENV ] ?? '' ) . trim ( ) ;
130- if ( envPath !== '' ) {
131- // For backward compatibility, only use the first path if multiple are provided
132- const firstPath = envPath . split ( ',' ) [ 0 ] ?. trim ( ) ;
133- if ( firstPath != null && firstPath !== '' ) {
134- if ( ! isDirectorySync ( firstPath ) ) {
135- throw new Error ( `CLAUDE_CONFIG_DIR path is not a valid directory: ${ firstPath } ` ) ;
136- }
137- return firstPath ;
138- }
139- }
140-
141- // Prefer the new default path (XDG config directory) if it exists
142- const newDefaultPath = DEFAULT_CLAUDE_CONFIG_PATH ;
143- if ( isDirectorySync ( newDefaultPath ) ) {
144- return newDefaultPath ;
145- }
146-
147- // Fall back to the old default path ~/.claude for backward compatibility
148- const oldDefaultPath = path . join ( USER_HOME_DIR , DEFAULT_CLAUDE_CODE_PATH ) ;
149- if ( isDirectorySync ( oldDefaultPath ) ) {
150- return oldDefaultPath ;
151- }
152-
153- // If neither exists, return the old default for backward compatibility
154- return oldDefaultPath ;
155- }
156-
157121/**
158122 * Zod schema for validating Claude usage data from JSONL files
159123 */
@@ -1183,68 +1147,6 @@ if (import.meta.vitest != null) {
11831147 } ) ;
11841148 } ) ;
11851149
1186- describe ( 'getDefaultClaudePath' , ( ) => {
1187- afterEach ( ( ) => {
1188- // Clean up any environment variable mocks
1189- vi . unstubAllEnvs ( ) ;
1190- } ) ;
1191-
1192- it ( 'returns CLAUDE_CONFIG_DIR when environment variable is set' , async ( ) => {
1193- await using fixture = await createFixture ( {
1194- projects : { } ,
1195- } ) ;
1196-
1197- // Use vitest's environment variable stubbing
1198- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , fixture . path ) ;
1199-
1200- expect ( getDefaultClaudePath ( ) ) . toBe ( fixture . path ) ;
1201- } ) ;
1202-
1203- it ( 'returns default path when CLAUDE_CONFIG_DIR is not set' , ( ) => {
1204- // Explicitly ensure the environment variable is not set
1205- // Use undefined to indicate the env var should not be set
1206- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , undefined as string | undefined ) ;
1207-
1208- // Test that it returns the default path (which can be either .config/claude or .claude)
1209- const actualPath = getDefaultClaudePath ( ) ;
1210- expect ( actualPath ) . toMatch ( / \. ( c o n f i g \/ c l a u d e | c l a u d e ) $ / ) ;
1211- expect ( actualPath ) . toContain ( homedir ( ) ) ;
1212- } ) ;
1213-
1214- it ( 'returns default path with trimmed CLAUDE_CONFIG_DIR' , async ( ) => {
1215- await using fixture = await createFixture ( {
1216- projects : { } ,
1217- } ) ;
1218-
1219- // Test with extra spaces using vitest env stubbing
1220- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , ` ${ fixture . path } ` ) ;
1221-
1222- expect ( getDefaultClaudePath ( ) ) . toBe ( fixture . path ) ;
1223- } ) ;
1224-
1225- it ( 'throws an error when CLAUDE_CONFIG_DIR is not a directory' , async ( ) => {
1226- await using fixture = await createFixture ( ) ;
1227- const nonExistentPath = join ( fixture . path , 'not-a-directory' ) ;
1228-
1229- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , nonExistentPath ) ;
1230-
1231- expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C L A U D E _ C O N F I G _ D I R p a t h i s n o t a v a l i d d i r e c t o r y / ) ;
1232- } ) ;
1233-
1234- it ( 'throws an error when CLAUDE_CONFIG_DIR does not exist' , ( ) => {
1235- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , '/nonexistent/path/that/does/not/exist' ) ;
1236-
1237- expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C L A U D E _ C O N F I G _ D I R p a t h i s n o t a v a l i d d i r e c t o r y / ) ;
1238- } ) ;
1239-
1240- it ( 'throws an error when default path does not exist' , ( ) => {
1241- // Set to a non-existent path
1242- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , '/nonexistent/path/.claude' ) ;
1243-
1244- expect ( ( ) => getDefaultClaudePath ( ) ) . toThrow ( / C L A U D E _ C O N F I G _ D I R p a t h i s n o t a v a l i d d i r e c t o r y / ) ;
1245- } ) ;
1246- } ) ;
1247-
12481150 describe ( 'loadDailyUsageData' , ( ) => {
12491151 it ( 'returns empty array when no files found' , async ( ) => {
12501152 await using fixture = await createFixture ( {
@@ -3666,45 +3568,6 @@ if (import.meta.vitest != null) {
36663568 } ) ;
36673569 } ) ;
36683570
3669- describe ( 'getDefaultClaudePath (deprecated)' , ( ) => {
3670- afterEach ( ( ) => {
3671- vi . unstubAllEnvs ( ) ;
3672- } ) ;
3673-
3674- it ( 'uses environment variable when set' , async ( ) => {
3675- await using fixture = await createFixture ( {
3676- projects : { } ,
3677- } ) ;
3678-
3679- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , fixture . path ) ;
3680-
3681- expect ( getDefaultClaudePath ( ) ) . toBe ( fixture . path ) ;
3682- } ) ;
3683-
3684- it ( 'prefers new default path over old when both exist' , async ( ) => {
3685- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , '' ) ;
3686-
3687- // In CI environment, both paths are created, so it should prefer new one
3688- const result = getDefaultClaudePath ( ) ;
3689- // Should contain either the new path or old path
3690- expect ( typeof result ) . toBe ( 'string' ) ;
3691- expect ( result . length ) . toBeGreaterThan ( 0 ) ;
3692- } ) ;
3693-
3694- it ( 'falls back to first environment path when multiple provided' , async ( ) => {
3695- await using fixture1 = await createFixture ( {
3696- projects : { } ,
3697- } ) ;
3698- await using fixture2 = await createFixture ( {
3699- projects : { } ,
3700- } ) ;
3701-
3702- vi . stubEnv ( 'CLAUDE_CONFIG_DIR' , `${ fixture1 . path } ,${ fixture2 . path } ` ) ;
3703-
3704- expect ( path . resolve ( getDefaultClaudePath ( ) ) ) . toBe ( path . resolve ( fixture1 . path ) ) ;
3705- } ) ;
3706- } ) ;
3707-
37083571 describe ( 'getClaudePaths' , ( ) => {
37093572 afterEach ( ( ) => {
37103573 vi . unstubAllEnvs ( ) ;
0 commit comments