Skip to content

Claude session restoration fails after page refresh - sessions not properly preserved #44

@danieldeusing

Description

@danieldeusing

Problem Description

When using Claude in Clode Studio, sessions were not properly preserved across page refreshes or app restarts. Multiple issues were identified:

  1. Session Loss on Refresh: Refreshing the page would cause "Failed to start Claude CLI" errors
  2. Session ID Conflicts: "Session ID already in use" errors when trying to resume sessions
  3. Incomplete Session Restoration: Only the first session state was restored, not the latest conversation
  4. Poor UX: No clear indication of session state or easy way to continue conversations

Root Causes

  1. Claude CLI creates new session IDs when using --resume, but we weren't tracking the new IDs
  2. Session locks weren't properly released during shutdown
  3. No persistence mechanism for session metadata across app restarts
  4. Claude processes were killed immediately on refresh instead of being preserved

Solution Implemented

See PR #43 for the complete implementation.

Key Improvements:

  1. Automatic Session ID Tracking

    • Monitor ~/.claude/projects/ for new session files
    • Automatically detect and update session IDs after resume
    • Ensures conversation continuity across pause/continue cycles
  2. Robust Session Persistence

    • Store session metadata in .claude/sessions/ at project level
    • Preserve Claude processes during page refresh
    • Auto-start preserved sessions after app reload
  3. Improved Process Management

    • Graceful shutdown with SIGINT before SIGTERM/SIGKILL
    • Proper cleanup to avoid session lock conflicts
    • Wait periods to ensure locks are released
  4. Enhanced User Experience

    • Dynamic button labels (Start/Continue, Pause, Delete/Stop & Delete)
    • Auto-fill "Continue" text when resuming sessions
    • Clear visual feedback for session state

Testing

  • Sessions now properly restore with full conversation history
  • No more "Session ID already in use" errors
  • Multiple Claude instances maintain separate sessions
  • Page refresh preserves active sessions

Related Issues

Implementation PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions