fix: use API profile environment variables for task title generation (#1471)

Task title generation was failing when an API profile was active
because it only used Claude OAuth profile environment variables
(CLAUDE_CODE_OAUTH_TOKEN), not the API profile vars
(ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, etc.).

This fixes it by:
1. Adding getAPIProfileEnv() to fetch API profile env vars
2. Adding getOAuthModeClearVars() to clear stale ANTHROPIC_* vars
   when in OAuth mode
3. Including all three env sources in the spawn() call

This matches the pattern used in agent-queue.ts for spawning
agent processes.

Fixes error: "Your account does not have access to Claude Code.
Please run /login." when using API profiles.

Signed-off-by: Joshua Riley <joshua@joshuariley.co.uk>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
JoshuaRileyDev
2026-01-23 17:43:53 +00:00
committed by GitHub
parent 12e788417d
commit c5a0f042da
+14 -3
View File
@@ -11,6 +11,8 @@ import { EventEmitter } from 'events';
import { detectRateLimit, createSDKRateLimitInfo, getProfileEnv } from './rate-limit-detector';
import { parsePythonCommand, getValidatedPythonPath } from './python-detector';
import { getConfiguredPythonPath } from './python-env-manager';
import { getAPIProfileEnv } from './services/profile';
import { getOAuthModeClearVars } from './agent/env-utils';
/**
* Debug logging - only logs when DEBUG=true or in development mode
@@ -142,8 +144,15 @@ export class TitleGenerator extends EventEmitter {
hasOAuthToken: !!autoBuildEnv.CLAUDE_CODE_OAUTH_TOKEN
});
// Get active Claude profile environment (CLAUDE_CONFIG_DIR if not default)
const profileEnv = getProfileEnv();
// Get active API profile environment variables (ANTHROPIC_* vars)
const apiProfileEnv = await getAPIProfileEnv();
const isApiProfileActive = Object.keys(apiProfileEnv).length > 0;
// Only get OAuth profile env if no API profile is active to avoid conflicts
const profileEnv = isApiProfileActive ? {} : getProfileEnv();
// Get OAuth mode clearing vars (clears stale ANTHROPIC_* vars when in OAuth mode)
const oauthModeClearVars = getOAuthModeClearVars(apiProfileEnv);
return new Promise((resolve) => {
// Parse Python command to handle space-separated commands like "py -3"
@@ -153,7 +162,9 @@ export class TitleGenerator extends EventEmitter {
env: {
...process.env,
...autoBuildEnv,
...profileEnv, // Include active Claude profile config
...profileEnv, // Claude OAuth profile (only when no API profile active)
...apiProfileEnv, // API profile (ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL, etc.)
...oauthModeClearVars, // Clear stale ANTHROPIC_* vars when in OAuth mode
PYTHONUNBUFFERED: '1',
PYTHONIOENCODING: 'utf-8',
PYTHONUTF8: '1'