Repository navigation
fix(config): honor CLAUDE_CONFIG_DIR for Claude Code paths - #3215
Conversation
Claude Code reads its config from CLAUDE_CONFIG_DIR when set, relocating the entire tree (settings.json, plugins/, ...) away from the default ~/.claude. worktrunk hardcoded ~/.claude in every Claude Code path, so on a machine using the override: - `wt config show` reported the plugin and statusline as not installed even when they were - `wt config plugins claude install-statusline` wrote to the wrong ~/.claude/settings.json, silently creating a stray directory and never touching the config Claude Code actually loads Add a `claude_config_dir()` helper that honors CLAUDE_CONFIG_DIR (with leading `~/` expansion) and falls back to ~/.claude, and route the plugin-detection, statusline-detection, and statusline-install paths through it. Pin CLAUDE_CONFIG_DIR in `set_temp_home_env` so the Claude Code tests stay hermetic against an ambient override in the runner's environment, mirroring the existing OPENCODE_CONFIG_DIR handling. Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
|
thanks @tftio ! |
codecov/patch failing on 2 added lines — dismissing until the ~/-expansion branch in claude_config_dir() is covered (see review comment).
worktrunk-bot
left a comment
There was a problem hiding this comment.
codecov/patch is failing — it's marked non-required on GitHub but gates merge here, so I'm dismissing my approval until the gap is closed. It reports two uncovered added lines:
-
src/commands/config/show.rs— the~/expansion branch inclaude_config_dir()(return home_dir().map(|home| home.join(rest));). This is the meaningful gap: the new testtest_plugins_claude_install_statusline_honors_claude_config_dirpointsCLAUDE_CONFIG_DIRat an absolute path (temp_home/custom-claude), so thestrip_prefix("~/")path the docstring documents at length never executes. A focused test that setsCLAUDE_CONFIG_DIR=~/<subdir>and asserts it resolves under the temp home would cover it and lock in the documented behavior. -
src/commands/config/plugins.rs— thebail!("Could not determine Claude Code config directory")inrequire_settings_path(). This is a defensive path that only fires when bothCLAUDE_CONFIG_DIRis unset andhome_dir()returnsNone; it mirrors the pre-existingbail!("Could not determine home directory")it replaced, so it was effectively unreachable in tests before this PR too. Reasonable to leave as-is — the first line is the one worth covering.
Happy to push a small test for the ~/-expansion case if you'd like; just say the word.
Otherwise the change looks correct and well-scoped: routing the three call sites through one claude_config_dir() helper next to home_dir(), the help-text update, and the set_temp_home_env pin (now required for hermeticity since detection reads the variable) all hang together.
Unrelated: affected tests (linux, advisory) failed on test_switch_picker_alt_r_keeps_cursor_sticky — a picker/PTY test untouched by this change that passed in the required test (linux) run and on macOS. That's a flake, not a reason to hold the PR.
|
@worktrunk-bot if you can push coverage for those then great |
…anches #3215 added `claude_config_dir()` but codecov/patch flagged two uncovered lines: the `~/` expansion branch (set outside a shell) and the unset fallback to `~/.claude`. The existing test only exercised an absolute `CLAUDE_CONFIG_DIR`, and `set_temp_home_env` now pins the variable for every test, so neither branch was hit. Add two `install-statusline` integration tests: one sets `CLAUDE_CONFIG_DIR=~/custom-claude` and asserts the statusline lands at `<home>/custom-claude/settings.json` (no literal `~` directory under the cwd); the other unsets the variable and asserts the fallback to `~/.claude/settings.json`. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Pushed coverage for the two flagged lines in |
…anches (#3222) Follow-up to #3215 (merged), where `codecov/patch` flagged two uncovered lines in the new `claude_config_dir()` helper. Per @max-sixty's [request](#3215 (comment)) to push coverage for those. ## The gap `claude_config_dir()` has three paths; #3215's test only exercised one (an absolute `CLAUDE_CONFIG_DIR`). The two misses were the `~/`-expansion branch and the unset fallback to `~/.claude`. Both were structurally unreachable from the existing suite because `set_temp_home_env` now pins `CLAUDE_CONFIG_DIR` to an absolute path for every test. ## The tests Two `install-statusline` integration tests, each overriding the pinned variable after `set_temp_home_env`: - `test_plugins_claude_install_statusline_expands_tilde_in_claude_config_dir` — sets `CLAUDE_CONFIG_DIR=~/custom-claude` and asserts the statusline lands at `<home>/custom-claude/settings.json`, with no literal `~` directory created under the cwd. Covers the `strip_prefix("~/")` expansion branch. - `test_plugins_claude_install_statusline_falls_back_to_dot_claude` — `env_remove`s the variable and asserts the fallback to `~/.claude/settings.json`. Covers the final `home_dir().map(|home| home.join(".claude"))` arm. Both pass locally (`cargo test --test integration test_plugins_claude_install_statusline` — 7 passed), `cargo fmt --check` clean. Co-authored-by: worktrunk-bot <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
The bug
Claude Code reads its configuration from the directory named by the
CLAUDE_CONFIG_DIRenvironment variable when it is set, falling back to~/.claudeotherwise. The override relocates the entire config tree, so settings live at$CLAUDE_CONFIG_DIR/settings.jsonand plugins at$CLAUDE_CONFIG_DIR/plugins/...(not under a nested.claude/). This is the documented mechanism for running multiple accounts side by side, e.g.alias claude-work='CLAUDE_CONFIG_DIR=~/.claude-work claude'.worktrunk hardcoded
~/.claudein every Claude Code path and never consultedCLAUDE_CONFIG_DIR. On a machine that uses the override:wt config showreports the worktrunk plugin and the statusline as not installed even when they are — it reads~/.claude/plugins/installed_plugins.jsonand~/.claude/settings.json, which Claude Code isn't using.wt config plugins claude install-statuslinewrites to the wrong file: it creates/edits~/.claude/settings.json, silently materializing a stray directory while never touching thesettings.jsonClaude Code actually loads. The statusline appears to install successfully but never shows up.The affected call sites were all in
src/commands/config/:show.rsis_plugin_installed()show.rsis_statusline_configured()plugins.rsrequire_settings_path()The fix
Add a single
claude_config_dir()helper next to the existinghome_dir()helper. It returns$CLAUDE_CONFIG_DIRwhen set (expanding a leading~/against the home directory, since a literal~only reaches us when the variable is set outside a shell), and falls back to~/.claudeotherwise. The three call sites above now resolve their paths through it, and theinstall-statuslinehelp text / directory-creation message no longer hardcode.claude.The Gemini extension path (
~/.gemini/...) is a separate tool and is intentionally untouched.Tests
test_plugins_claude_install_statusline_honors_claude_config_dir: withCLAUDE_CONFIG_DIRpointed at a custom directory,install-statuslinewrites there (and not to~/.claude), and a second run detects the relocated statusline as already configured.set_temp_home_envnow also pinsCLAUDE_CONFIG_DIRto the temp home's.claude, mirroring the existingOPENCODE_CONFIG_DIRhandling. This keeps the Claude Code detection tests hermetic against an ambientCLAUDE_CONFIG_DIRinherited from the runner's environment — without it, the suite is non-deterministic on any machine (such as a Claude Code session) that sets the variable.Locally verified:
cargo fmt --check,cargo clippy --all-targets, the fullconfig_showmodule (covers every detection/install path), and the fulluser_hooksmodule (covers hook env behavior, the only place theset_temp_home_envchange could ripple) all pass.