Skip to content

fix(config): honor CLAUDE_CONFIG_DIR for Claude Code paths - #3215

Merged
max-sixty merged 3 commits into
max-sixty:mainfrom
tftio:fix-claude-config-dir
Jun 25, 2026
Merged

max-sixty merged 3 commits into
max-sixty:mainfrom
tftio:fix-claude-config-dir

Conversation

@tftio

@tftio tftio commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The bug

Claude Code reads its configuration from the directory named by the CLAUDE_CONFIG_DIR environment variable when it is set, falling back to ~/.claude otherwise. The override relocates the entire config tree, so settings live at $CLAUDE_CONFIG_DIR/settings.json and 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 ~/.claude in every Claude Code path and never consulted CLAUDE_CONFIG_DIR. On a machine that uses the override:

  • wt config show reports the worktrunk plugin and the statusline as not installed even when they are — it reads ~/.claude/plugins/installed_plugins.json and ~/.claude/settings.json, which Claude Code isn't using.
  • wt config plugins claude install-statusline writes to the wrong file: it creates/edits ~/.claude/settings.json, silently materializing a stray directory while never touching the settings.json Claude Code actually loads. The statusline appears to install successfully but never shows up.

The affected call sites were all in src/commands/config/:

Location Symptom
show.rs is_plugin_installed() plugin reported uninstalled
show.rs is_statusline_configured() statusline reported unconfigured
plugins.rs require_settings_path() statusline written to the wrong file

The fix

Add a single claude_config_dir() helper next to the existing home_dir() helper. It returns $CLAUDE_CONFIG_DIR when 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 ~/.claude otherwise. The three call sites above now resolve their paths through it, and the install-statusline help text / directory-creation message no longer hardcode .claude.

The Gemini extension path (~/.gemini/...) is a separate tool and is intentionally untouched.

Tests

  • New integration test test_plugins_claude_install_statusline_honors_claude_config_dir: with CLAUDE_CONFIG_DIR pointed at a custom directory, install-statusline writes there (and not to ~/.claude), and a second run detects the relocated statusline as already configured.
  • set_temp_home_env now also pins CLAUDE_CONFIG_DIR to the temp home's .claude, mirroring the existing OPENCODE_CONFIG_DIR handling. This keeps the Claude Code detection tests hermetic against an ambient CLAUDE_CONFIG_DIR inherited 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 full config_show module (covers every detection/install path), and the full user_hooks module (covers hook env behavior, the only place the set_temp_home_env change could ripple) all pass.

tftio and others added 2 commits June 24, 2026 15:25
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]>
@max-sixty

Copy link
Copy Markdown
Owner

thanks @tftio !

@max-sixty
max-sixty enabled auto-merge (squash) June 25, 2026 02:37
worktrunk-bot
worktrunk-bot previously approved these changes Jun 25, 2026
@worktrunk-bot
worktrunk-bot dismissed their stale review June 25, 2026 02:52

codecov/patch failing on 2 added lines — dismissing until the ~/-expansion branch in claude_config_dir() is covered (see review comment).

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 in claude_config_dir() (return home_dir().map(|home| home.join(rest));). This is the meaningful gap: the new test test_plugins_claude_install_statusline_honors_claude_config_dir points CLAUDE_CONFIG_DIR at an absolute path (temp_home/custom-claude), so the strip_prefix("~/") path the docstring documents at length never executes. A focused test that sets CLAUDE_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 — the bail!("Could not determine Claude Code config directory") in require_settings_path(). This is a defensive path that only fires when both CLAUDE_CONFIG_DIR is unset and home_dir() returns None; it mirrors the pre-existing bail!("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.

@max-sixty
max-sixty merged commit 64d5eff into max-sixty:main Jun 25, 2026
36 of 38 checks passed
@max-sixty

Copy link
Copy Markdown
Owner

@worktrunk-bot if you can push coverage for those then great

worktrunk-bot added a commit that referenced this pull request Jun 25, 2026
…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]>
@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Pushed coverage for the two flagged lines in claude_config_dir() (the ~/ expansion branch and the ~/.claude fallback) as #3222 — both were unreachable from the existing suite since set_temp_home_env pins CLAUDE_CONFIG_DIR to an absolute path. Watching its CI now.

max-sixty pushed a commit that referenced this pull request Jun 25, 2026
…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]>
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.

3 participants