From 6bf36969910350e4292c3e36ffd77a0c8984cedf Mon Sep 17 00:00:00 2001 From: simosmik Date: Wed, 17 Dec 2025 12:18:40 +0000 Subject: [PATCH] fix: fixing claude and cursor login defaulting to the previously opened shell --- server/index.js | 26 ++++++++++++++++++++++++-- src/components/Onboarding.jsx | 1 + src/components/Settings.jsx | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server/index.js b/server/index.js index a094d9d..e1b23a4 100755 --- a/server/index.js +++ b/server/index.js @@ -827,9 +827,31 @@ function handleShellConnection(ws) { const initialCommand = data.initialCommand; const isPlainShell = data.isPlainShell || (!!initialCommand && !hasSession) || provider === 'plain-shell'; - ptySessionKey = `${projectPath}_${sessionId || 'default'}`; + // Login commands (Claude/Cursor auth) should never reuse cached sessions + const isLoginCommand = initialCommand && ( + initialCommand.includes('setup-token') || + initialCommand.includes('cursor-agent login') || + initialCommand.includes('auth login') + ); - const existingSession = ptySessionsMap.get(ptySessionKey); + // Include command hash in session key so different commands get separate sessions + const commandSuffix = isPlainShell && initialCommand + ? `_cmd_${Buffer.from(initialCommand).toString('base64').slice(0, 16)}` + : ''; + ptySessionKey = `${projectPath}_${sessionId || 'default'}${commandSuffix}`; + + // Kill any existing login session before starting fresh + if (isLoginCommand) { + const oldSession = ptySessionsMap.get(ptySessionKey); + if (oldSession) { + console.log('🧹 Cleaning up existing login session:', ptySessionKey); + if (oldSession.timeoutId) clearTimeout(oldSession.timeoutId); + if (oldSession.pty && oldSession.pty.kill) oldSession.pty.kill(); + ptySessionsMap.delete(ptySessionKey); + } + } + + const existingSession = isLoginCommand ? null : ptySessionsMap.get(ptySessionKey); if (existingSession) { console.log('♻️ Reconnecting to existing PTY session:', ptySessionKey); shellProcess = existingSession.pty; diff --git a/src/components/Onboarding.jsx b/src/components/Onboarding.jsx index 33d61e5..0943bbb 100644 --- a/src/components/Onboarding.jsx +++ b/src/components/Onboarding.jsx @@ -575,6 +575,7 @@ const Onboarding = ({ onComplete }) => { {/* Login Modal */} {showLoginModal && ( setShowLoginModal(false)} provider={loginProvider} diff --git a/src/components/Settings.jsx b/src/components/Settings.jsx index b3760ac..681fc22 100644 --- a/src/components/Settings.jsx +++ b/src/components/Settings.jsx @@ -2149,6 +2149,7 @@ function Settings({ isOpen, onClose, projects = [], initialTab = 'tools' }) { {/* Login Modal */} setShowLoginModal(false)} provider={loginProvider}