Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says "Multi-root or no folder - add the no-project slug", but the code now derives the slug from process.cwd(). Please update the comment to match the current behavior (and/or rename "no-project" wording) to avoid misleading future readers.

Suggested change
// Multi-root or no folder - add the no-project slug
// Multi-root or no workspace folder - derive a slug from the current working directory

Copilot uses AI. Check for mistakes.
slugs.push('-');
slugs.push(this._computeFolderSlug(URI.file(process.cwd())));
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.cwd() can throw (e.g., if the current working directory was deleted), which would make getAllSessions fail unexpectedly. Consider wrapping process.cwd() in a try/catch and falling back to a safe default (e.g., '-' or userHome) so session discovery remains resilient.

Copilot uses AI. Check for mistakes.
}

for (const slug of slugs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -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,
Expand All @@ -585,16 +589,16 @@ 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);

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,
Expand All @@ -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);
Expand Down
Loading