Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(config): expand a bare tilde in CLAUDE_CONFIG_DIR (#4247)

hiro-nikaitouf88b827c40ac
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rs
index 4dcbadff9..4c7645e7f 100644
--- a/src/commands/config/show.rs
+++ b/src/commands/config/show.rs
@@ -318,7 +318,7 @@ pub(super) fn home_dir() -> Option<PathBuf> {
/// harness (see [`super::harness_listing`]).
///
/// Honors `CLAUDE_CONFIG_DIR`, which Claude Code uses to relocate its config
-/// away from the default `~/.claude`. A leading `~/` in the value is expanded
+/// away from the default `~/.claude`. A leading `~` in the value is expanded
/// against the home directory; the shell normally expands it before the
/// variable is set, so a literal `~` only reaches us when the variable is set
/// in a non-shell context.
@@ -326,7 +326,10 @@ pub(super) fn claude_config_dir() -> Option<PathBuf> {
if let Ok(dir) = std::env::var("CLAUDE_CONFIG_DIR")
&& !dir.is_empty()
{
- if let Some(rest) = dir.strip_prefix("~/") {
+ if dir == "~" {
+ return home_dir();
+ }
+ if let Ok(rest) = Path::new(&dir).strip_prefix("~") {
return home_dir().map(|home| home.join(rest));
}
return Some(PathBuf::from(dir));
diff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rs
index 044f2b59b..ad1294755 100644
--- a/tests/integration_tests/config_show.rs
+++ b/tests/integration_tests/config_show.rs
@@ -6649,19 +6649,24 @@ fn test_plugins_claude_install_statusline_honors_claude_config_dir(
}
#[rstest]
+#[case::tilde_slash("~/custom-claude", "custom-claude/settings.json")]
+#[case::bare_tilde("~", "settings.json")]
fn test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dir(
repo: TestRepo,
temp_home: TempDir,
+ #[case] config_dir: &str,
+ #[case] expected_settings: &str,
) {
- // A literal `~/` in CLAUDE_CONFIG_DIR (which only reaches us when the
+ // A literal tilde in CLAUDE_CONFIG_DIR (which only reaches us when the
// variable is set outside a shell) is expanded against the home directory,
- // not treated as a relative path under the cwd.
+ // not treated as a relative path under the cwd. A bare `~` names the home
+ // directory itself, so it has no `/` for a prefix strip to key on.
let mut cmd = wt_command();
repo.configure_wt_cmd(&mut cmd);
cmd.args(["config", "plugins", "claude", "install-statusline", "--yes"])
.current_dir(repo.root_path());
set_temp_home_env(&mut cmd, temp_home.path());
- cmd.env("CLAUDE_CONFIG_DIR", "~/custom-claude");
+ cmd.env("CLAUDE_CONFIG_DIR", config_dir);
let output = cmd.output().unwrap();
assert!(
@@ -6670,8 +6675,13 @@ fn test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dir(
String::from_utf8_lossy(&output.stderr)
);
- // `~/custom-claude` expanded to <home>/custom-claude.
- let settings_path = temp_home.path().join("custom-claude/settings.json");
+ // The tilde expanded against <home>.
+ let settings_path = temp_home.path().join(expected_settings);
+ assert!(
+ settings_path.exists(),
+ "expected settings.json at {}",
+ settings_path.display()
+ );
let content = fs::read_to_string(&settings_path).unwrap();
let parsed: serde_json::Value = serde_json::from_str(&content).unwrap();
assert_eq!(