Skip to content

The agent that grows with you

fix(desktop): keep Home new sessions detached from the last project

xxxigmf3e0cf098b97
diff --git a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
index cf913713f03..727242428ea 100644
--- a/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
+++ b/apps/desktop/src/app/session/hooks/use-session-actions/index.ts
@@ -2,6 +2,7 @@ import { useStore } from '@nanostores/react'
import { type MutableRefObject, useCallback, useEffect, useRef } from 'react'
import type { NavigateFunction } from 'react-router'
+import { NO_PROJECT_ID } from '@/app/chat/sidebar/projects/workspace-groups'
import { graftRefreshedTailOntoBackfill } from '@/app/chat/transcript-backfill'
import { revealTreePane } from '@/components/pane-shell/tree/store'
import { setWorkspaceScope } from '@/components/pane-shell/workspace-scope'
@@ -30,6 +31,7 @@ import {
normalizeProfileKey
} from '@/store/profile'
import {
+ $projectScope,
beginSessionMutation,
endSessionMutation,
resolveNewSessionCwd,
@@ -470,10 +472,13 @@ export function useSessionActions({
// An explicit one-shot workspace target (null → detached, string → that
// folder) wins; otherwise the live cwd, then the project-aware default
// (resolveNewSessionCwd — a project's new session keeps its repo cwd).
+ // Home is an explicit detached scope: do not let a stale live cwd from
+ // the previously selected project leak into this new session (#84220).
const workspaceTarget = $newChatWorkspaceTarget.get()
+ const homeScope = $projectScope.get() === NO_PROJECT_ID
const cwd =
- workspaceTarget === null
+ workspaceTarget === null || (workspaceTarget === undefined && homeScope)
? ''
: typeof workspaceTarget === 'string'
? workspaceTarget.trim()
@@ -612,16 +617,24 @@ export function useSessionActions({
try {
// Fresh tile → the caller's workspace when one was named (the sidebar
- // "+" on a project/worktree lane), else the resolved new-session cwd
- // (project scope → configured default).
+ // "+" on a project/worktree lane), explicit null means Home/detached,
+ // else the resolved new-session cwd (project scope → configured default).
+ // `options?.cwd || resolve…` is wrong for Home: null is falsy and used
+ // to fall through into the last project folder while main chat was
+ // occupied (openTab path for "New session in Home").
const capturedRoute = options?.route === undefined ? $newChatRoute.get() : options.route
const workspaceScope = options?.workspaceScope ?? { workspaceMode: 'sessions' }
+ const cwd =
+ options?.cwd === null
+ ? ''
+ : typeof options?.cwd === 'string'
+ ? options.cwd.trim()
+ : resolveNewSessionCwd()
const params = {
- ...(await desktopSessionCreateParams((options?.cwd || resolveNewSessionCwd()).trim(), capturedRoute)),
+ ...(await desktopSessionCreateParams(cwd, capturedRoute)),
...(workspaceScope.workspaceMode === 'bots' ? { hidden: true } : {})
}
-
const created = capturedRoute
? await requestGatewayForAgent<SessionCreateResponse>(
capturedRoute.connectionId,
diff --git a/apps/desktop/src/app/session/workspace-session-target.ts b/apps/desktop/src/app/session/workspace-session-target.ts
index da5028502a1..d41aad375f5 100644
--- a/apps/desktop/src/app/session/workspace-session-target.ts
+++ b/apps/desktop/src/app/session/workspace-session-target.ts
@@ -3,6 +3,7 @@ import type { MutableRefObject } from 'react'
import { followActiveSessionCwd, resolveNewSessionCwd } from '@/store/projects'
import {
$newChatWorkspaceTargetGeneration,
+ type NewChatWorkspaceTarget,
setCurrentBranch,
setCurrentCwd,
setNewChatWorkspaceTarget
@@ -14,7 +15,7 @@ interface WorkspaceSessionOptions {
onExplicitWorkspace?: (cwd: string) => void
path: null | string
requestGateway: <T>(method: string, params?: Record<string, unknown>) => Promise<T>
- startFreshSessionDraft: (options?: { workspaceTarget: string }) => void
+ startFreshSessionDraft: (options?: { workspaceTarget: NewChatWorkspaceTarget }) => void
}
export function startWorkspaceSession({
@@ -25,13 +26,22 @@ export function startWorkspaceSession({
requestGateway,
startFreshSessionDraft
}: WorkspaceSessionOptions): void {
- // A worktree lane carries its own path; a project trunk can be path-less, so
- // fall back to the active project's root for that existing controller path.
- const explicitTarget = path?.trim()
+ // Home's "+" passes path=null on purpose ("no folder"). That must stay
+ // detached — do NOT fall through to resolveNewSessionCwd(), which can still
+ // return a default/remembered project folder and re-attach the last repo
+ // (digitwo: New session in Home still shows `main`).
+ if (path === null) {
+ startFreshSessionDraft({ workspaceTarget: null })
+
+ return
+ }
+
+ // A worktree lane carries its own path. Empty string (legacy/path-less trunk)
+ // can fall back to the active project's root, but null was handled above.
+ const explicitTarget = path.trim()
const target = explicitTarget || resolveNewSessionCwd()
startFreshSessionDraft(target ? { workspaceTarget: target } : undefined)
-
if (!target) {
return
}