Skip to content

Code tab session history lost on app restart — LocalSessionManager fails to persist sessions across restarts #248

@harderthan

Description

@harderthan

Description

All "Code" tab session history is lost every time the Claude Desktop app is restarted. After closing and reopening the app, the session list appears empty with no way to resume previous conversations.

Environment

  • OS: Ubuntu 22.04 (Linux 6.8.0-100-generic)
  • Claude Desktop: installed via claude-desktop-debian
  • Claude Code SDK version: 2.1.49

Root Cause Analysis

The session metadata files stored in ~/.config/Claude/claude-code-sessions/{accountId}/{orgId}/ are not persisted across app restarts. From ~/.config/Claude/logs/main.log:

[LocalSessionManager] Cannot initialize sessions: accountId=null, orgId=null. Keeping existing sessions.
No persisted sessions found
Org changed from null to d40dde79-..., reinitializing sessions
Failed to read sessions directory: ENOENT: no such file or directory, scandir '.../{accountId}/{orgId}'
[LocalSessionManager] loadSessions failed during account transition, restoring previous sessions

The startup sequence has a race condition:

  1. App starts with accountId=null, orgId=null → "No persisted sessions found"
  2. Authentication completes, orgId loads → triggers session reinitialization
  3. loadSessions tries to scan the {orgId} subdirectory, but it doesn't exist yet (ENOENT)
  4. Falls back to "restoring previous sessions" — but none were loaded in step 1
  5. Result: all previous session metadata is gone

The {orgId} directory is only created during an active session and appears to be removed on app shutdown. So on every restart, the directory doesn't exist at the time loadSessions runs.

Note: The actual conversation data (JSONL files in ~/.claude/projects/) survives, but the Desktop app cannot display them without the corresponding session metadata JSON files.

Steps to Reproduce

  1. Open Claude Desktop, go to the "Code" tab
  2. Create one or more code sessions
  3. Close the app completely
  4. Reopen the app
  5. Observe: all previous code sessions are gone from the sidebar

Expected Behavior

Code tab sessions should persist across app restarts, similar to how the main chat history is preserved.

Workaround

A systemd user service that monitors the session directory and backs up/restores session metadata files on directory recreation. Happy to share if anyone needs it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: highImportant, should be addressed soontriage: investigatedIssue has been triaged and investigated

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions