diff --git a/src/core/context-tracking/FileContextTracker.ts b/src/core/context-tracking/FileContextTracker.ts index 5741b62cfc..dd4c0317da 100644 --- a/src/core/context-tracking/FileContextTracker.ts +++ b/src/core/context-tracking/FileContextTracker.ts @@ -37,7 +37,9 @@ export class FileContextTracker { // Gets the current working directory or returns undefined if it cannot be determined private getCwd(): string | undefined { - const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) + // Ensure we handle empty arrays properly - check length before accessing + const workspaceFolders = vscode.workspace.workspaceFolders + const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined if (!cwd) { console.info("No workspace folder available - cannot determine current working directory") } diff --git a/src/integrations/claude-code/run.ts b/src/integrations/claude-code/run.ts index ac2e856f7a..e6f42331bc 100644 --- a/src/integrations/claude-code/run.ts +++ b/src/integrations/claude-code/run.ts @@ -7,7 +7,9 @@ import { CLAUDE_CODE_DEFAULT_MAX_OUTPUT_TOKENS } from "@roo-code/types" import * as os from "os" import { t } from "../../i18n" -const cwd = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) +// Ensure we handle empty arrays properly - check length before accessing +const workspaceFolders = vscode.workspace.workspaceFolders +const cwd = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : undefined // Claude Code installation URL - can be easily updated if needed const CLAUDE_CODE_INSTALLATION_URL = "https://docs.anthropic.com/en/docs/claude-code/setup" diff --git a/src/services/mcp/McpHub.ts b/src/services/mcp/McpHub.ts index 6ec5b839e8..07264637b2 100644 --- a/src/services/mcp/McpHub.ts +++ b/src/services/mcp/McpHub.ts @@ -86,7 +86,10 @@ const createServerTypeSchema = () => { type: z.enum(["stdio"]).optional(), command: z.string().min(1, "Command cannot be empty"), args: z.array(z.string()).optional(), - cwd: z.string().default(() => vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? process.cwd()), + cwd: z.string().default(() => { + const workspaceFolders = vscode.workspace.workspaceFolders + return workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : process.cwd() + }), env: z.record(z.string()).optional(), // Ensure no SSE fields are present url: z.undefined().optional(), diff --git a/src/utils/path.ts b/src/utils/path.ts index 48e2ce6673..ccd0826212 100644 --- a/src/utils/path.ts +++ b/src/utils/path.ts @@ -107,7 +107,9 @@ export const toRelativePath = (filePath: string, cwd: string) => { } export const getWorkspacePath = (defaultCwdPath = "") => { - const cwdPath = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath).at(0) || defaultCwdPath + // Ensure we handle empty arrays properly - check length before mapping + const workspaceFolders = vscode.workspace.workspaceFolders + const cwdPath = workspaceFolders && workspaceFolders.length > 0 ? workspaceFolders[0].uri.fsPath : defaultCwdPath const currentFileUri = vscode.window.activeTextEditor?.document.uri if (currentFileUri) { const workspaceFolder = vscode.workspace.getWorkspaceFolder(currentFileUri)