From 602d25075b6c13cf5b318992405f544683088330 Mon Sep 17 00:00:00 2001 From: Jon Atkinson Date: Fri, 28 Feb 2025 02:23:29 +0000 Subject: [PATCH] fix: Respect the user's XDG Document folder settings on Linux. (#1884) This is related to issue #899. Co-authored-by: Dennis Bartlett --- .changeset/mighty-hounds-watch.md | 5 +++++ src/core/webview/ClineProvider.ts | 27 ++++++++++++++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 .changeset/mighty-hounds-watch.md diff --git a/.changeset/mighty-hounds-watch.md b/.changeset/mighty-hounds-watch.md new file mode 100644 index 0000000000..430b03361d --- /dev/null +++ b/.changeset/mighty-hounds-watch.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Change how Cline finds the path to the user's Documents folder by querying xdg-user-dir on Linux systems. diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 9a17ebe617..c239930846 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1141,21 +1141,38 @@ export class ClineProvider implements vscode.WebviewViewProvider { async getDocumentsPath(): Promise { if (process.platform === "win32") { - // If the user is running Win 7/Win Server 2008 r2+, we want to get the correct path to their Documents directory. try { const { stdout: docsPath } = await execa("powershell", [ "-NoProfile", // Ignore user's PowerShell profile(s) "-Command", "[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments)", ]) - return docsPath.trim() + const trimmedPath = docsPath.trim() + if (trimmedPath) { + return trimmedPath + } } catch (err) { console.error("Failed to retrieve Windows Documents path. Falling back to homedir/Documents.") - return path.join(os.homedir(), "Documents") } - } else { - return path.join(os.homedir(), "Documents") // On POSIX (macOS, Linux, etc.), assume ~/Documents by default (existing behavior, but may want to implement similar logic here) + } else if (process.platform === "linux") { + try { + // First check if xdg-user-dir exists + await execa("which", ["xdg-user-dir"]) + + // If it exists, try to get XDG documents path + const { stdout } = await execa("xdg-user-dir", ["DOCUMENTS"]) + const trimmedPath = stdout.trim() + if (trimmedPath) { + return trimmedPath + } + } catch { + // Log error but continue to fallback + console.error("Failed to retrieve XDG Documents path. Falling back to homedir/Documents.") + } } + + // Default fallback for all platforms + return path.join(os.homedir(), "Documents") } async ensureMcpServersDirectoryExists(): Promise {