fix(auth): avoid setting CLAUDE_CONFIG_DIR when it matches default path

On macOS, the Claude CLI uses a Keychain namespace derived from the
presence of CLAUDE_CONFIG_DIR env var. Setting it to the default
~/.claude creates a different Keychain key than when the var is absent,
causing "not logged in" errors even after successful `claude auth login`.

Only set CLAUDE_CONFIG_DIR when the user has configured a custom path
that differs from the auto-detected default.

Fixes #27
This commit is contained in:
iliya 2026-03-25 12:23:57 +02:00
parent 896c749e76
commit 60d80cde70
2 changed files with 15 additions and 5 deletions

View file

@ -6885,9 +6885,12 @@ export class TeamProvisioningService {
USER: user, USER: user,
LOGNAME: shellEnv.LOGNAME?.trim() || process.env.LOGNAME?.trim() || user, LOGNAME: shellEnv.LOGNAME?.trim() || process.env.LOGNAME?.trim() || user,
TERM: shellEnv.TERM?.trim() || process.env.TERM?.trim() || 'xterm-256color', TERM: shellEnv.TERM?.trim() || process.env.TERM?.trim() || 'xterm-256color',
// Ensure CLI reads/writes from the same Claude root as the app. // Only set CLAUDE_CONFIG_DIR when the user configured a custom path.
// This aligns teams/tasks locations when the app overrides claudeRootPath. // Setting it to the default ~/.claude changes the macOS Keychain namespace
CLAUDE_CONFIG_DIR: getClaudeBasePath(), // for OAuth credential lookup, causing auth failures. (See issue #27)
...(getClaudeBasePath() !== getAutoDetectedClaudeBasePath()
? { CLAUDE_CONFIG_DIR: getClaudeBasePath() }
: {}),
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1', CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1',
}; };

View file

@ -9,7 +9,7 @@
*/ */
import { buildMergedCliPath } from '@main/utils/cliPathMerge'; import { buildMergedCliPath } from '@main/utils/cliPathMerge';
import { getClaudeBasePath } from '@main/utils/pathDecoder'; import { getAutoDetectedClaudeBasePath, getClaudeBasePath } from '@main/utils/pathDecoder';
import { getCachedShellEnv, getShellPreferredHome } from '@main/utils/shellEnv'; import { getCachedShellEnv, getShellPreferredHome } from '@main/utils/shellEnv';
import { userInfo } from 'os'; import { userInfo } from 'os';
@ -29,13 +29,20 @@ export function buildEnrichedEnv(binaryPath?: string | null): NodeJS.ProcessEnv
osUsername || osUsername ||
''; '';
// Only set CLAUDE_CONFIG_DIR when the user has configured a custom path.
// Setting it to the default ~/.claude changes the macOS Keychain namespace
// that the CLI uses for OAuth credential lookup, causing "not logged in"
// even though `claude auth login` succeeded without the env var.
const configDir = getClaudeBasePath();
const isCustomConfigDir = configDir !== getAutoDetectedClaudeBasePath();
return { return {
...process.env, ...process.env,
...(shellEnv ?? {}), ...(shellEnv ?? {}),
HOME: home, HOME: home,
USERPROFILE: home, USERPROFILE: home,
PATH: buildMergedCliPath(binaryPath), PATH: buildMergedCliPath(binaryPath),
CLAUDE_CONFIG_DIR: getClaudeBasePath(), ...(isCustomConfigDir ? { CLAUDE_CONFIG_DIR: configDir } : {}),
...(user ...(user
? { ? {
USER: user, USER: user,