Bug: VS Code Extension Sessions Not Registered in history.jsonl, Breaking /resume Cross-Environment
Bug: VS Code Extension Sessions Not Registered in history.jsonl, Breaking /resume Cross-Environment
Description
Sessions created by the Claude Code VS Code extension are not registered in ~/.claude/history.jsonl. Since the /resume command uses history.jsonl as its session index, these sessions are invisible to /resume — both in the VS Code integrated terminal and in external terminals.
This means users cannot resume VS Code extension sessions from any environment, and the /resume experience is inconsistent across execution contexts of the same tool.
Environment
- OS: Windows 10/11 (MSYS_NT-10.0-26200)
- Claude Code CLI version: Latest (as of 2025-02-10)
- VS Code Extension:
anthropic.claude-code-2.1.38-win32-x64 - Shell: Git Bash (MSYS2)
Steps to Reproduce
- Open a project folder in VS Code
- Start a conversation using the Claude Code VS Code extension (sidebar panel)
- Have a multi-turn conversation and close it
- Open VS Code integrated terminal in the same project folder
- Run
claude(orcc) and type/resume - Result: "No conversations found to resume"
- Open an external terminal,
cdto the same project folder - Run
claudeand type/resume - Result: Same — the VS Code extension session is not listed
Expected Behavior
All sessions created in any execution environment (CLI, VS Code extension, VS Code terminal) should be visible and resumable via /resume, regardless of which environment is used to resume.
Actual Behavior
- CLI sessions (
claudefrom terminal): Properly registered inhistory.jsonland resumable via/resume✅ - VS Code extension sessions: Session
.jsonlfiles are created in~/.claude/projects/<encoded-cwd>/but NOT registered inhistory.jsonl❌ - VS Code terminal sessions: May also be affected by inherited environment variables (
CLAUDECODE=1,CLAUDE_CODE_ENTRYPOINT=claude-vscode)
Root Cause Analysis
Through investigation of the session storage system, I identified the following:
1. Session Storage Architecture
- Sessions are stored as
.jsonlfiles in~/.claude/projects/<encoded-cwd>/ - Path encoding:
cwd.replace(/[^a-zA-Z0-9]/g, "-") history.jsonlserves as the central index for the/resumecommand
2. The Bug
The VS Code extension creates session .jsonl files in the correct project folder, but never writes an entry to history.jsonl. The /resume command exclusively reads history.jsonl to list available sessions, so VS Code extension sessions are invisible.
3. Evidence
In my project folder, I found:
- 4 session
.jsonlfiles in the project's session directory - Only 1 of these was registered in
history.jsonl(created by CLIclaude) - 3 orphaned sessions created by the VS Code extension — completely invisible to
/resume
Verified by examining the extension source (extension.js):
- The encoding function
Zz(v)correctly computes the project folder path - The
spawnClaudefunction setscwdfrom the workspace folder - But no code path writes to
history.jsonlafter session creation
Impact
- Session continuity broken: Users cannot resume VS Code extension sessions
- Cross-environment workflow broken: Users who switch between VS Code and terminal lose access to prior sessions
- Data exists but is inaccessible: Session files are properly saved but not indexed
Suggested Fix
When the VS Code extension creates or completes a session, it should append an entry to ~/.claude/history.jsonl with the same format used by the CLI:
{
"display": "<first user message or session title>",
"pastedContents": {},
"timestamp": <epoch_ms>,
"project": "<workspace folder path>",
"sessionId": "<session-uuid>"
}
This would make all sessions uniformly discoverable by /resume regardless of the execution environment.
Workaround
A manual sync script can scan session files and register orphaned sessions in history.jsonl:
// Scan ~/.claude/projects/*/*.jsonl and register missing sessions in history.jsonl
const fs = require('fs');
const path = require('path');
const claudeDir = path.join(require('os').homedir(), '.claude');
const histPath = path.join(claudeDir, 'history.jsonl');
const projectsDir = path.join(claudeDir, 'projects');
// Read existing history
const existing = new Set();
if (fs.existsSync(histPath)) {
for (const line of fs.readFileSync(histPath, 'utf-8').trim().split('\n')) {
try { existing.add(JSON.parse(line).sessionId); } catch {}
}
}
// Scan all project session files
for (const proj of fs.readdirSync(projectsDir)) {
const projDir = path.join(projectsDir, proj);
if (!fs.statSync(projDir).isDirectory()) continue;
for (const file of fs.readdirSync(projDir).filter(f => f.endsWith('.jsonl'))) {
const sessionId = file.replace('.jsonl', '');
if (existing.has(sessionId)) continue;
// Extract first user message as display title
const lines = fs.readFileSync(path.join(projDir, file), 'utf-8').trim().split('\n');
let display = 'Untitled';
for (const l of lines) {
try {
const d = JSON.parse(l);
if (d.type === 'human' || d.role === 'user') {
display = (d.message?.content || d.content || '').slice(0, 80);
break;
}
} catch {}
}
const stat = fs.statSync(path.join(projDir, file));
const entry = { display, pastedContents: {}, timestamp: stat.mtimeMs, project: proj, sessionId };
fs.appendFileSync(histPath, JSON.stringify(entry) + '\n');
}
}
Related
This may also affect other IDE integrations (JetBrains, etc.) if they use the same session creation path as the VS Code extension.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗