Skip to content

Commit ec2e2e7

Browse files
Update ccusage nitializatio & fix colors
1 parent 28274ef commit ec2e2e7

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77
- Fixed ccusage command hanging indefinitely by adding 30-second timeout to subprocess calls
88
- Added ccusage availability check at startup with helpful error messages
99
- Improved error display when ccusage fails with better debugging information
10+
- Fixed npm 7+ compatibility issue where npx doesn't find globally installed packages
1011

1112
### Added
1213
- Timeout handling for all ccusage subprocess calls to prevent hanging
1314
- Pre-flight check for ccusage availability before entering main loop
1415
- More informative error messages suggesting installation steps and login requirements
16+
- Dual command execution: tries direct `ccusage` command first, then falls back to `npx ccusage`
17+
- Detection and reporting of which method (direct or npx) is being used
1518

1619
## [1.0.11] - 2025-06-22
1720

claude_monitor.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)