diff --git a/src/main/services/team/TeamProvisioningService.ts b/src/main/services/team/TeamProvisioningService.ts index 69790de0..ee1f0513 100644 --- a/src/main/services/team/TeamProvisioningService.ts +++ b/src/main/services/team/TeamProvisioningService.ts @@ -6885,9 +6885,12 @@ export class TeamProvisioningService { USER: user, LOGNAME: shellEnv.LOGNAME?.trim() || process.env.LOGNAME?.trim() || user, TERM: shellEnv.TERM?.trim() || process.env.TERM?.trim() || 'xterm-256color', - // Ensure CLI reads/writes from the same Claude root as the app. - // This aligns teams/tasks locations when the app overrides claudeRootPath. - CLAUDE_CONFIG_DIR: getClaudeBasePath(), + // Only set CLAUDE_CONFIG_DIR when the user configured a custom path. + // Setting it to the default ~/.claude changes the macOS Keychain namespace + // for OAuth credential lookup, causing auth failures. (See issue #27) + ...(getClaudeBasePath() !== getAutoDetectedClaudeBasePath() + ? { CLAUDE_CONFIG_DIR: getClaudeBasePath() } + : {}), CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: '1', }; diff --git a/src/main/utils/cliEnv.ts b/src/main/utils/cliEnv.ts index 6ad5ca15..b39d76ed 100644 --- a/src/main/utils/cliEnv.ts +++ b/src/main/utils/cliEnv.ts @@ -9,7 +9,7 @@ */ 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 { userInfo } from 'os'; @@ -29,13 +29,20 @@ export function buildEnrichedEnv(binaryPath?: string | null): NodeJS.ProcessEnv 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 { ...process.env, ...(shellEnv ?? {}), HOME: home, USERPROFILE: home, PATH: buildMergedCliPath(binaryPath), - CLAUDE_CONFIG_DIR: getClaudeBasePath(), + ...(isCustomConfigDir ? { CLAUDE_CONFIG_DIR: configDir } : {}), ...(user ? { USER: user,