Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(terminal): restore Bash job control after CLI exit (#10145)

Mi Ramoncdca31153276
diff --git a/src-tauri/src/commands/terminal_launch.rs b/src-tauri/src/commands/terminal_launch.rs
index c99d13fba..dfa0ba9d5 100644
--- a/src-tauri/src/commands/terminal_launch.rs
+++ b/src-tauri/src/commands/terminal_launch.rs
@@ -87,7 +87,7 @@ fn build_exec_line(shell: &str, cwd: Option<&Path>) -> String {
/// 构建 provider 命令行:通过用户 shell 的交互模式执行,确保 GUI 启动的终端也加载用户 PATH。
#[cfg_attr(windows, allow(dead_code))]
fn build_provider_command_line(shell: &str, launch_command: &str, cwd: Option<&Path>) -> String {
- let command = cwd
+ let mut command = cwd
.map(|dir| {
format!(
"cd {} && {}",
@@ -97,6 +97,12 @@ fn build_provider_command_line(shell: &str, launch_command: &str, cwd: Option<&P
})
.unwrap_or_else(|| launch_command.to_string());
+ if shell.rsplit('/').next() == Some("bash") {
+ // Bash -ic can exec its last external command. Keep Bash alive to wait
+ // for the CLI and restore the foreground process group before returning to sh.
+ command.push_str("; exit $?");
+ }
+
format!(
"{} {} {}",
shell_single_quote(shell),
@@ -2975,7 +2981,7 @@ mod tests {
);
assert_eq!(
build_provider_command_line("/bin/bash", &claude, Some(Path::new("/tmp/project"))),
- r#"'/bin/bash' -ic 'cd '"'"'/tmp/project'"'"' && claude --settings '"'"'/tmp/claude config.json'"'"''"#
+ r#"'/bin/bash' -ic 'cd '"'"'/tmp/project'"'"' && claude --settings '"'"'/tmp/claude config.json'"'"'; exit $?'"#
);
assert_eq!(
build_provider_command_line(
@@ -3332,7 +3338,7 @@ mod tests {
Some(Path::new("/tmp/env.sh")),
);
assert!(!script.contains("7890"));
- let run = script.find("'/bin/bash' -ic 'claude'").unwrap();
+ let run = script.find("'/bin/bash' -ic 'claude; exit $?'").unwrap();
let unset = script
.find("unset HTTPS_PROXY https_proxy HTTP_PROXY http_proxy\n")
.unwrap();