Skip to content

Commit 6bf3696

Browse files
committed
fix: fixing claude and cursor login defaulting to the previously opened shell
1 parent d822a96 commit 6bf3696

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

server/index.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,31 @@ function handleShellConnection(ws) {
827827
const initialCommand = data.initialCommand;
828828
const isPlainShell = data.isPlainShell || (!!initialCommand && !hasSession) || provider === 'plain-shell';
829829

830-
ptySessionKey = `${projectPath}_${sessionId || 'default'}`;
830+
// Login commands (Claude/Cursor auth) should never reuse cached sessions
831+
const isLoginCommand = initialCommand && (
832+
initialCommand.includes('setup-token') ||
833+
initialCommand.includes('cursor-agent login') ||
834+
initialCommand.includes('auth login')
835+
);
836+
837+
// Include command hash in session key so different commands get separate sessions
838+
const commandSuffix = isPlainShell && initialCommand
839+
? `_cmd_${Buffer.from(initialCommand).toString('base64').slice(0, 16)}`
840+
: '';
841+
ptySessionKey = `${projectPath}_${sessionId || 'default'}${commandSuffix}`;
842+
843+
// Kill any existing login session before starting fresh
844+
if (isLoginCommand) {
845+
const oldSession = ptySessionsMap.get(ptySessionKey);
846+
if (oldSession) {
847+
console.log('🧹 Cleaning up existing login session:', ptySessionKey);
848+
if (oldSession.timeoutId) clearTimeout(oldSession.timeoutId);
849+
if (oldSession.pty && oldSession.pty.kill) oldSession.pty.kill();
850+
ptySessionsMap.delete(ptySessionKey);
851+
}
852+
}
831853

832-
const existingSession = ptySessionsMap.get(ptySessionKey);
854+
const existingSession = isLoginCommand ? null : ptySessionsMap.get(ptySessionKey);
833855
if (existingSession) {
834856
console.log('♻️ Reconnecting to existing PTY session:', ptySessionKey);
835857
shellProcess = existingSession.pty;

src/components/Onboarding.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ const Onboarding = ({ onComplete }) => {
575575
{/* Login Modal */}
576576
{showLoginModal && (
577577
<LoginModal
578+
key={loginProvider}
578579
isOpen={showLoginModal}
579580
onClose={() => setShowLoginModal(false)}
580581
provider={loginProvider}

src/components/Settings.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2149,6 +2149,7 @@ function Settings({ isOpen, onClose, projects = [], initialTab = 'tools' }) {
21492149

21502150
{/* Login Modal */}
21512151
<LoginModal
2152+
key={loginProvider}
21522153
isOpen={showLoginModal}
21532154
onClose={() => setShowLoginModal(false)}
21542155
provider={loginProvider}

0 commit comments

Comments
 (0)