@@ -633,11 +633,15 @@ const useStore = create<SessionStore>()(
633633 addSession ( session ) ;
634634 subscribeToChannel ( taskRunId ) ;
635635
636- // Proactively get the local worktree path so the agent has access to both
637- // the main repo and the local worktree when/if we focus a worktree later
638- const localWorktreePath = await trpcVanilla . focus . getLocalWorktreePath
639- . query ( { mainRepoPath : repoPath } )
640- . catch ( ( ) => null ) ;
636+ // For local-mode sessions (not worktree), proactively get the local worktree path
637+ // so the agent has access to both the main repo and the local worktree when/if
638+ // we focus a worktree later. Skip this for worktree sessions (paths inside ~/.twig).
639+ const isWorktreeSession = repoPath . includes ( "/.twig/" ) ;
640+ const localWorktreePath = isWorktreeSession
641+ ? null
642+ : await trpcVanilla . focus . getLocalWorktreePath
643+ . query ( { mainRepoPath : repoPath } )
644+ . catch ( ( ) => null ) ;
641645
642646 const result = await trpcVanilla . agent . reconnect . mutate ( {
643647 taskId,
@@ -649,7 +653,7 @@ const useStore = create<SessionStore>()(
649653 logUrl,
650654 sdkSessionId,
651655 // Add the local worktree as an additional directory so the agent
652- // can access it if the user focuses a worktree later
656+ // can access it if the user focuses a worktree later (local-mode only)
653657 ...( localWorktreePath && {
654658 additionalDirectories : [ localWorktreePath ] ,
655659 } ) ,
@@ -706,11 +710,15 @@ const useStore = create<SessionStore>()(
706710 const persistedMode = getPersistedTaskMode ( taskId ) ;
707711 const effectiveMode = executionMode ?? persistedMode ;
708712
709- // Proactively get the local worktree path so the agent has access to both
710- // the main repo and the local worktree when/if we focus a worktree later
711- const localWorktreePath = await trpcVanilla . focus . getLocalWorktreePath
712- . query ( { mainRepoPath : repoPath } )
713- . catch ( ( ) => null ) ;
713+ // For local-mode sessions (not worktree), proactively get the local worktree path
714+ // so the agent has access to both the main repo and the local worktree when/if
715+ // we focus a worktree later. Skip this for worktree sessions (paths inside ~/.twig).
716+ const isWorktreeSession = repoPath . includes ( "/.twig/" ) ;
717+ const localWorktreePath = isWorktreeSession
718+ ? null
719+ : await trpcVanilla . focus . getLocalWorktreePath
720+ . query ( { mainRepoPath : repoPath } )
721+ . catch ( ( ) => null ) ;
714722
715723 const { defaultModel } = useSettingsStore . getState ( ) ;
716724 const result = await trpcVanilla . agent . start . mutate ( {
@@ -723,7 +731,7 @@ const useStore = create<SessionStore>()(
723731 model : defaultModel ,
724732 executionMode : effectiveMode ,
725733 // Add the local worktree as an additional directory so the agent
726- // can access it if the user focuses a worktree later
734+ // can access it if the user focuses a worktree later (local-mode only)
727735 ...( localWorktreePath && {
728736 additionalDirectories : [ localWorktreePath ] ,
729737 } ) ,
0 commit comments