From 77413b33c2791719e13cefade32a96cd9a24dda4 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sun, 1 Nov 2026 21:40:41 +0200 Subject: [PATCH 1/2] Read the login shell's PATH on Linux as well as macOS A desktop-launched app on Linux gets a minimal PATH too, so tools that only the shell's startup files add (nvm, for one) were not found. Sessions now start through the login shell on every Unix, with bash as the fallback when SHELL is unset, and find_executable looks at its PATH. --- README.md | 2 +- src/app/setup.rs | 2 +- src/platform.rs | 88 ++++++++++++++++++++++++++++++++++++------------ 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7a20dc9..f386dbe 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Claudiu never deletes a transcript. It writes to Claude Code's own data only to ## Known gaps - macOS is lightly tested, and the build isn't notarized, so Gatekeeper complains on first launch. -- Linux is new and lightly tested. An app started from the desktop sees only the session's PATH, so tools that only your shell's startup files add (nvm, for one) aren't found. +- Linux is new and lightly tested. - Quitting ends running PTYs. Sessions stay resumable, but live processes don't survive a restart. ## Development diff --git a/src/app/setup.rs b/src/app/setup.rs index 403cd45..75acc06 100644 --- a/src/app/setup.rs +++ b/src/app/setup.rs @@ -111,7 +111,7 @@ impl SetupView { view } - /// Look for both tools off the UI thread, after reading the PATH again: a Finder-launched macOS app starts with a + /// Look for both tools off the UI thread, after reading the PATH again: a desktop-launched app starts with a /// minimal one, and a tool installed since Claudiu started is not on any. fn run_checks(&mut self, cx: &mut Context) { self.checked = None; diff --git a/src/platform.rs b/src/platform.rs index 7dbb04a..ce2ef14 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -27,24 +27,32 @@ pub fn default_shell(custom: Option<&str>) -> (String, Vec) { } } -/// On macOS a GUI-launched app inherits a minimal PATH (no nvm/fnm/Homebrew node), so Claude Code hooks -/// that call `node` fail. Run the program through the user's login shell so it sees their normal environment. -/// Other platforms are returned unchanged. +/// On macOS and Linux a desktop-launched app inherits a minimal PATH (no nvm, fnm or a Homebrew node), so Claude +/// Code hooks that call `node` fail. Run the program through the user's login shell so it sees their normal +/// environment. Windows is returned unchanged. pub fn through_login_shell(program: String, args: Vec) -> (String, Vec) { - #[cfg(target_os = "macos")] + #[cfg(unix)] { - let shell = std::env::var("SHELL").ok().filter(|s| !s.is_empty()).unwrap_or_else(|| "/bin/zsh".into()); + let shell = login_shell(); let script = if shell.ends_with("/fish") { "exec $argv" } else { r#"exec "$@""# }; let mut wrapped = vec!["-l".into(), "-i".into(), "-c".into(), script.into(), "claudiu".into(), program]; wrapped.extend(args); (shell, wrapped) } - #[cfg(not(target_os = "macos"))] + #[cfg(not(unix))] { (program, args) } } +/// `SHELL` when a desktop launch set it, otherwise the platform's usual login shell. +#[cfg(unix)] +fn login_shell() -> String { + std::env::var("SHELL").ok().filter(|s| !s.is_empty()).unwrap_or_else(|| { + if cfg!(target_os = "macos") { "/bin/zsh" } else { "/bin/bash" }.into() + }) +} + /// The fixed-width font for terminals and code. GPUI matches family names exactly and, when one is missing, falls /// back to a proportional UI font, which breaks a terminal's grid; so Linux uses the monospace family fontconfig /// picks for the desktop instead of naming one that may not be installed. @@ -89,7 +97,7 @@ pub fn home_dir() -> Option { /// PATH lookup (honors PATHEXT on Windows). pub fn find_executable(name: &str) -> Option { let found = which::which(name).ok(); - #[cfg(target_os = "macos")] + #[cfg(unix)] let found = found.or_else(|| { let path = LOGIN_PATH.lock().ok()?.clone()?; which::which_in(name, Some(path), std::env::current_dir().ok()?).ok() @@ -97,15 +105,15 @@ pub fn find_executable(name: &str) -> Option { found } -/// The PATH of the user's login shell, as `reload_path` last read it. A Finder-launched app gets a minimal PATH, and +/// The PATH of the user's login shell, as `reload_path` last read it. A desktop-launched app gets a minimal PATH, and /// the environment of a running process is not changed here (`set_var` is unsafe beside other threads on Unix), so /// `find_executable` looks here as well. Sessions already start through the login shell (`through_login_shell`). -#[cfg(target_os = "macos")] +#[cfg(unix)] static LOGIN_PATH: std::sync::Mutex> = std::sync::Mutex::new(None); /// Look for the PATH again, for a tool installed since Claudiu started or one that only the shell's startup files /// put on the PATH. Windows reads the system and user PATH from the registry and uses it for this process and the -/// programs it starts. macOS asks the login shell (blocking, up to a few seconds). Call it off the UI thread. +/// programs it starts. macOS and Linux ask the login shell (blocking, up to a few seconds). Call it off the UI thread. pub fn reload_path() { #[cfg(target_os = "windows")] { @@ -121,7 +129,7 @@ pub fn reload_path() { // SAFETY: on Windows `set_var` is safe to call from any thread (std's documentation says so). unsafe { std::env::set_var("PATH", rebuilt_path(®istry, ¤t)) }; } - #[cfg(target_os = "macos")] + #[cfg(unix)] { if let Some(text) = login_shell_path() { let shell_dirs: Vec = std::env::split_paths(&text).collect(); @@ -134,21 +142,21 @@ pub fn reload_path() { } /// Ask the user's login shell for its PATH. Interactive (`-i`) so `.zshrc` runs too, which is where nvm and friends -/// add theirs. -#[cfg(target_os = "macos")] +/// add theirs. A bash login shell reads `.bashrc` only when its profile sources it, as the usual Linux skeleton +/// does, and that file stops unless the shell is interactive. +#[cfg(unix)] fn login_shell_path() -> Option { - let shell = std::env::var_os("SHELL").filter(|s| !s.is_empty()).unwrap_or_else(|| "/bin/zsh".into()); - path_from_shell(&shell, &print_path_script(), std::time::Duration::from_secs(5)) + path_from_shell(std::ffi::OsStr::new(&login_shell()), &print_path_script(), std::time::Duration::from_secs(5)) } -#[cfg(any(target_os = "macos", test))] +#[cfg(any(unix, test))] const PATH_BEGIN: &str = "< String { format!("printf '%s%s%s' '{PATH_BEGIN}' \"$PATH\" '{PATH_END}'") } @@ -156,7 +164,7 @@ fn print_path_script() -> String { /// Run `script` in `shell` as a login shell and return the PATH it printed. Startup files may print anything, so the /// PATH sits between markers. A shell that has not answered after `wait` is killed and gives `None`, as does any shell /// that fails to run it. -#[cfg(any(target_os = "macos", test))] +#[cfg(any(unix, test))] fn path_from_shell(shell: &OsStr, script: &str, wait: std::time::Duration) -> Option { use std::io::Read; let mut child = Command::new(shell) @@ -181,7 +189,7 @@ fn path_from_shell(shell: &OsStr, script: &str, wait: std::time::Duration) -> Op } /// The text between the markers, ignoring whatever the shell's startup files printed around them. -#[cfg(any(target_os = "macos", test))] +#[cfg(any(unix, test))] fn path_between_markers(output: &str) -> Option<&str> { let after = output.split_once(PATH_BEGIN)?.1; Some(after.split_once(PATH_END)?.0) @@ -189,7 +197,7 @@ fn path_between_markers(output: &str) -> Option<&str> { /// The registry's directories first, then whatever this process had that the registry lacks (for example folders a /// launcher added for Claudiu alone). Each directory appears once. -#[cfg(any(target_os = "windows", target_os = "macos", test))] +#[cfg(any(windows, unix, test))] fn rebuilt_path(registry: &[PathBuf], current: &OsStr) -> std::ffi::OsString { let mut dirs: Vec = Vec::new(); for dir in registry.iter().cloned().chain(std::env::split_paths(current)) { @@ -481,6 +489,44 @@ bye candidates.into_iter().find(|p| p.is_file()) } + #[test] + fn a_desktop_launch_starts_the_program_through_the_login_shell() { + let (program, args) = through_login_shell("/usr/bin/claude".into(), vec!["--resume".into(), "abc".into()]); + if cfg!(windows) { + assert_eq!(program, "/usr/bin/claude"); + assert_eq!(args, ["--resume".to_string(), "abc".into()]); + return; + } + let shell = std::env::var("SHELL").ok().filter(|s| !s.is_empty()).unwrap_or_else(|| { + if cfg!(target_os = "macos") { "/bin/zsh".into() } else { "/bin/bash".into() } + }); + let script = if shell.ends_with("/fish") { "exec $argv" } else { r#"exec "$@""# }; + assert_eq!(program, shell); + assert_eq!(args, vec!["-l".into(), "-i".into(), "-c".into(), script.into(), "claudiu".into(), "/usr/bin/claude".into(), "--resume".into(), "abc".into()]); + } + + /// A tool that is not on this process's PATH, sitting in a directory recorded as the login shell's. + #[test] + #[cfg(unix)] + fn find_executable_uses_a_directory_only_the_login_shell_reported() { + use std::os::unix::fs::PermissionsExt; + let dir = std::env::temp_dir().join(format!("claudiu-login-path-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).unwrap(); + let tool = dir.join("claudiu-login-path-probe"); + std::fs::write(&tool, b"#!/bin/sh\n").unwrap(); + let mut perms = std::fs::metadata(&tool).unwrap().permissions(); + perms.set_mode(0o755); + std::fs::set_permissions(&tool, perms).unwrap(); + + let previous = LOGIN_PATH.lock().unwrap().clone(); + *LOGIN_PATH.lock().unwrap() = Some(dir.as_os_str().to_os_string()); + let found = find_executable("claudiu-login-path-probe"); + *LOGIN_PATH.lock().unwrap() = previous; + let _ = std::fs::remove_dir_all(&dir); + assert_eq!(found, Some(tool)); + } + #[test] fn a_shell_answers_with_its_path_and_a_hung_one_is_given_up_on() { let Some(bash) = posix_shell() else { return }; From bc3d4e499237b0bbfc5c7a7e61694241db892be8 Mon Sep 17 00:00:00 2001 From: Savin Angel-Mario Date: Sun, 1 Nov 2026 22:22:38 +0200 Subject: [PATCH 2/2] Name the expected argument type in the login shell launch test The assertion compared Vec against vec![.. .into()], which rustc cannot infer (E0283), so the test build failed on every platform. Claude-Session: https://claude.ai/code/session_01Du3Uo5uNcjDYQqGRwN1XR9 --- src/platform.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/platform.rs b/src/platform.rs index ce2ef14..a86ff6f 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -502,7 +502,8 @@ bye }); let script = if shell.ends_with("/fish") { "exec $argv" } else { r#"exec "$@""# }; assert_eq!(program, shell); - assert_eq!(args, vec!["-l".into(), "-i".into(), "-c".into(), script.into(), "claudiu".into(), "/usr/bin/claude".into(), "--resume".into(), "abc".into()]); + let expected: Vec = ["-l", "-i", "-c", script, "claudiu", "/usr/bin/claude", "--resume", "abc"].map(String::from).to_vec(); + assert_eq!(args, expected); } /// A tool that is not on this process's PATH, sitting in a directory recorded as the login shell's.