Skip to content

Conversation

@santonakakis
Copy link

@santonakakis santonakakis commented Jul 25, 2025

Add support for CLAUDE_CONFIG_DIR environment variable

Summary

This PR adds support for the CLAUDE_CONFIG_DIR environment variable used by Claude Code (Anthropic's official CLI), enabling claude-monitor to work with Claude Code's configuration directory structure.

Problem

Currently, claude-monitor only looks for data in:

  • ~/.claude/projects
  • ~/.config/claude/projects

However, Claude Code uses a different structure where:

  • Configuration can be in any directory specified by CLAUDE_CONFIG_DIR
  • The .claude directory is directly used, not a projects subdirectory
  • Multiple configurations can exist for different workspaces

Solution

Modified the get_standard_claude_paths() function to:

  1. Check CLAUDE_CONFIG_DIR environment variable first
  2. Support running from within a .claude directory
  3. Add Claude Code's default ~/.claude location to the search paths
  4. Maintain backward compatibility with existing paths

Changes

def get_standard_claude_paths() -> List[str]:
    """Get list of standard Claude data directory paths to check.
    
    Now supports CLAUDE_CONFIG_DIR environment variable for Claude Code compatibility.
    """
    paths = []
    
    # Check CLAUDE_CONFIG_DIR first (Claude Code standard)
    claude_config_dir = os.environ.get("CLAUDE_CONFIG_DIR")
    if claude_config_dir:
        # For Claude Code, the data is directly in CLAUDE_CONFIG_DIR/.claude
        config_path = Path(claude_config_dir).expanduser()
        if config_path.name == ".claude":
            # If CLAUDE_CONFIG_DIR already points to .claude, use it directly
            paths.append(str(config_path))
        else:
            # Otherwise, append .claude
            paths.append(str(config_path / ".claude"))
    
    # Also check current directory for .claude (when running from within .claude dir)
    cwd_claude = Path.cwd()
    if cwd_claude.name == ".claude" and cwd_claude.exists():
        paths.append(str(cwd_claude))
    
    # Fall back to original paths and Claude Code's default location
    paths.extend(["~/.claude/projects", "~/.config/claude/projects", "~/.claude"])
    
    return paths

Testing

Tested with multiple Claude Code configurations:

  • CLAUDE_CONFIG_DIR=$HOME/ccmax.pdi01 claude-monitor
  • CLAUDE_CONFIG_DIR=$HOME/cc_pers claude-monitor
  • cd ~/.claude && claude-monitor
  • Running without CLAUDE_CONFIG_DIR still works with original paths ✓

Use Case

This enables users to monitor multiple Claude Code instances in a tmux dashboard:

# Monitor different Claude configurations
tmux new-session -d
tmux send-keys "CLAUDE_CONFIG_DIR=$HOME/workspace1 claude-monitor" C-m
tmux split-window
tmux send-keys "CLAUDE_CONFIG_DIR=$HOME/workspace2 claude-monitor" C-m

Author

Steve Antonakakis ([email protected]) on behalf of AeyeOps

Backward Compatibility

All existing functionality is preserved. The changes only add new search paths and do not modify the behavior for users not using Claude Code.

Summary by CodeRabbit

  • New Features

    • Expanded support for discovering Claude data directories, including detection via an environment variable and the current working directory.
  • Chores

    • Improved internal handling of directory paths for enhanced flexibility.

This adds support for the CLAUDE_CONFIG_DIR environment variable used by Claude Code (Anthropic's official CLI), enabling claude-monitor to work with Claude Code's configuration directory structure.

The changes:
- Add import os for environment variable access
- Modify get_standard_claude_paths() to check CLAUDE_CONFIG_DIR first
- Support running from within a .claude directory
- Add Claude Code's default ~/.claude location to search paths
- Maintain backward compatibility with existing paths

This enables users to monitor multiple Claude Code instances in a tmux dashboard by setting different CLAUDE_CONFIG_DIR values.

Tested with multiple Claude Code configurations and confirmed backward compatibility.

Co-authored-by: Steve Antonakakis <[email protected]>
@coderabbitai
Copy link

coderabbitai bot commented Jul 25, 2025

Walkthrough

The get_standard_claude_paths function in src/claude_monitor/cli/main.py was updated to expand its directory search logic. It now considers the CLAUDE_CONFIG_DIR environment variable, checks for a .claude directory in the current working directory, and maintains the original default paths. An import for os was also added.

Changes

File(s) Change Summary
src/claude_monitor/cli/main.py Enhanced get_standard_claude_paths to check CLAUDE_CONFIG_DIR, current .claude dir, and defaults; added os import.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

In burrows deep, I search with glee,
For Claude’s paths, where might they be?
Env vars checked and folders found,
In current holes and all around.
With every hop, I sniff and peer—
The cleverest code is always near!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 06f0fe1 and 7fa4295.

📒 Files selected for processing (1)
  • src/claude_monitor/cli/main.py (3 hunks)
🔇 Additional comments (6)
src/claude_monitor/cli/main.py (6)

11-11: LGTM: Import addition is appropriate.

The os import is correctly placed and necessary for the environment variable functionality.


46-49: Documentation is clear and informative.

The updated docstring accurately describes the new functionality and is appropriately concise.


50-62: CLAUDE_CONFIG_DIR handling logic is sound.

The implementation correctly handles both cases where CLAUDE_CONFIG_DIR points directly to a .claude directory or to a parent directory. The use of expanduser() and safe environment variable access with get() are appropriate.


64-67: Current directory detection works correctly.

The logic properly detects when running from within a .claude directory. Note that the .exists() check is technically redundant since Path.cwd() always returns an existing directory, but it doesn't harm functionality.


69-72: Excellent backward compatibility preservation.

The fallback paths maintain full compatibility with existing functionality while adding support for Claude Code's default location. The path ordering is logical, prioritizing environment-specified and current directory paths.


45-72: Well-implemented enhancement that meets all PR objectives.

The complete rewrite successfully adds CLAUDE_CONFIG_DIR support while maintaining full backward compatibility. The implementation follows a logical priority order (environment variable → current directory → defaults) and integrates seamlessly with the existing codebase. The code is clean, readable, and handles the key use cases described in the PR.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 generate unit tests to generate unit tests for 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.

@santonakakis
Copy link
Author

Additional Context on CLAUDE_CONFIG_DIR

For reference, here are some official Anthropic Claude Code issues that discuss CLAUDE_CONFIG_DIR:

  • Issue #519 - Users reporting usage of CLAUDE_CONFIG_DIR with file not found errors
  • Issue #2277 - Discussion about user config directory behavior
  • Issue #1455 - Claude Code's configuration directory structure

The environment variable is actively used by the Claude Code community for managing multiple installations, though it appears to have some implementation quirks (requiring full paths instead of relative paths).

This PR makes claude-monitor compatible with this Claude Code feature, allowing users to monitor different Claude Code configurations as intended.

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.

1 participant