Skip to content

Conversation

@nakatanakatana
Copy link
Contributor

@nakatanakatana nakatanakatana commented Jun 17, 2025

fix #90

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation of the Claude config directory by ensuring a required 'projects' subdirectory exists when using a custom configuration path.
  • Tests

    • Updated test cases and fixtures to align with the new directory validation requirements.

@coderabbitai
Copy link

coderabbitai bot commented Jun 17, 2025

Warning

Rate limit exceeded

@ryoppippi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 16 minutes and 47 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 293462d54f709c284880b8896dc423e8fa60e30d and 7f606e8.

📒 Files selected for processing (1)
  • src/data-loader.ts (4 hunks)

Walkthrough

The logic of the getDefaultClaudePath function in src/data-loader.ts was updated to require that the 'projects' subdirectory exists within the configured Claude config directory. Test fixtures and related test cases were also updated to reflect this new validation, ensuring alignment with the revised directory structure requirements.

Changes

File(s) Change Summary
src/data-loader.ts Modified getDefaultClaudePath to validate the existence of a 'projects' subdirectory within the config directory.
(test fixtures, test cases) Updated test fixtures and cases to use 'projects' subdirectory, renaming directories as needed for alignment.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Env
    participant FS

    Caller->>Env: Read CLAUDE_CONFIG_DIR
    alt CLAUDE_CONFIG_DIR unset or empty
        Caller->>FS: Check ~/.claude/projects exists
        alt projects exists
            FS-->>Caller: Return ~/.claude
        else projects missing
            FS-->>Caller: Throw error
        end
    else CLAUDE_CONFIG_DIR is set
        Caller->>FS: Check $CLAUDE_CONFIG_DIR/projects exists
        alt projects exists
            FS-->>Caller: Return $CLAUDE_CONFIG_DIR
        else projects missing
            FS-->>Caller: Throw error referencing projects path
        end
    end
Loading

Assessment against linked issues

Objective Addressed Explanation
Revert to v8 behavior: Only require permissions for .claude/projects subdirectory, not entire .claude directory (#90)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Possibly related PRs

Poem

A rabbit hopped in Claude’s domain,
Tweaked the path, then checked again.
“Projects” must be found inside,
Or else the code will not abide.
Now tests align, the logic’s neat—
This patch has made the config sweet!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Summary of Changes

Hello @nakatanakatana, 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 addresses an issue by refining how the Claude data directory is validated. The core change involves enforcing the presence of a 'projects' subdirectory within the configured data path, making the path resolution more explicit and robust. This ensures that the application relies on a correctly structured data directory.

Highlights

  • Improved Data Directory Validation: The getDefaultClaudePath function now includes a more robust validation check. It ensures that the directory specified by CLAUDE_CONFIG_DIR (or the default ~/.claude path) contains a mandatory projects subdirectory. If this subdirectory is not found, an error is now explicitly thrown, providing clearer feedback to the user.
  • Enhanced Test Coverage: New test cases have been added to data-loader.test.ts to specifically verify the improved validation logic. These tests confirm that getDefaultClaudePath correctly throws an error when the CLAUDE_CONFIG_DIR points to a location that lacks the expected projects subdirectory. Existing test fixtures were also updated to align with the new expectation of a projects subdirectory.
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.

Copy link
Contributor

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

Choose a reason for hiding this comment

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

Code Review

This pull request addresses issue #90 by improving the validation logic for the CLAUDE_CONFIG_DIR environment variable. The getDefaultClaudePath function now correctly checks for the existence of the projects subdirectory within the specified path when the environment variable is set, aligning with the expected data structure. Tests have been updated and a new test added to cover this specific validation case. The changes are well-implemented and improve the robustness of the data loading process.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/data-loader.ts (1)

34-41: Validate the fallback path as well

getDefaultClaudePath now guarantees projects/ exists only when CLAUDE_CONFIG_DIR is set.
When the variable is not set we blindly return ~/.claude even if that directory (and its projects sub-dir) is missing.
load* functions later on use this path as cwd for tinyglobby; if it does not exist tinyglobby will throw, causing a less helpful stack trace.

-		return DEFAULT_CLAUDE_CODE_PATH;
+		const defaultProjectsPath = path.join(DEFAULT_CLAUDE_CODE_PATH, 'projects');
+		if (!isDirectorySync(defaultProjectsPath)) {
+			throw new Error(
+				`Claude data directory does not exist: ${defaultProjectsPath}. ` +
+				`Create it or set CLAUDE_CONFIG_DIR.`
+			);
+		}
+		return DEFAULT_CLAUDE_CODE_PATH;
🧹 Nitpick comments (2)
src/data-loader.ts (1)

37-38: Super-fluous leading whitespace in error message

The template literal starts with a space, producing " Claude data directory…".
Trimming later removes line-breaks but keeps the leading space.

-			` Claude data directory does not exist: ${claudeCodeProjectsPath}. 
+			`Claude data directory does not exist: ${claudeCodeProjectsPath}. 
src/data-loader.test.ts (1)

103-110: Fix typo in test description

Minor typo: “dose” → “does”.

-test('throws an error when CLAUDE_CONFIG_DIR dose not have a "projects" directory', async () => {
+test('throws an error when CLAUDE_CONFIG_DIR does not have a "projects" directory', async () => {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3506c38 and da6d10da78d580f49021c14d44043a074087a1c8.

📒 Files selected for processing (2)
  • src/data-loader.test.ts (2 hunks)
  • src/data-loader.ts (1 hunks)
🧰 Additional context used
🪛 ESLint
src/data-loader.test.ts

[error] 98-98: Unsafe member access .env on an error typed value.

(ts/no-unsafe-member-access)


[error] 98-98: Unsafe member access .path on an error typed value.

(ts/no-unsafe-member-access)


[error] 100-100: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 100-100: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 100-100: Unsafe member access .toBe on an error typed value.

(ts/no-unsafe-member-access)


[error] 100-100: Unsafe member access .path on an error typed value.

(ts/no-unsafe-member-access)


[error] 103-103: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 104-106: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 104-104: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 107-107: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 107-107: Unsafe member access .env on an error typed value.

(ts/no-unsafe-member-access)


[error] 107-107: Unsafe member access .path on an error typed value.

(ts/no-unsafe-member-access)


[error] 109-109: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 109-109: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 109-109: Unsafe member access .toThrow on an error typed value.

(ts/no-unsafe-member-access)

src/data-loader.ts

[error] 29-29: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 29-29: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 29-29: Unsafe member access .env on an error typed value.

(ts/no-unsafe-member-access)


[error] 31-31: Unsafe return of a value of type error.

(ts/no-unsafe-return)


[error] 34-34: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 34-34: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 34-34: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


[error] 35-35: Unexpected any value in conditional. An explicit comparison or type conversion is required.

(ts/strict-boolean-expressions)


[error] 35-35: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (2)
src/data-loader.test.ts (2)

74-82: Fixture update LGTM

Switching the fixture root to contain a projects directory mirrors the new validation logic and keeps the test meaningful.


93-101: Consistent fixture trimming

Same positive change as above – no action needed.

@ryoppippi
Copy link
Owner

hi. please resolve conflicts!

Copy link
Owner

@ryoppippi ryoppippi left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

Copilot AI left a comment

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 improves validation for the Claude data directory by ensuring that the required "projects" subdirectory exists, thereby providing clearer error messages when it is missing. In addition, the test coverage has been updated to verify this stricter validation behavior.

  • Improved directory validation by checking for the existence of a "projects" subdirectory.
  • Updated test fixtures to reflect the new configuration requirements.
Comments suppressed due to low confidence (2)

src/data-loader.ts:34

  • [nitpick] Consider adding a comment explaining why an empty CLAUDE_CONFIG_DIR results in returning DEFAULT_CLAUDE_CODE_PATH. This would improve clarity for future maintainers.
	if (envClaudeCodePath === '') {

src/data-loader.ts:1059

  • [nitpick] Ensure the test fixture change from 'claude' to 'projects' aligns with the updated validation logic for the directory structure. Additional tests verifying the absence of the 'projects' subdirectory could further enhance coverage.
				projects: {},

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jun 17, 2025

Open in StackBlitz

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

commit: 7f606e8

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/data-loader.ts (1)

33-38: Still missing the early check that CLAUDE_CONFIG_DIR itself is a directory

The earlier review already pointed this out: if CLAUDE_CONFIG_DIR points to an existing file (or broken symlink), the current logic happily appends projects and only fails on that sub-path, yielding a misleading error.
Fail fast on the base path first and keep the existing projects check.

 	const envClaudeCodePath = process.env.CLAUDE_CONFIG_DIR?.trim() ?? '';
 	if (envClaudeCodePath === '') {
 		return DEFAULT_CLAUDE_CODE_PATH;
 	}

+	// Validate that the env path itself exists *and* is a directory
+	if (!isDirectorySync(envClaudeCodePath)) {
+		throw new Error(
+			`CLAUDE_CONFIG_DIR must point to an existing directory: ${envClaudeCodePath}`,
+		);
+	}
+
 	const claudeCodeProjectsPath = path.join(envClaudeCodePath, 'projects');
🧹 Nitpick comments (2)
src/data-loader.ts (2)

41-44: Error message formatting nit

There is an unintended leading space and super-fluous newline in the thrown message.

-			` Claude data directory does not exist: ${claudeCodeProjectsPath}. 
+			`Claude data directory does not exist: ${claudeCodeProjectsPath}.
 			 Please set CLAUDE_CONFIG_DIR to a valid path, or ensure ${DEFAULT_CLAUDE_CODE_PATH} exists.

33-35: ESLint “unsafe-*” warnings originate from the untyped process.env access

Casting once avoids the cascade of ts/no-unsafe-* complaints:

-	const envClaudeCodePath = process.env.CLAUDE_CONFIG_DIR?.trim() ?? '';
+	const envClaudeCodePath = (process.env.CLAUDE_CONFIG_DIR ?? '').trim();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da6d10da78d580f49021c14d44043a074087a1c8 and 293462d54f709c284880b8896dc423e8fa60e30d.

📒 Files selected for processing (1)
  • src/data-loader.ts (3 hunks)
🧰 Additional context used
🪛 ESLint
src/data-loader.ts

[error] 33-33: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 33-33: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 33-33: Unsafe member access .env on an error typed value.

(ts/no-unsafe-member-access)


[error] 35-35: Unsafe return of a value of type error.

(ts/no-unsafe-return)


[error] 38-38: Unsafe assignment of an error typed value.

(ts/no-unsafe-assignment)


[error] 38-38: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)


[error] 38-38: Unsafe member access .join on an error typed value.

(ts/no-unsafe-member-access)


[error] 39-39: Unexpected any value in conditional. An explicit comparison or type conversion is required.

(ts/strict-boolean-expressions)


[error] 39-39: Unsafe call of a(n) error type typed value.

(ts/no-unsafe-call)

nakatanakatana and others added 2 commits June 17, 2025 21:25
- Add validation to check if CLAUDE_CONFIG_DIR itself exists and is a
directory before checking the projects subfolder
- Provide clearer error message when CLAUDE_CONFIG_DIR is invalid (e.g.,
file, broken symlink, or non-existent)
- This prevents confusing downstream errors and improves user experience
with early error detection
- Also fix minor formatting issue in error message (remove extra leading
space)
@ryoppippi ryoppippi merged commit 468f18e into ryoppippi:main Jun 17, 2025
7 checks passed
ryoppippi added a commit that referenced this pull request Jun 22, 2025
fix: improve Claude data directory validation
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.

Deno: Increased permissions required, command in README fails

2 participants