From 78279fb758d79deaffd52f965f849085af600a30 Mon Sep 17 00:00:00 2001 From: Marc Date: Fri, 16 Jan 2026 15:51:50 +0100 Subject: [PATCH] fix: inherit auth-profiles from main agent for subagents When a subagent is spawned, it creates a new agent directory but has no auth-profiles.json. This adds a fallback in ensureAuthProfileStore() to inherit auth-profiles from the main agent when the subagent has none, ensuring subagents can use OAuth tokens without manual file copying. Co-Authored-By: Claude Opus 4.5 --- src/agents/auth-profiles/store.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/agents/auth-profiles/store.ts b/src/agents/auth-profiles/store.ts index 062fbad6c..c94b6872e 100644 --- a/src/agents/auth-profiles/store.ts +++ b/src/agents/auth-profiles/store.ts @@ -207,6 +207,19 @@ export function ensureAuthProfileStore( return asStore; } + // Fallback: inherit auth-profiles from main agent if subagent has none + if (agentDir) { + const mainAuthPath = resolveAuthStorePath(); // without agentDir = main + const mainRaw = loadJsonFile(mainAuthPath); + const mainStore = coerceAuthStore(mainRaw); + if (mainStore && Object.keys(mainStore.profiles).length > 0) { + // Clone main store to subagent directory for auth inheritance + saveJsonFile(authPath, mainStore); + log.info("inherited auth-profiles from main agent", { agentDir }); + return mainStore; + } + } + const legacyRaw = loadJsonFile(resolveLegacyAuthStorePath(agentDir)); const legacy = coerceLegacyStore(legacyRaw); const store: AuthProfileStore = {