claude-code - 💡(How to fix) Fix [BUG] VS Code: Session vanishes from history after closing tab, despite .jsonl file intact on disk [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45424Fetched 2026-04-09 08:05:46
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
0
Participants
Timeline (top)
labeled ×5

Error Message

Error Messages/Logs

No error messages. The session silently disappears from the history list.

Root Cause

The root cause is that session history in the VS Code extension is powered by agentSessions.model.cache in the workspace's state.vscdb (SQLite), not by scanning .jsonl files on disk. When a tab is closed, the session is removed from or never written to this cache. The extension doesn't rescan the sessions directory to reconcile.

Code Example

No error messages. The session silently disappears from the history list.

Diagnostic evidence:
- Session file exists: .claude-sessions/7c508c44-2615-4ab5-8bf0-85330a9a2bcb.jsonl (5.5 MB, 627 lines)
- ai-title record present: "Align on IC3 log collection scope for May 1st"
- agentSessions.model.cache in state.vscdb: does NOT contain this session ID
- 45 of 105 session files on disk are missing from the cache
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Closing a Claude Code session tab in VS Code causes the session to permanently disappear from the session history list, even though the .jsonl session file remains intact on disk with valid data and a valid ai-title record.

The session history UI is powered by agentSessions.model.cache in VS Code's workspace state.vscdb (SQLite), not by scanning session files on disk. When a tab is closed, the session is either removed from or never written to this cache. Since the extension doesn't rescan the sessions directory to reconcile, the session becomes invisible.

In my workspace: 105 session .jsonl files exist on disk, but only 60 are indexed in agentSessions.model.cache. 45 sessions are invisible to the UI despite having valid data.

Repro steps:

  1. Have a Claude Code conversation in VS Code
  2. Reboot or restart VS Code (tab is restored via editor state recovery, session still visible)
  3. Close the session tab manually
  4. Open session history — the session is gone

The session can still be resumed via claude --resume <session-id>, confirming the data is intact. The issue is purely that the UI index loses track of it.

What Should Happen?

Closing a session tab should persist the session to the history index. Ideally, the extension should also rescan the sessions directory on startup and reconcile with its cache, adding any .jsonl files that are missing from the index.

Error Messages/Logs

No error messages. The session silently disappears from the history list.

Diagnostic evidence:
- Session file exists: .claude-sessions/7c508c44-2615-4ab5-8bf0-85330a9a2bcb.jsonl (5.5 MB, 627 lines)
- ai-title record present: "Align on IC3 log collection scope for May 1st"
- agentSessions.model.cache in state.vscdb: does NOT contain this session ID
- 45 of 105 session files on disk are missing from the cache

Steps to Reproduce

  1. Open a Claude Code session in VS Code and have a full conversation (generates an ai-title)
  2. Close VS Code or reboot the computer
  3. Reopen VS Code — the session tab is restored via VS Code's editor state recovery
  4. Close the session tab manually within VS Code
  5. Open session history — the session is gone from the list

Note: The .jsonl session file remains on disk with valid data. The session can still be resumed via CLI with claude --resume <session-id>.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

2.1.49 (Claude Code)

Platform

Other

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

The root cause is that session history in the VS Code extension is powered by agentSessions.model.cache in the workspace's state.vscdb (SQLite), not by scanning .jsonl files on disk. When a tab is closed, the session is removed from or never written to this cache. The extension doesn't rescan the sessions directory to reconcile.

Suggested fix: The extension should either persist sessions to the cache on tab close, rescan the sessions directory on startup, or use the filesystem as the source of truth for session discovery.

extent analysis

TL;DR

The issue can be fixed by modifying the Claude Code extension to persist sessions to the cache when a tab is closed or rescan the sessions directory on startup.

Guidance

  • The extension should be updated to write the session to agentSessions.model.cache when the tab is closed, ensuring the session remains in the history index.
  • Alternatively, the extension could rescan the sessions directory on startup, reconciling the cache with the filesystem to add any missing sessions.
  • To verify the fix, close a session tab and check if the session remains in the history list; also, restart VS Code and confirm that all sessions are properly indexed.
  • Consider implementing a periodic rescan of the sessions directory to handle cases where the cache becomes outdated.

Example

No specific code example can be provided without knowing the extension's codebase, but the fix would involve modifying the tab close event handler to update agentSessions.model.cache or adding a startup routine to rescan the sessions directory.

Notes

The suggested fix assumes that the extension has the capability to write to agentSessions.model.cache and scan the sessions directory. The exact implementation details may vary depending on the extension's architecture and the VS Code API.

Recommendation

Apply a workaround by modifying the extension to rescan the sessions directory on startup, as this approach is more likely to ensure data consistency and accuracy. This workaround can be implemented until a more permanent fix is available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING