fix: respect CLAUDE_CONFIG_DIR environment variable for Claude Code config path#2740
fix: respect CLAUDE_CONFIG_DIR environment variable for Claude Code config path#2740lihan3238 wants to merge 3 commits into
Conversation
When CLAUDE_CONFIG_DIR is set as an environment variable, cc-switch should read Claude Code configuration from that directory instead of the default ~/.claude path. The priority order is now: 1. cc-switch settings override (claude_config_dir in settings) 2. CLAUDE_CONFIG_DIR environment variable (if absolute path) 3. Default ~/.claude Fixes farion1231#2706
|
Claude finished @farion1231's task in 1m 39s —— View job Claude Code Review
Finding: MCP path (
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d84288102b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if let Ok(env_dir) = std::env::var("CLAUDE_CONFIG_DIR") { | ||
| let p = PathBuf::from(env_dir); | ||
| if p.is_absolute() { | ||
| return p; | ||
| } |
There was a problem hiding this comment.
Align MCP path with CLAUDE_CONFIG_DIR
When CLAUDE_CONFIG_DIR is set (and no claude_config_dir override exists), this new branch makes get_claude_config_dir() return the env directory, but MCP/state file resolution still goes through get_default_claude_mcp_path() (~/.claude.json). That splits one Claude profile across two locations: settings.json/projects under CLAUDE_CONFIG_DIR, while MCP servers and onboarding flags are read/written in home, so users on custom profiles will see missing or stale MCP config.
Useful? React with 👍 / 👎.
When CLAUDE_CONFIG_DIR is set (and no GUI override exists), get_claude_mcp_path() now derives the MCP path from the env var directory instead of falling back to ~/.claude.json. This mirrors the priority ladder in get_claude_config_dir(): GUI override > CLAUDE_CONFIG_DIR > default. Addresses review feedback from Codex and Claude bots.
|
Thanks for the review feedback from both Codex and Claude bots! I've addressed the MCP path asymmetry: Problem: Fix: Updated
This ensures MCP config and settings stay in the same profile when using |
Fixes #2706
Summary
When the
CLAUDE_CONFIG_DIRenvironment variable is set, cc-switch now reads Claude Code configuration from that directory instead of always defaulting to~/.claude.The priority order for determining the Claude Code config directory is now:
claude_config_dirin settings) - highest priorityCLAUDE_CONFIG_DIRenvironment variable (only if the path is absolute)~/.claude- fallbackChanges
get_claude_config_dir()insrc-tauri/src/config.rsto checkstd::env::var("CLAUDE_CONFIG_DIR")before falling back to the default pathTest plan
cargo buildin src-tauri)CLAUDE_CONFIG_DIR=/custom/pathand verify cc-switch reads config from that path~/.claude)