Files
SuperCharged-Claude-Code-Up…/SESSION_ATTACHMENT_FIX.md
uroma 55aafbae9a Fix project isolation: Make loadChatHistory respect active project sessions
- Modified loadChatHistory() to check for active project before fetching all sessions
- When active project exists, use project.sessions instead of fetching from API
- Added detailed console logging to debug session filtering
- This prevents ALL sessions from appearing in every project's sidebar

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-22 14:43:05 +00:00

4.2 KiB

Session Attachment Bug Fix

Date: 2025-01-22 Issue: Folder selection creates session and navigates to URL, but IDE shows "No sessions yet"

Root Cause

The loadChatView() function in chat-functions.js only checked for URL-based session attachment (PRELOAD_SESSION_ID) when there were no active sessions (activeSessions.length === 0).

When a session was created via folder selection:

  1. Session created successfully
  2. Browser navigates to /claude/ide/session/session-XXX
  3. IDE loads and calls loadChatView()
  4. loadChatView() fetches sessions list
  5. Session exists in active list (because it was just created)
  6. Code renders the session list but never checks the URL for session attachment
  7. User sees "No sessions yet" or the session list but isn't attached to the URL-specified session

The Fix

Moved the URL-based session attachment check to execute before checking whether there are active sessions. Now:

  1. URL check happens first
  2. If URL contains a session ID, attach to it immediately
  3. Only render session list if no URL-based session attachment needed

Files Modified

/home/uroma/obsidian-web-interface/public/claude-ide/chat-functions.js

Before: URL check only in else block (when activeSessions.length === 0)

if (activeSessions.length > 0) {
    // Render session list
} else {
    // Check URL for session ID
    let pendingSessionId = window.PRELOAD_SESSION_ID;
    // ...
}

After: URL check happens before session list rendering

// URL-BASED SESSION ATTACHMENT (Always check first!)
let pendingSessionId = window.PRELOAD_SESSION_ID;
if (!pendingSessionId) {
    pendingSessionId = window.pendingSessionAttach;
}
if (!pendingSessionId) {
    const pathname = window.location.pathname;
    const sessionMatch = pathname.match(/\/claude\/ide\/session\/([^\/]+)$/);
    if (sessionMatch && sessionMatch[1]) {
        pendingSessionId = sessionMatch[1];
    }
}
if (!pendingSessionId) {
    const urlParams = new URLSearchParams(window.location.search);
    pendingSessionId = urlParams.get('session');
}

if (pendingSessionId) {
    // Attach to session immediately
    attachToSession(pendingSessionId);
    return;
}

// No URL-based session - render session list normally
if (activeSessions.length > 0) {
    // Render session list
} else {
    // Show "no sessions" message
}

/home/uroma/obsidian-web-interface/public/claude-ide/index.html

Updated cache buster version:

const EXPECTED_JS_VERSION = '1769079537621';  // Cache bust for URL-based session attachment fix

Testing

Steps to verify:

  1. Go to https://rommark.dev/claude/
  2. Click "Start New Session" → "Choose Folder"
  3. Select any folder
  4. Click "Select Folder"
  5. Should navigate to /claude/ide/session/session-XXX
  6. IDE should show "Loading session..." then attach to the session
  7. Chat interface should be ready, not "No sessions yet"

Technical Details

Priority order for session detection:

  1. PRELOAD_SESSION_ID - Set by inline script before any JS loads
  2. window.pendingSessionAttach - Set by ide.js initialization
  3. URL pathname /claude/ide/session/XXX - Direct route matching
  4. Query parameter ?session=XXX - Legacy support

Why this fix works:

  • URL-based navigation is now the PRIMARY way to specify which session to attach to
  • Session list rendering is secondary
  • Even if 100 sessions exist, navigating to /claude/ide/session/specific-id will attach to that specific session
  • No race condition between session creation and list fetching
  • PRELOAD_SESSION_ID extraction in /public/claude-ide/index.html (lines 11-39)
  • attachToSession() function in /public/claude-ide/chat-functions.js
  • Folder selection navigation in /public/claude-ide/components/folder-explorer-modal.js (line 452)

Cache Busting

The fix includes a cache buster update to force browsers to reload the JavaScript:

  • Old version: 1769073600000
  • New version: 1769079537621

Browsers will detect the version mismatch and automatically reload to get the fixed code.