Skip to content

fix(server): use CLAUDE_CONFIG_DIR instead of HOME for Claude instanc…#4017

Open
dmstoykov wants to merge 4 commits into
pingdotgg:mainfrom
dmstoykov:fix/claude-macos-keychain-config-dir
Open

fix(server): use CLAUDE_CONFIG_DIR instead of HOME for Claude instanc…#4017
dmstoykov wants to merge 4 commits into
pingdotgg:mainfrom
dmstoykov:fix/claude-macos-keychain-config-dir

Conversation

@dmstoykov

@dmstoykov dmstoykov commented Jul 15, 2026

Copy link
Copy Markdown

…e isolation

What Changed

Two commits:

  • fix(server)makeClaudeEnvironment (ClaudeHome.ts) now sets CLAUDE_CONFIG_DIR instead of overriding HOME for a configured Claude home path. Test updated.
  • fix(contracts) — relabel the setting (title → "CLAUDE_CONFIG_DIR path", placeholder → ~/.claude) so the UI matches the new behavior. Schema key stays homePath; no migration.
-    HOME: resolvedHomePath,
+    CLAUDE_CONFIG_DIR: resolvedHomePath,

Why

Overriding HOME also relocates macOS's login-keychain lookup ($HOME/Library/Keychains/login.keychain-db), so the spawned CLI can't read its OAuth token and returns Not logged in · Please run /login on every turn — even though the auth probe shows "Authenticated". Any Claude instance with a custom home path fails to authenticate on macOS.

Proof (same shell, only HOME differs):

$ security find-generic-password -s "Claude Code-credentials" >/dev/null; echo $?   # 0  (real HOME)
$ HOME=~/.claude-custom security find-generic-password -s "Claude Code-credentials" >/dev/null; echo $?   # 44 (not found)

CLAUDE_CONFIG_DIR is Claude Code's per-instance config knob — it isolates config while leaving HOME (and the keychain) intact. The auth probe spawns the CLI through this same env, so probe and generation stay consistent.

Context: the HOME override was introduced incidentally in #2277 (multi-provider foundation) and never revisited. The sibling Codex provider already uses this exact pattern (CODEX_HOME, real HOME preserved), predating the Claude code by ~2 months — so this just aligns Claude with the established precedent. It also finally delivers the work/personal separation requested in #1444 / #2111: HOME-isolation collided on one shared keychain entry, whereas CLAUDE_CONFIG_DIR gives each instance its own.

Verified end-to-end on macOS (custom-path instance went from failing every turn to authenticating normally); ClaudeHome unit test passes.

UI Changes

None (settings label text only).

Checklist

  • Small and focused
  • Explained what changed and why
  • No UI/interaction changes needing screenshots or video

Note

Medium Risk
Changes how every spawned Claude CLI inherits environment for custom home paths (auth, config location); behavior fix with broad provider impact but narrow code surface and strong test coverage.

Overview
Custom Claude homePath now isolates config via CLAUDE_CONFIG_DIR instead of overriding HOME. makeClaudeEnvironment sets the resolved path on that variable so spawned Claude Code processes keep the real HOME (and on macOS, the login keychain) while still using a separate config directory.

Provider settings copy is updated to describe CLAUDE_CONFIG_DIR semantics (title, description, placeholder ~/.claude); the stored field remains homePath with no migration. Tests for SDK sessions, status probes, and text generation now assert CLAUDE_CONFIG_DIR in the child env rather than HOME.

Reviewed by Cursor Bugbot for commit 7fbaf5e. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix makeClaudeEnvironment to set CLAUDE_CONFIG_DIR instead of HOME for Claude instances

Sets CLAUDE_CONFIG_DIR to the resolved config path when homePath is configured, leaving HOME unchanged to avoid breaking macOS keychain lookups. Updates all related tests and renames the homePath setting annotation in the contracts schema from 'Claude HOME path' to 'CLAUDE_CONFIG_DIR path'.

Macroscope summarized 7fbaf5e.

…e isolation

Overriding HOME to isolate a Claude provider instance also relocates the
macOS login-keychain lookup ($HOME/Library/Keychains/login.keychain-db),
so the spawned CLI cannot read its stored OAuth credentials and returns
"Not logged in · Please run /login" on every turn -- even though the auth
probe reports "Authenticated". Any Claude provider with a non-empty
"Claude HOME path" therefore fails to authenticate on macOS.

Set CLAUDE_CONFIG_DIR (Claude Code's per-instance config knob) instead of
HOME. It points the CLI at the config dir directly while leaving HOME --
and the keychain -- intact. Verified end-to-end on macOS: an instance
with a custom path went from failing every turn to authenticating and
completing turns normally.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75f49603-3f9b-48a7-a896-d0c1024ed70f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Jul 15, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jul 15, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This change modifies runtime behavior by switching from HOME to CLAUDE_CONFIG_DIR for Claude configuration. An unresolved review comment identifies a potential breaking change: existing custom path configurations may become invalid due to the different path semantics between the two environment variables.

You can customize Macroscope's approvability policy. Learn more.

The Claude provider now isolates instances via CLAUDE_CONFIG_DIR instead of
HOME. Update the setting's title, description, and placeholder to match --
and to mirror the sibling Codex "CODEX_HOME path" field -- so users don't
enter a HOME-style value like `~` and end up pointing at the wrong config
dir. The internal schema key stays `homePath` for backward compatibility.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@macroscopeapp macroscopeapp Bot dismissed their stale review July 16, 2026 07:30

Dismissing prior approval to re-evaluate 1e9b2fa

@github-actions github-actions Bot added size:S 10-29 changed lines (additions + deletions). and removed size:XS 0-9 changed lines (additions + deletions). labels Jul 16, 2026
macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Jul 16, 2026
@juliusmarminge juliusmarminge enabled auto-merge (squash) July 16, 2026 07:35

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2ea4218. Configure here.

Comment thread apps/server/src/provider/Drivers/ClaudeHome.ts
The Claude provider now sets CLAUDE_CONFIG_DIR instead of HOME, so the tests
that verified the spawned CLI's environment must check CLAUDE_CONFIG_DIR:
- ClaudeTextGeneration.test.ts (fake-binary env assertion)
- ProviderRegistry.test.ts (status-probe env)
- ClaudeAdapter.test.ts (SDK session env)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
auto-merge was automatically disabled July 16, 2026 08:09

Head branch was pushed to by a user without write access

@macroscopeapp macroscopeapp Bot dismissed their stale review July 16, 2026 08:09

Dismissing prior approval to re-evaluate 7fbaf5e

@dmstoykov

dmstoykov commented Jul 16, 2026

Copy link
Copy Markdown
Author

@juliusmarminge can you re-approve?

@dmstoykov dmstoykov requested a review from juliusmarminge July 16, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants