diff --git a/src/extension/agents/claude/node/claudeCodeSessionService.ts b/src/extension/agents/claude/node/claudeCodeSessionService.ts index 7b3a18c01f..34ea400df3 100644 --- a/src/extension/agents/claude/node/claudeCodeSessionService.ts +++ b/src/extension/agents/claude/node/claudeCodeSessionService.ts @@ -116,7 +116,7 @@ export class ClaudeCodeSessionService implements IClaudeCodeSessionService { slugs.push(this._computeFolderSlug(folders[0])); } else { // Multi-root or no folder - add the no-project slug - slugs.push('-'); + slugs.push(this._computeFolderSlug(URI.file(process.cwd()))); } for (const slug of slugs) { diff --git a/src/extension/agents/claude/node/test/claudeCodeSessionService.spec.ts b/src/extension/agents/claude/node/test/claudeCodeSessionService.spec.ts index ebe4e2e19a..d7ac43050d 100644 --- a/src/extension/agents/claude/node/test/claudeCodeSessionService.spec.ts +++ b/src/extension/agents/claude/node/test/claudeCodeSessionService.spec.ts @@ -490,6 +490,8 @@ describe('ClaudeCodeSessionService', () => { let noWorkspaceDirUri: URI; let noWorkspaceService: ClaudeCodeSessionService; let noWorkspaceMockFs: MockFileSystemService; + // No-workspace uses process.cwd() to compute the slug (matching SDK behavior) + const cwdSlug = computeFolderSlug(URI.file(process.cwd())); beforeEach(() => { noWorkspaceMockFs = new MockFileSystemService(); @@ -504,12 +506,12 @@ describe('ClaudeCodeSessionService', () => { noWorkspaceMockFs = accessor.get(IFileSystemService) as MockFileSystemService; const instaService = accessor.get(IInstantiationService); const nativeEnvService = accessor.get(INativeEnvService); - // When there's no workspace, sessions are stored in the '-' directory - noWorkspaceDirUri = URI.joinPath(nativeEnvService.userHome, '.claude', 'projects', '-'); + // When there's no workspace, sessions are stored based on process.cwd() + noWorkspaceDirUri = URI.joinPath(nativeEnvService.userHome, '.claude', 'projects', cwdSlug); noWorkspaceService = instaService.createInstance(ClaudeCodeSessionService); }); - it('loads sessions from no-project directory when there are no workspace folders', async () => { + it('loads sessions from process.cwd() directory when there are no workspace folders', async () => { const fileName = 'no-workspace-session.jsonl'; const fileContents = JSON.stringify({ parentUuid: null, @@ -530,7 +532,7 @@ describe('ClaudeCodeSessionService', () => { expect(sessions[0].label).toBe('session without workspace'); }); - it('returns empty array when no-project directory does not exist', async () => { + it('returns empty array when process.cwd() directory does not exist', async () => { // Don't mock any directory - simulate non-existent directory const sessions = await noWorkspaceService.getAllSessions(CancellationToken.None); @@ -543,6 +545,8 @@ describe('ClaudeCodeSessionService', () => { let multiRootDirUri: URI; let multiRootService: ClaudeCodeSessionService; let multiRootMockFs: MockFileSystemService; + // Multi-root workspaces use process.cwd() to compute the slug (matching SDK behavior) + const cwdSlug = computeFolderSlug(URI.file(process.cwd())); beforeEach(() => { multiRootMockFs = new MockFileSystemService(); @@ -559,12 +563,12 @@ describe('ClaudeCodeSessionService', () => { multiRootMockFs = accessor.get(IFileSystemService) as MockFileSystemService; const instaService = accessor.get(IInstantiationService); const nativeEnvService = accessor.get(INativeEnvService); - // Multi-root workspaces use the '-' directory (same as no-workspace) - multiRootDirUri = URI.joinPath(nativeEnvService.userHome, '.claude', 'projects', '-'); + // Multi-root workspaces use process.cwd() slug to match where SDK stores sessions + multiRootDirUri = URI.joinPath(nativeEnvService.userHome, '.claude', 'projects', cwdSlug); multiRootService = instaService.createInstance(ClaudeCodeSessionService); }); - it('loads sessions from no-project directory for multi-root workspaces', async () => { + it('loads sessions from process.cwd() directory for multi-root workspaces', async () => { const fileName = 'multi-root-session.jsonl'; const fileContents = JSON.stringify({ parentUuid: null, @@ -585,7 +589,7 @@ describe('ClaudeCodeSessionService', () => { expect(sessions[0].label).toBe('session in multi-root workspace'); }); - it('returns empty array when no-project directory does not exist for multi-root', async () => { + it('returns empty array when process.cwd() directory does not exist for multi-root', async () => { // Don't mock any directory - simulate non-existent directory const sessions = await multiRootService.getAllSessions(CancellationToken.None); @@ -593,8 +597,8 @@ describe('ClaudeCodeSessionService', () => { expect(sessions).toHaveLength(0); }); - it('uses dash directory not individual folder slugs for multi-root', async () => { - // Mock the '-' directory with a session + it('uses process.cwd() directory not individual folder slugs for multi-root', async () => { + // Mock the process.cwd() directory with a session const fileName = 'shared-session.jsonl'; const fileContents = JSON.stringify({ parentUuid: null, @@ -608,7 +612,7 @@ describe('ClaudeCodeSessionService', () => { multiRootMockFs.mockDirectory(multiRootDirUri, [[fileName, FileType.File]]); multiRootMockFs.mockFile(URI.joinPath(multiRootDirUri, fileName), fileContents, 1000); - // The session should only come from the '-' directory, not individual folder slugs + // The session should only come from the process.cwd() directory, not individual folder slugs const sessions = await multiRootService.getAllSessions(CancellationToken.None); expect(sessions).toHaveLength(1);