@@ -357,19 +357,46 @@ def main():
357357
358358 # Test if ccusage is available by running a quick command
359359 print (f"{ cyan } Checking ccusage availability...{ reset } " )
360+ ccusage_available = False
361+ method_used = None
362+
363+ # Try direct command first
360364 try :
361365 subprocess .run (
362- ["npx" , " ccusage" , "--version" ],
366+ ["ccusage" , "--version" ],
363367 capture_output = True ,
364368 text = True ,
365369 check = True ,
366370 timeout = 10 ,
367371 )
368- print (f"{ cyan } ✓ ccusage is available{ reset } " )
369- except (subprocess .CalledProcessError , subprocess .TimeoutExpired ) as e :
372+ ccusage_available = True
373+ method_used = "direct"
374+ except (subprocess .CalledProcessError , subprocess .TimeoutExpired , FileNotFoundError ):
375+ pass
376+
377+ # If direct command failed, try npx
378+ if not ccusage_available :
379+ try :
380+ subprocess .run (
381+ ["npx" , "ccusage" , "--version" ],
382+ capture_output = True ,
383+ text = True ,
384+ check = True ,
385+ timeout = 10 ,
386+ )
387+ ccusage_available = True
388+ method_used = "npx"
389+ except (subprocess .CalledProcessError , subprocess .TimeoutExpired , FileNotFoundError ):
390+ pass
391+
392+ if ccusage_available :
393+ print (f"{ cyan } ✓ ccusage is available (using { method_used } method){ reset } " )
394+ else :
370395 print (f"{ red } ✗ ccusage check failed{ reset } " )
371396 print (f"{ yellow } Please ensure ccusage is installed:{ reset } " )
372397 print (f" npm install -g ccusage" )
398+ print (f"\n { yellow } If you're using npm 7+ and have ccusage installed globally,{ reset } " )
399+ print (f"{ yellow } you may need to add npm's global bin directory to your PATH.{ reset } " )
373400 print (f"\n { yellow } Also make sure you're logged into Claude in your browser{ reset } " )
374401 sys .exit (1 )
375402
@@ -411,6 +438,7 @@ def main():
411438 screen_buffer .append ("" )
412439 screen_buffer .append (f"{ yellow } Possible causes:{ reset } " )
413440 screen_buffer .append (f" • ccusage is not installed (run: npm install -g ccusage)" )
441+ screen_buffer .append (f" • For npm 7+: ccusage may be in PATH but npx can't find it" )
414442 screen_buffer .append (f" • You're not logged into Claude" )
415443 screen_buffer .append (f" • Network connection issues" )
416444 screen_buffer .append ("" )
0 commit comments