From e92f08472704e371c1884c51f778dce491babaf2 Mon Sep 17 00:00:00 2001 From: hissincn Date: Sat, 25 Apr 2026 13:54:55 +0800 Subject: [PATCH] fix(server): skip home directory in workspace prefix matching When resolving a workspace for a given cwd, the prefix matching loop would match the user's home directory (~) as a prefix for any path under it. This caused new projects created under the home directory to be incorrectly associated with the home workspace instead of getting their own independent workspace. Added a check to skip the home directory (homedir()) during prefix matching. Exact matches for the home directory still work fine. Fixes #BUG Co-Authored-By: Claude Sonnet 4.6 --- packages/server/src/server/session.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/server/src/server/session.ts b/packages/server/src/server/session.ts index aacdc4648..d5c4304df 100644 --- a/packages/server/src/server/session.ts +++ b/packages/server/src/server/session.ts @@ -6010,8 +6010,10 @@ export class Session { return exact.workspaceId; } + const userHome = homedir(); let bestMatch: PersistedWorkspaceRecord | null = null; for (const workspace of workspaces) { + if (workspace.cwd === userHome) continue; const prefix = workspace.cwd.endsWith(sep) ? workspace.cwd : `${workspace.cwd}${sep}`; if (!normalizedCwd.startsWith(prefix)) { continue;