From 3ae594ccda87c29c7a626bbda61d159b6f01c68e Mon Sep 17 00:00:00 2001 From: MorikawaSouma Date: Sat, 14 Mar 2026 14:03:27 +0800 Subject: [PATCH] fix(paths): use OPENCLAW_HOME directly as config dir when explicitly set When OPENCLAW_HOME is set to a path ending with .openclaw (e.g., ~/.openclaw), the previous logic would append another .openclaw, creating a nested directory like ~/.openclaw/.openclaw. This fix checks if OPENCLAW_HOME is explicitly set and uses it directly as the config directory, avoiding the unwanted nesting. Fixes #45765 --- src/utils.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/utils.ts b/src/utils.ts index caf5edb1969..986d71b3607 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -290,6 +290,22 @@ export function resolveConfigDir( if (override) { return resolveUserPath(override, env, homedir); } + + // If OPENCLAW_HOME is explicitly set, use it directly as the config directory. + // This prevents nested .openclaw/.openclaw when OPENCLAW_HOME already points to .openclaw. + const explicitHome = env.OPENCLAW_HOME?.trim(); + if (explicitHome) { + const resolvedHome = resolveRequiredHomeDir(env, homedir); + try { + if (fs.existsSync(resolvedHome)) { + return resolvedHome; + } + } catch { + // best-effort + } + return resolvedHome; + } + const newDir = path.join(resolveRequiredHomeDir(env, homedir), ".openclaw"); try { const hasNew = fs.existsSync(newDir);