fix: use getClaudePaths for multi-directory support by nicobailon · Pull Request #129 · ccusage/ccusage · GitHub
Skip to content

fix: use getClaudePaths for multi-directory support#129

Merged
ryoppippi merged 1 commit into
ccusage:mainfrom
nicobailon:fix-claude-path
Jun 20, 2025
Merged

fix: use getClaudePaths for multi-directory support#129
ryoppippi merged 1 commit into
ccusage:mainfrom
nicobailon:fix-claude-path

Conversation

@nicobailon

@nicobailon nicobailon commented Jun 20, 2025

Copy link
Copy Markdown
Contributor
  • Remove claudePath parameter from data loading functions in all commands
  • This allows the data loader to check multiple Claude directories automatically
  • Supports both ~/.config/claude and ~/.claude paths
  • Fixes 'No Claude usage data found' error when data exists in alternate locations

Summary by CodeRabbit

  • Refactor
    • Simplified data loading and mismatch detection by removing explicit usage of the default Claude path across several commands. The system now defaults to implicit or no path, streamlining internal processes. No changes to user-facing features or command usage.

- Remove claudePath parameter from data loading functions in all commands
- This allows the data loader to check multiple Claude directories automatically
- Supports both ~/.config/claude and ~/.claude paths
- Fixes 'No Claude usage data found' error when data exists in alternate locations
@coderabbitai

coderabbitai Bot commented Jun 20, 2025

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @nicobailon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors how Claude usage data is located and loaded by various commands. It removes the need for commands to explicitly provide a claudePath, instead enabling the data loader to automatically discover usage data across multiple common directory locations. This change resolves issues where data might not be found if stored in alternative, yet valid, paths.

Highlights

  • Data Loading Enhancement: The claudePath parameter has been removed from data loading function calls across blocks, daily, monthly, and session commands. This delegates the responsibility of path discovery to the underlying data loader, which now supports multiple Claude data directories.
  • Multi-Directory Support: The system now automatically checks common Claude data locations (e.g., ~/.config/claude and ~/.claude), improving robustness and user experience by preventing 'No Claude usage data found' errors when data exists in alternate, yet valid, paths.
  • Simplified Command Logic: Commands like blocks, daily, monthly, and session are simplified by no longer needing to manage or pass the claudePath, making their code cleaner and more maintainable.
  • Improved Debugging: The detectMismatches function in daily, monthly, and session commands has also been updated to leverage the new automatic path discovery, ensuring debug information is gathered from all relevant locations.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request removes the claudePath parameter from data loading functions, enabling the data loader to automatically check multiple Claude directories, supporting both ~/.config/claude and ~/.claude paths. This fixes the 'No Claude usage data found' error when data exists in alternate locations. I have suggested a few minor improvements to the code.

Comment thread src/commands/daily.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Passing undefined explicitly here might not be the most readable approach. Consider if there's a way to omit the parameter entirely when ctx.values.debug is false to simplify the call.

Suggested change
const mismatchStats = await detectMismatches(undefined);
const mismatchStats = await detectMismatches();

Comment thread src/commands/monthly.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Passing undefined explicitly here might not be the most readable approach. Consider if there's a way to omit the parameter entirely when ctx.values.debug is false to simplify the call.

Suggested change
const mismatchStats = await detectMismatches(undefined);
const mismatchStats = await detectMismatches();

Comment thread src/commands/session.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Passing undefined explicitly here might not be the most readable approach. Consider if there's a way to omit the parameter entirely when ctx.values.debug is false to simplify the call.

Suggested change
const mismatchStats = await detectMismatches(undefined);
const mismatchStats = await detectMismatches();

@ryoppippi ryoppippi requested review from Copilot and ryoppippi June 20, 2025 21:08
@pkg-pr-new

pkg-pr-new Bot commented Jun 20, 2025

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/ryoppippi/ccusage@129

commit: 0131077

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the explicit usage of the default Claude path in several commands to enable multi-directory support, allowing for automatic detection of usage data in both ~/.config/claude and ~/.claude.

  • Removed the claudePath parameter from data loading functions and their corresponding calls.
  • Updated debug functionality to pass an undefined value instead of getDefaultClaudePath.
  • Similar changes applied across session, monthly, daily, and blocks commands.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/commands/session.ts Removed claudePath parameter and updated detectMismatches call.
src/commands/monthly.ts Removed claudePath parameter and updated detectMismatches call.
src/commands/daily.ts Removed claudePath parameter and updated detectMismatches call.
src/commands/blocks.ts Removed claudePath parameter from session block loading.

Comment thread src/commands/session.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If detectMismatches has a default parameter for handling undefined, consider omitting the argument entirely to enhance clarity.

Suggested change
const mismatchStats = await detectMismatches(undefined);
const mismatchStats = await detectMismatches();

Copilot uses AI. Check for mistakes.
Comment thread src/commands/monthly.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] If detectMismatches supports a default value when no argument is provided, consider calling it without passing undefined directly.

Suggested change
const mismatchStats = await detectMismatches(undefined);
const mismatchStats = await detectMismatches();

Copilot uses AI. Check for mistakes.
Comment thread src/commands/daily.ts
// Show debug information if requested
if (ctx.values.debug && !ctx.values.json) {
const mismatchStats = await detectMismatches(getDefaultClaudePath());
const mismatchStats = await detectMismatches(undefined);

Copilot AI Jun 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] To improve code clarity, consider invoking detectMismatches without parameters if the function already defaults to checking multiple directories.

Suggested change

Copilot uses AI. Check for mistakes.

@ryoppippi ryoppippi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
good PR
thanks

@ryoppippi ryoppippi merged commit c11e0c6 into ccusage:main Jun 20, 2025
7 checks passed
ryoppippi added a commit that referenced this pull request Jun 22, 2025
fix: use getClaudePaths for multi-directory support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants