Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Add option to launch Studio without opening the default browser (#7016)

Michael Han3860d69ab2e8
diff --git a/README.md b/README.md
index 849958bfbbc..d5b6feb18d2 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,8 @@ unsloth studio -p 8888
```
For LAN or cloud access, add `-H 0.0.0.0` (raw port only; add `--cloudflare` for a public URL). By default, Unsloth is accessible only locally.
+Launching from the terminal never opens a browser: open the printed URL yourself. The desktop shortcut opens your default browser once the server is up; to launch the server without that (e.g. when running Unsloth as a browser PWA / app window), answer "n" at the installer's browser prompt, pass `--no-browser` to the launcher, or set `UNSLOTH_STUDIO_NO_BROWSER=1`.
+
To reach Unsloth over HTTPS, use `unsloth studio --secure`. Unsloth stays bound to localhost and is reached only through a free Cloudflare tunnel, which publishes it at a public `https://*.trycloudflare.com` URL (it fails closed if the tunnel can't start, so the raw port is never exposed). This makes Unsloth reachable from the internet, so anyone with the link and API key can use it and run code: keep your API key private (see Remote access below).
#### Docker
diff --git a/install.ps1 b/install.ps1
index e80b0626df2..6654d531713 100644
--- a/install.ps1
+++ b/install.ps1
@@ -161,6 +161,8 @@ function Install-UnslothStudio {
$SkipTorch = $false
$SkipAutostart = $false
$ShortcutsOnly = $false
+ # Launcher browser auto-open: "" = undecided (prompt, else keep existing, else on).
+ $OpenBrowserPref = ""
$WithLlamaCppDir = ""
$argList = $args
for ($i = 0; $i -lt $argList.Count; $i++) {
@@ -171,6 +173,8 @@ function Install-UnslothStudio {
"--verbose" { $script:UnslothVerbose = $true }
"-v" { $script:UnslothVerbose = $true }
"--shortcuts-only" { $ShortcutsOnly = $true }
+ "--no-browser" { $OpenBrowserPref = '0' }
+ "--browser" { $OpenBrowserPref = '1' }
"--package" {
$i++
if ($i -ge $argList.Count) {
@@ -752,6 +756,20 @@ function Install-UnslothStudio {
"`$portFile = `$null`n`$mutexName = 'Local\UnslothStudioLauncher'`n"
}
+ # Browser auto-open: explicit installer choice wins; else keep the
+ # value baked into the existing launcher so `studio update`
+ # (--shortcuts-only) never resets it.
+ $_openBrowser = $OpenBrowserPref
+ if (-not $_openBrowser -and (Test-Path -LiteralPath $launcherPs1)) {
+ try {
+ $_prevLauncher = [System.IO.File]::ReadAllText($launcherPs1)
+ if ($_prevLauncher -match "(?m)^\`$openBrowserDefault = '([01])'") {
+ $_openBrowser = $Matches[1]
+ }
+ } catch {}
+ }
+ if ($_openBrowser -ne '0') { $_openBrowser = '1' }
+
$launcherContent = @"
$studioHomeExport`$ErrorActionPreference = 'Stop'
`$basePort = 8888
@@ -759,6 +777,30 @@ $studioHomeExport`$ErrorActionPreference = 'Stop'
`$timeoutSec = 60
`$pollIntervalMs = 1000
`$_ExpectedStudioRootId = '$_studioRootId'
+`$openBrowserDefault = '$_openBrowser'
+
+# Browser auto-open: disabled by -NoBrowser/--no-browser, the
+# UNSLOTH_STUDIO_NO_BROWSER env var, or the baked installer preference.
+# When off the server still starts; the URL is printed instead (PWA use).
+`$openBrowser = (`$openBrowserDefault -ne '0')
+if (`$env:UNSLOTH_STUDIO_NO_BROWSER -and
+ (`$env:UNSLOTH_STUDIO_NO_BROWSER -notin @('0', 'false', 'no', 'off'))) {
+ `$openBrowser = `$false
+}
+foreach (`$_launchArg in `$args) {
+ if (`$_launchArg -in @('-NoBrowser', '--no-browser')) { `$openBrowser = `$false }
+ elseif (`$_launchArg -in @('-Browser', '--browser')) { `$openBrowser = `$true }
+}
+
+function Open-StudioUrl {
+ param([Parameter(Mandatory = `$true)][string]`$Url)
+ if (`$openBrowser) {
+ Start-Process `$Url
+ } else {
+ # Hidden-window launches have no console; never fail on the echo.
+ try { Write-Host "Unsloth Studio is running at: `$Url" } catch {}
+ }
+}
function Test-StudioHealth {
param([Parameter(Mandatory = `$true)][int]`$Port)
@@ -855,7 +897,7 @@ function Find-FreeLaunchPort {
# If Unsloth is already healthy on any expected port, just open it and exit.
`$existingPort = Find-HealthyStudioPort
if (`$existingPort) {
- Start-Process "http://localhost:`$existingPort"
+ Open-StudioUrl "http://localhost:`$existingPort"
exit 0
}
@@ -872,7 +914,7 @@ try {
`$deadline = (Get-Date).AddSeconds(`$timeoutSec)
while ((Get-Date) -lt `$deadline) {
`$port = Find-HealthyStudioPort
- if (`$port) { Start-Process "http://localhost:`$port"; exit 0 }
+ if (`$port) { Open-StudioUrl "http://localhost:`$port"; exit 0 }
Start-Sleep -Milliseconds `$pollIntervalMs
}
exit 0
@@ -921,7 +963,7 @@ try {
[System.IO.File]::WriteAllText(`$portFile, "`$launchPort`n")
} catch {}
}
- Start-Process "http://localhost:`$launchPort"
+ Open-StudioUrl "http://localhost:`$launchPort"
`$browserOpened = `$true
break
}
@@ -3692,6 +3734,37 @@ exit 0
return
}
+ # Ask once (interactive installs only) whether the launcher should open
+ # the browser after the server is up. Skipped when --no-browser/--browser
+ # was passed or input is redirected; then an existing choice is kept.
+ # Enter keeps the choice baked into the existing launcher so a reinstall
+ # that accepts the defaults never flips a saved no-browser preference.
+ # UNSLOTH_SKIP_AUTOSTART is documented for automated installs, so it must
+ # suppress this prompt too, matching the $IsInteractive gate on the launch
+ # prompt below. Leaving $OpenBrowserPref empty falls through to the existing
+ # "keep the baked choice, else default on" logic.
+ $_browserPromptOk = (-not $SkipAutostart) -and [Environment]::UserInteractive -and
+ (-not [Console]::IsInputRedirected)
+ if (-not $OpenBrowserPref -and $_browserPromptOk) {
+ $_existingPref = ""
+ $_promptLauncher = if ($StudioDataDir) { Join-Path $StudioDataDir "launch-studio.ps1" } else { $null }
+ if ($_promptLauncher -and (Test-Path -LiteralPath $_promptLauncher)) {
+ try {
+ $_prevText = [System.IO.File]::ReadAllText($_promptLauncher)
+ if ($_prevText -match "(?m)^\`$openBrowserDefault = '([01])'") {
+ $_existingPref = $Matches[1]
+ }
+ } catch {}
+ }
+ $_browserHint = if ($_existingPref -eq '0') { '[y/N]' } else { '[Y/n]' }
+ Write-Host ""
+ $_browserReply = Read-Host " Open Unsloth Studio in your default browser after launch? $_browserHint"
+ $OpenBrowserPref = if ($_browserReply -match '^[Nn]') { '0' }
+ elseif ($_browserReply -match '^[Yy]') { '1' }
+ elseif ($_existingPref) { $_existingPref }
+ else { '1' }
+ }
+
# New-StudioShortcuts gates the .lnk shortcuts on env-mode internally.
New-StudioShortcuts -UnslothExePath $UnslothExe
@@ -3726,11 +3799,92 @@ exit 0
# caller explicitly disabled the post-install prompt.
# In non-interactive environments (CI, Docker) just print instructions.
$IsInteractive = (-not $SkipAutostart) -and [Environment]::UserInteractive -and (-not [Console]::IsInputRedirected)
+ # Select the same bounded free-port range as the generated desktop launcher.
+ # Passing the selected port to both the server and watcher prevents an
+ # existing Studio on 8888 from moving the backend while the watcher stays
+ # behind.
+ function Find-PostInstallStudioPort {
+ param([int]$BasePort = 8888, [int]$MaxPortOffset = 20)
+ $probes = @(
+ @{ Family = [System.Net.Sockets.AddressFamily]::InterNetwork; Host = '127.0.0.1' },
+ @{ Family = [System.Net.Sockets.AddressFamily]::InterNetworkV6; Host = '::1' }
+ )
+ for ($offset = 0; $offset -le $MaxPortOffset; $offset++) {
+ $candidate = $BasePort + $offset
+ $busy = $false
+ foreach ($probe in $probes) {
+ $client = $null
+ try {
+ $client = [System.Net.Sockets.TcpClient]::new($probe.Family)
+ $connect = $client.ConnectAsync($probe.Host, $candidate)
+ if ($connect.Wait(100) -and $client.Connected) {
+ $busy = $true
+ break
+ }
+ } catch {
+ } finally {
+ if ($client) { $client.Dispose() }
+ }
+ }
+ if (-not $busy) { return $candidate }
+ }
+ return $BasePort
+ }
+
+ # Background watcher for the foreground launch below: once the server is
+ # healthy on the selected port, open the browser per the persisted
+ # preference. Guarded by the per-install root id so a different Studio is
+ # never the one opened.
+ $_browserWatch = {
+ param($RootId, $Port)
+ $deadline = (Get-Date).AddSeconds(120)
+ while ((Get-Date) -lt $deadline) {
+ try {
+ $r = Invoke-RestMethod -Uri "http://127.0.0.1:$Port/api/health" -TimeoutSec 1 -Method Get
+ # An empty RootId must never mean "any backend will do"; the
+ # caller does not start the job in that case.
+ if ($r.service -eq 'Unsloth UI Backend' -and
+ $RootId -and $r.studio_root_id -eq $RootId) {
+ Start-Process "http://localhost:$Port"
+ break
+ }
+ } catch {}
+ Start-Sleep -Seconds 1
+ }
+ }
if ($IsInteractive) {
Write-Host ""
$reply = Read-Host " Start Unsloth Studio now? [Y/n]"
if ([string]::IsNullOrWhiteSpace($reply) -or $reply -match '^[Yy]') {
- & $UnslothExe studio -p 8888
+ $_launchPort = Find-PostInstallStudioPort
+ # Open the browser once the server is up, unless opted out. The
+ # server prints its own URL, so no watcher is needed when off.
+ $_browserJob = $null
+ if ($OpenBrowserPref -ne '0') {
+ $_watchRootId = ""
+ $_watchIdFile = Join-Path $StudioHome "share\studio_install_id"
+ if (Test-Path -LiteralPath $_watchIdFile) {
+ try { $_watchRootId = ([System.IO.File]::ReadAllText($_watchIdFile)).Trim() } catch {}
+ }
+ # Fail closed: without our own id we cannot tell our backend from
+ # another Studio on the same port, so open nothing rather than
+ # risk opening a stranger's.
+ if ($_watchRootId) {
+ try {
+ $_browserJob = Start-Job -ScriptBlock $_browserWatch -ArgumentList @($_watchRootId, $_launchPort)
+ } catch {}
+ }
+ }
+ try {
+ & $UnslothExe studio -p $_launchPort
+ } finally {
+ # The server is gone; reap the watcher instead of leaving it to
+ # poll out its 120s deadline and pop a browser after the fact.
+ if ($_browserJob) {
+ Stop-Job -Job $_browserJob -ErrorAction SilentlyContinue
+ Remove-Job -Job $_browserJob -Force -ErrorAction SilentlyContinue
+ }
+ }
} else {
step "launch" "to start later, run:"
substep "unsloth studio -p 8888"
diff --git a/install.sh b/install.sh
index 4af4763a274..f6fad59623e 100755
--- a/install.sh
+++ b/install.sh
@@ -13,6 +13,7 @@
# curl -fsSL https://unsloth.ai/install.sh | UNSLOTH_PYTHON=3.12 sh # pin Python version
# curl -fsSL https://unsloth.ai/install.sh | UNSLOTH_STUDIO_HOME=/abs/path sh
# Equivalent flags: ./install.sh --no-torch --python 3.12 (or pipe them: sh -s -- --no-torch)
+# ./install.sh --no-browser: launcher starts the server without opening the browser.
#
# Install dir priority: UNSLOTH_STUDIO_HOME > STUDIO_HOME (alias) > $HOME/.unsloth/studio
#
@@ -64,6 +65,8 @@ _NO_TORCH_FLAG=false
_SKIP_AUTOSTART=false
_VERBOSE=false
_SHORTCUTS_ONLY=false
+# Launcher browser auto-open: "" = undecided (prompt, else keep existing, else on).
+_STUDIO_OPEN_BROWSER=""
_next_is_package=false
_next_is_python=false
_next_is_llama_cpp_dir=false
@@ -95,6 +98,8 @@ for arg in "$@"; do
--no-torch) _NO_TORCH_FLAG=true ;;
--verbose|-v) _VERBOSE=true ;;
--shortcuts-only) _SHORTCUTS_ONLY=true ;;
+ --no-browser) _STUDIO_OPEN_BROWSER=0 ;;
+ --browser) _STUDIO_OPEN_BROWSER=1 ;;
--with-llama-cpp-dir) _next_is_llama_cpp_dir=true ;;
esac
done
@@ -1015,6 +1020,22 @@ if [ -z "${UNSLOTH_EXE:-}" ] || [ ! -x "${UNSLOTH_EXE:-}" ]; then
exit 1
fi
+# Browser auto-open. Priority: --no-browser/--browser arg, then
+# UNSLOTH_STUDIO_NO_BROWSER env var, then studio.conf, default on.
+# When off the server still starts; the URL is printed instead (PWA use).
+OPEN_BROWSER="${STUDIO_OPEN_BROWSER:-1}"
+# Case-insensitive falsy check, matching the PowerShell launcher's -notin.
+case "$(printf '%s' "${UNSLOTH_STUDIO_NO_BROWSER:-}" | tr '[:upper:]' '[:lower:]')" in
+ ''|0|false|no|off) ;;
+ *) OPEN_BROWSER=0 ;;
+esac
+for _arg in "$@"; do
+ case "$_arg" in
+ --no-browser) OPEN_BROWSER=0 ;;
+ --browser) OPEN_BROWSER=1 ;;
+ esac
+done
+
BASE_PORT=8888
MAX_PORT_OFFSET=20
TIMEOUT_SEC=60
@@ -1148,6 +1169,10 @@ _find_launch_port() {
# ── Open browser ──
_open_browser() {
_url="$1"
+ if [ "$OPEN_BROWSER" = "0" ]; then
+ echo "Unsloth Studio is running at: $_url"
+ return 0
+ fi
if [ "$(uname)" = "Darwin" ] && command -v open >/dev/null 2>&1; then
open "$_url"
elif grep -qi microsoft /proc/version 2>/dev/null; then
@@ -1379,11 +1404,21 @@ LAUNCHER_EOF
chmod +x "$_css_launcher"
+ # Browser auto-open: explicit installer choice wins; else keep the existing
+ # studio.conf value so `studio update` (--shortcuts-only) never resets it.
+ _css_open_browser="${_STUDIO_OPEN_BROWSER:-}"
+ if [ -z "$_css_open_browser" ] && [ -f "$_css_data_dir/studio.conf" ]; then
+ _css_open_browser=$(sed -n "s/^STUDIO_OPEN_BROWSER='\([01]\)'\$/\1/p" \
+ "$_css_data_dir/studio.conf" 2>/dev/null | head -n 1)
+ fi
+ [ "$_css_open_browser" = "0" ] || _css_open_browser=1
+
# studio.conf: exe path + (env-mode only) persisted env vars so fresh
# shells launch the right install without re-exporting.
_css_quoted_exe=$(printf '%s' "$_css_exe" | sed "s/'/'\\\\''/g")
{
printf '%s\n' "UNSLOTH_EXE='$_css_quoted_exe'"
+ printf '%s\n' "STUDIO_OPEN_BROWSER='$_css_open_browser'"
if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then
# When an override resolves to the legacy default, llama.cpp
# still lives at ~/.unsloth/llama.cpp (one shared build).
@@ -1810,6 +1845,10 @@ if [ "$_SHORTCUTS_ONLY" = true ]; then
fi
create_studio_shortcuts "$VENV_ABS_BIN/unsloth" "$OS"
fi
+ # Drain piped stdin (curl | sh -s -- --shortcuts-only ...) before this
+ # early exit; otherwise curl dies with EPIPE, prints "curl: (23) Failure
+ # writing output to destination", and fails the whole pipeline.
+ [ ! -t 0 ] && cat > /dev/null 2>&1
exit 0
fi
@@ -2053,6 +2092,10 @@ _maybe_reroute_strixhalo_to_2404() {
[ -n "$_USER_PYTHON" ] && _rr_args="$_rr_args --python $(_rr_q "$_USER_PYTHON")"
[ "$_VERBOSE" = true ] && _rr_args="$_rr_args --verbose"
[ "$TAURI_MODE" = true ] && _rr_args="$_rr_args --tauri"
+ # Forward an explicit browser choice; "" (undecided) forwards nothing so
+ # the rerouted install keeps its own default.
+ [ "$_STUDIO_OPEN_BROWSER" = "0" ] && _rr_args="$_rr_args --no-browser"
+ [ "$_STUDIO_OPEN_BROWSER" = "1" ] && _rr_args="$_rr_args --browser"
if [ -n "${UNSLOTH_WSL_REROUTE_CMD:-}" ]; then
_rr_cmd="$UNSLOTH_WSL_REROUTE_CMD" # user took full control
elif [ -n "$_rr_args" ]; then
@@ -4644,6 +4687,39 @@ esac
# create_studio_shortcuts gates persistent menu shortcuts on env-mode;
# launcher + studio.conf + icon are always written.
if [ "$TAURI_MODE" != true ]; then
+ # Ask once (interactive installs only) whether the launcher should open
+ # the browser after the server is up. Skipped when --no-browser/--browser
+ # was passed or no TTY; then an existing choice is kept, defaulting to on.
+ # Enter keeps the choice persisted in studio.conf so a reinstall that
+ # accepts the defaults never flips a saved no-browser preference.
+ # UNSLOTH_SKIP_AUTOSTART is documented for automated installs, so it must
+ # suppress this prompt too, exactly as it suppresses the launch prompt
+ # below. Leaving _STUDIO_OPEN_BROWSER empty falls through to the existing
+ # "keep the saved choice, else default on" logic.
+ # _can_read_tty, not `test -r`: the latter only checks permission bits, which
+ # look fine in containers and systemd units where the open() then fails, and
+ # every other prompt was moved off it in #7435 / #7470.
+ if [ "$_SKIP_AUTOSTART" != true ] && [ -z "$_STUDIO_OPEN_BROWSER" ] \
+ && [ -t 1 ] && _can_read_tty; then
+ _existing_open_browser=""
+ if [ -f "$DATA_DIR/studio.conf" ]; then
+ _existing_open_browser=$(sed -n "s/^STUDIO_OPEN_BROWSER='\([01]\)'\$/\1/p" \
+ "$DATA_DIR/studio.conf" 2>/dev/null | head -n 1)
+ fi
+ if [ "$_existing_open_browser" = "0" ]; then
+ _browser_hint="[y/N]"
+ else
+ _browser_hint="[Y/n]"
+ fi
+ echo ""
+ printf " Open Unsloth Studio in your default browser after launch? %s " "$_browser_hint"
+ read -r _browser_reply </dev/tty || _browser_reply=""
+ case "$_browser_reply" in
+ [nN]*) _STUDIO_OPEN_BROWSER=0 ;;
+ [yY]*) _STUDIO_OPEN_BROWSER=1 ;;
+ *) _STUDIO_OPEN_BROWSER="${_existing_open_browser:-1}" ;;
+ esac
+ fi
create_studio_shortcuts "$VENV_ABS_BIN/unsloth" "$OS"
fi
@@ -4705,6 +4781,103 @@ printf " ${C_TITLE}%s${C_RST}\n" "Unsloth Studio installed!"
printf " ${C_DIM}%s${C_RST}\n" "$RULE"
echo ""
+# Select the same bounded free-port range as the generated desktop launcher.
+# Passing the selected port to both the server and watcher prevents an existing
+# Studio on 8888 from making the backend move while the watcher stays behind.
+_find_post_install_port() {
+ _pifp_base="${1:-8888}"
+ _pifp_max_offset="${2:-20}"
+ "$VENV_DIR/bin/python" - "$_pifp_base" "$_pifp_max_offset" <<'PY'
+import socket
+import sys
+
+base = int(sys.argv[1])
+max_offset = int(sys.argv[2])
+
+def is_free(port):
+ endpoints = (
+ (socket.AF_INET, ("127.0.0.1", port)),
+ (socket.AF_INET6, ("::1", port, 0, 0)),
+ )
+ for family, address in endpoints:
+ try:
+ with socket.socket(family, socket.SOCK_STREAM) as probe:
+ probe.settimeout(0.1)
+ if probe.connect_ex(address) == 0:
+ return False
+ except OSError:
+ # IPv6 can be unavailable; match the backend's loopback probe.
+ continue
+ return True
+
+for offset in range(max_offset + 1):
+ candidate = base + offset
+ if is_free(candidate):
+ print(candidate)
+ raise SystemExit(0)
+raise SystemExit(1)
+PY
+}
+
+# Background watcher for the post-install foreground launch below: once the
+# server is healthy on the selected port, open the browser per the persisted
+# preference. Guarded by the per-install root id so a different Studio is never
+# the one opened.
+_post_install_browser_watch() {
+ _pibw_port="$1"
+ _pibw_url="http://localhost:$_pibw_port"
+ _pibw_id=$(cat "$STUDIO_HOME/share/studio_install_id" 2>/dev/null || true)
+ # Fail closed: without our own id we cannot tell our backend from someone
+ # else's on the same port, and opening a stranger's Studio is worse than
+ # opening nothing. The server prints its own URL either way.
+ if [ -z "$_pibw_id" ]; then
+ return 0
+ fi
+ (
+ _pibw_deadline=$(($(date +%s) + 120))
+ while [ "$(date +%s)" -lt "$_pibw_deadline" ]; do
+ _pibw_resp=$(curl -fsS --max-time 1 "http://127.0.0.1:$_pibw_port/api/health" 2>/dev/null \
+ || wget -qO- --timeout=1 "http://127.0.0.1:$_pibw_port/api/health" 2>/dev/null \
+ || true)
+ case "$_pibw_resp" in
+ *'"Unsloth UI Backend"'*)
+ case "$_pibw_resp" in
+ *"\"studio_root_id\":\"$_pibw_id\""*|*"\"studio_root_id\": \"$_pibw_id\""*) ;;
+ *) sleep 1; continue ;;
+ esac
+ if [ "$(uname)" = "Darwin" ] && command -v open >/dev/null 2>&1; then
+ open "$_pibw_url" 2>/dev/null
+ elif grep -qi microsoft /proc/version 2>/dev/null; then
+ if command -v powershell.exe >/dev/null 2>&1; then
+ powershell.exe -NoProfile -Command "Start-Process '$_pibw_url'" >/dev/null 2>&1
+ elif command -v cmd.exe >/dev/null 2>&1; then
+ cmd.exe /c start "" "$_pibw_url" >/dev/null 2>&1
+ elif command -v xdg-open >/dev/null 2>&1; then
+ xdg-open "$_pibw_url" >/dev/null 2>&1
+ fi
+ elif command -v xdg-open >/dev/null 2>&1; then
+ xdg-open "$_pibw_url" >/dev/null 2>&1
+ fi
+ exit 0
+ ;;
+ esac
+ sleep 1
+ done
+ ) &
+ # Remember the watcher so it can be reaped when the foreground server exits;
+ # otherwise a Ctrl-C leaves it polling for the rest of its 120s deadline and
+ # it can pop a browser long after the installer has visibly finished.
+ _PIBW_PID=$!
+}
+
+# Stop a watcher started above. Safe to call when none is running.
+_stop_post_install_browser_watch() {
+ [ -n "${_PIBW_PID:-}" ] || return 0
+ kill "$_PIBW_PID" 2>/dev/null || true
+ wait "$_PIBW_PID" 2>/dev/null || true
+ _PIBW_PID=""
+}
+
# In interactive terminals, ask the user before starting Unsloth unless the
# caller explicitly disabled the post-install prompt.
# In non-interactive environments (Docker, CI, cloud-init) just print instructions.
@@ -4722,6 +4895,15 @@ if [ "$_SKIP_AUTOSTART" != true ] && [ -t 1 ]; then
case "${_reply:-y}" in
[Yy]*|"")
step "launch" "starting Unsloth Studio..."
+ _post_install_port=$(_find_post_install_port 8888 20) || _post_install_port=8888
+ case "$_post_install_port" in
+ ''|*[!0-9]*) _post_install_port=8888 ;;
+ esac
+ # Open the browser once the server is up, unless opted out. The
+ # server prints its own URL, so no watcher is needed when off.
+ if [ "${_STUDIO_OPEN_BROWSER:-1}" != "0" ]; then
+ _post_install_browser_watch "$_post_install_port"
+ fi
# Detach stdin from the `curl | sh` pipe: as a foreground server the
# studio would otherwise drain the rest of this piped script, leaving
# the shell to die parsing the now-truncated tail (`unexpected fi`).
@@ -4730,7 +4912,9 @@ if [ "$_SKIP_AUTOSTART" != true ] && [ -t 1 ]; then
trap '' INT
# `|| ...`: capture the exit code without set -e aborting first.
_LAUNCH_EXIT=0
- (trap - INT; exec "$VENV_DIR/bin/unsloth" studio -p 8888 </dev/null) || _LAUNCH_EXIT=$?
+ (trap - INT; exec "$VENV_DIR/bin/unsloth" studio -p "$_post_install_port" </dev/null) || _LAUNCH_EXIT=$?
+ # The server is gone; the watcher has nothing left to wait for.
+ _stop_post_install_browser_watch
if [ "$_LAUNCH_EXIT" -ne 0 ] && [ "$_MIGRATED" = true ]; then
echo ""
echo "⚠️ Unsloth Studio failed to start after migration."
diff --git a/tests/sh/test_launcher_no_browser.sh b/tests/sh/test_launcher_no_browser.sh
new file mode 100755
index 00000000000..f1696481fb2
--- /dev/null
+++ b/tests/sh/test_launcher_no_browser.sh
@@ -0,0 +1,291 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# The generated desktop launchers must support suppressing the automatic
+# default-browser open after the server becomes healthy (PWA users run Studio
+# in a browser-app window, not the OS default browser). Covered surface:
+# - launch-studio.sh: --no-browser flag, UNSLOTH_STUDIO_NO_BROWSER env var,
+# persisted STUDIO_OPEN_BROWSER from studio.conf; prints the URL when off.
+# - install.sh: --no-browser flag, interactive prompt, studio.conf persistence
+# that survives the --shortcuts-only refresh run by `unsloth studio update`.
+# - install.ps1: same feature baked into launch-studio.ps1 (Open-StudioUrl).
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+INSTALL_SH="$SCRIPT_DIR/../../install.sh"
+INSTALL_PS1="$SCRIPT_DIR/../../install.ps1"
+PASS=0
+FAIL=0
+
+# Here-strings, not `echo | grep -q`: grep exiting on first match SIGPIPEs
+# the echo on large haystacks, spamming "write error: Broken pipe" in CI logs.
+assert_contains() {
+ _label="$1"; _haystack="$2"; _needle="$3"
+ if grep -qF -- "$_needle" <<< "$_haystack"; then
+ echo " PASS: $_label"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: $_label (expected to find '$_needle')"
+ FAIL=$((FAIL + 1))
+ fi
+}
+
+assert_not_contains() {
+ _label="$1"; _haystack="$2"; _needle="$3"
+ if grep -qF -- "$_needle" <<< "$_haystack"; then
+ echo " FAIL: $_label (found '$_needle' but should not)"
+ FAIL=$((FAIL + 1))
+ else
+ echo " PASS: $_label"
+ PASS=$((PASS + 1))
+ fi
+}
+
+echo ""
+echo "=== install.sh launcher template ==="
+
+# Extract the heredoc that generates ~/.local/share/unsloth/launch-studio.sh.
+_launcher=$(awk '/cat > "\$_css_launcher"/{found=1} found{print} /^LAUNCHER_EOF$/{found=0}' "$INSTALL_SH")
+assert_contains \
+ "launcher template: --no-browser argument handled" \
+ "$_launcher" "--no-browser) OPEN_BROWSER=0"
+assert_contains \
+ "launcher template: UNSLOTH_STUDIO_NO_BROWSER env var handled" \
+ "$_launcher" "UNSLOTH_STUDIO_NO_BROWSER"
+# Mixed-case falsy values (False, Off) must not disable, matching the
+# PowerShell launcher's case-insensitive -notin.
+assert_contains \
+ "launcher template: env var check is case-insensitive" \
+ "$_launcher" "tr '[:upper:]' '[:lower:]'"
+assert_contains \
+ "launcher template: studio.conf preference is the default" \
+ "$_launcher" 'OPEN_BROWSER="${STUDIO_OPEN_BROWSER:-1}"'
+assert_contains \
+ "launcher template: _open_browser is gated on OPEN_BROWSER" \
+ "$_launcher" '[ "$OPEN_BROWSER" = "0" ]'
+assert_contains \
+ "launcher template: URL still printed when auto-open is off" \
+ "$_launcher" "Unsloth Studio is running at:"
+
+echo ""
+echo "=== install.sh installer plumbing ==="
+
+_installer=$(cat "$INSTALL_SH")
+assert_contains \
+ "install.sh: --no-browser flag parsed" \
+ "$_installer" "--no-browser) _STUDIO_OPEN_BROWSER=0"
+assert_contains \
+ "install.sh: preference persisted into studio.conf" \
+ "$_installer" "STUDIO_OPEN_BROWSER='\$_css_open_browser'"
+assert_contains \
+ "install.sh: existing studio.conf choice preserved on refresh" \
+ "$_installer" "s/^STUDIO_OPEN_BROWSER="
+assert_contains \
+ "install.sh: interactive prompt asks about browser auto-open" \
+ "$_installer" "Open Unsloth Studio in your default browser after launch?"
+# A reinstall that accepts the prompt default must keep the saved choice.
+assert_contains \
+ "install.sh: prompt Enter keeps the persisted preference" \
+ "$_installer" '*) _STUDIO_OPEN_BROWSER="${_existing_open_browser:-1}"'
+# UNSLOTH_SKIP_AUTOSTART is documented for automated installs, so it must gate
+# this prompt too: under `curl ... | sh` only stdin is the pipe, [ -t 1 ] is
+# still true, so an ungated prompt blocks an install that used to run unattended.
+assert_contains \
+ "install.sh: browser prompt respects UNSLOTH_SKIP_AUTOSTART" \
+ "$_installer" 'if [ "$_SKIP_AUTOSTART" != true ] && [ -z "$_STUDIO_OPEN_BROWSER" ]'
+# The WSL Strix Halo reroute must forward an explicit browser choice.
+assert_contains \
+ "install.sh: reroute forwards --no-browser" \
+ "$_installer" '[ "$_STUDIO_OPEN_BROWSER" = "0" ] && _rr_args="$_rr_args --no-browser"'
+# The post-install foreground launch honors the preference too.
+assert_contains \
+ "install.sh: post-install launch opens browser via gated watcher" \
+ "$_installer" '_post_install_browser_watch "$_post_install_port"'
+assert_contains \
+ "install.sh: post-install launch selects a free port" \
+ "$_installer" "_find_post_install_port()"
+assert_contains \
+ "install.sh: server uses the watcher-selected port" \
+ "$_installer" 'studio -p "$_post_install_port"'
+# The --shortcuts-only early exit must not EPIPE a curl | sh pipeline.
+assert_contains \
+ "install.sh: shortcuts-only exit drains piped stdin" \
+ "$_installer" '[ ! -t 0 ] && cat > /dev/null'
+
+echo ""
+echo "=== install.sh _open_browser gating (functional) ==="
+
+# Extract the _open_browser function from the (column-0) launcher heredoc and
+# drive it with stubbed browser openers on PATH.
+_fn=$(printf '%s\n' "$_launcher" | awk '/^_open_browser\(\) \{/{found=1} found{print} found && /^\}/{exit}')
+if [ -z "$_fn" ]; then
+ echo " FAIL: could not extract _open_browser from launcher template"
+ FAIL=$((FAIL + 1))
+else
+ _tmp=$(mktemp -d)
+ trap 'rm -rf "$_tmp"' EXIT
+ # Stub EVERY opener _open_browser can reach, not just open/xdg-open: on WSL
+ # it prefers powershell.exe then cmd.exe, so on a WSL dev box an unstubbed
+ # run escapes to the real Windows browser and opens a window for real.
+ for _stub in open xdg-open powershell.exe cmd.exe; do
+ printf '#!/bin/sh\necho "BROWSER_OPENED:$*" >> "$RECORD"\n' > "$_tmp/$_stub"
+ chmod +x "$_tmp/$_stub"
+ done
+ # Pin PATH to the stubs plus coreutils so no host opener can leak in, and
+ # force the OS branch rather than inheriting the runner's.
+ _stub_path="$_tmp:/usr/bin:/bin"
+ printf '#!/bin/sh\necho Linux\n' > "$_tmp/uname"
+ chmod +x "$_tmp/uname"
+ # Fixture /proc/version: "microsoft" selects the WSL branch, anything else
+ # the plain-Linux branch. Lets one Linux runner cover both.
+ printf 'Linux version 5.15.0-microsoft-standard-WSL2\n' > "$_tmp/procversion_wsl"
+ printf 'Linux version 6.1.0-generic\n' > "$_tmp/procversion_linux"
+ _fn_linux=$(printf '%s\n' "$_fn" | sed "s#/proc/version#$_tmp/procversion_linux#")
+
+ # Off: no browser process, URL echoed instead.
+ _out=$(RECORD="$_tmp/record_off" PATH="$_stub_path" bash -c \
+ "OPEN_BROWSER=0; $_fn; _open_browser http://localhost:9999")
+ assert_contains \
+ "OPEN_BROWSER=0 prints the URL" \
+ "$_out" "Unsloth Studio is running at: http://localhost:9999"
+ if [ -f "$_tmp/record_off" ]; then
+ echo " FAIL: OPEN_BROWSER=0 still invoked a browser opener"
+ FAIL=$((FAIL + 1))
+ else
+ echo " PASS: OPEN_BROWSER=0 does not invoke a browser opener"
+ PASS=$((PASS + 1))
+ fi
+
+ # On (default): browser opener invoked with the URL.
+ RECORD="$_tmp/record_on" PATH="$_stub_path" bash -c \
+ "OPEN_BROWSER=1; $_fn_linux; _open_browser http://localhost:9999" > /dev/null
+ # xdg-open is backgrounded inside _open_browser; give the stub a moment.
+ _wait_for_record() {
+ _i=0
+ while [ ! -s "$1" ] && [ "$_i" -lt 20 ]; do
+ sleep 0.1
+ _i=$((_i + 1))
+ done
+ }
+ _wait_for_record "$_tmp/record_on"
+ assert_contains \
+ "OPEN_BROWSER=1 invokes a browser opener with the URL" \
+ "$(cat "$_tmp/record_on" 2>/dev/null)" "BROWSER_OPENED:http://localhost:9999"
+
+ # Each rung of the WSL ladder, by removing the one above it. Without this,
+ # the WSL branch is never exercised on a Linux CI runner at all.
+ _rung=1
+ for _drop in "" "powershell.exe" "powershell.exe cmd.exe"; do
+ _rung_dir="$_tmp/rung$_rung"
+ mkdir -p "$_rung_dir"
+ for _s in open xdg-open powershell.exe cmd.exe uname; do
+ cp "$_tmp/$_s" "$_rung_dir/$_s"
+ done
+ for _s in $_drop; do rm -f "$_rung_dir/$_s"; done
+ case "$_drop" in
+ "") _want="powershell.exe" ;;
+ "powershell.exe") _want="cmd.exe" ;;
+ *) _want="xdg-open" ;;
+ esac
+ _rec="$_tmp/record_rung$_rung"
+ _fn_r=$(printf '%s\n' "$_fn" | sed "s#/proc/version#$_tmp/procversion_wsl#")
+ RECORD="$_rec" PATH="$_rung_dir:/usr/bin:/bin" bash -c \
+ "OPEN_BROWSER=1; $_fn_r; _open_browser http://localhost:9999" > /dev/null 2>&1
+ _wait_for_record "$_rec"
+ # The recorder prints the whole arg list, so the URL shows up for
+ # `powershell.exe -NoProfile -Command "Start-Process '<url>'"` too.
+ assert_contains \
+ "WSL rung: ${_want} receives the URL when it is the first available opener" \
+ "$(cat "$_rec" 2>/dev/null)" "http://localhost:9999"
+ _rung=$((_rung + 1))
+ done
+
+ # And with no opener at all, nothing is spawned and a hint goes to stderr.
+ # PATH must contain ONLY this dir: leaving /usr/bin on it would find the
+ # real xdg-open and the "no opener" case would never be reached.
+ _none_dir="$_tmp/rung_none"
+ mkdir -p "$_none_dir"
+ cp "$_tmp/uname" "$_none_dir/uname"
+ cp "$(command -v grep)" "$_none_dir/grep"
+ # Absolute path for bash: the PATH assignment below also governs how bash
+ # itself is looked up, and this PATH deliberately holds almost nothing.
+ _bash=$(command -v bash)
+ _err=$(RECORD="$_tmp/record_none" PATH="$_none_dir" "$_bash" -c \
+ "OPEN_BROWSER=1; $_fn_linux; _open_browser http://localhost:9999" 2>&1 >/dev/null)
+ assert_contains \
+ "no opener available: prints a manual hint instead" \
+ "$_err" "Open in your browser: http://localhost:9999"
+fi
+
+echo ""
+echo "=== install.ps1 launcher template ==="
+
+# grep the file directly: piping the whole installer into grep -q trips
+# SIGPIPE noise from echo once grep exits on first match.
+assert_file_contains() {
+ _label="$1"; _file="$2"; _needle="$3"
+ if grep -qF -- "$_needle" "$_file"; then
+ echo " PASS: $_label"
+ PASS=$((PASS + 1))
+ else
+ echo " FAIL: $_label (expected to find '$_needle')"
+ FAIL=$((FAIL + 1))
+ fi
+}
+
+assert_file_contains \
+ "install.ps1: --no-browser flag parsed" \
+ "$INSTALL_PS1" "\"--no-browser\" { \$OpenBrowserPref = '0' }"
+assert_file_contains \
+ "install.ps1: preference baked into launch-studio.ps1" \
+ "$INSTALL_PS1" "openBrowserDefault = '\$_openBrowser'"
+assert_file_contains \
+ "install.ps1: launcher honors UNSLOTH_STUDIO_NO_BROWSER" \
+ "$INSTALL_PS1" "UNSLOTH_STUDIO_NO_BROWSER"
+assert_file_contains \
+ "install.ps1: gated helper defined" \
+ "$INSTALL_PS1" "function Open-StudioUrl {"
+assert_file_contains \
+ "install.ps1: interactive prompt asks about browser auto-open" \
+ "$INSTALL_PS1" "Open Unsloth Studio in your default browser after launch?"
+assert_file_contains \
+ "install.ps1: prompt Enter keeps the baked preference" \
+ "$INSTALL_PS1" 'elseif ($_existingPref) { $_existingPref }'
+assert_file_contains \
+ "install.ps1: browser prompt respects UNSLOTH_SKIP_AUTOSTART" \
+ "$INSTALL_PS1" '$_browserPromptOk = (-not $SkipAutostart) -and [Environment]::UserInteractive -and'
+assert_file_contains \
+ "install.ps1: post-install launch opens browser via gated watcher" \
+ "$INSTALL_PS1" 'Start-Job -ScriptBlock $_browserWatch'
+assert_file_contains \
+ "install.ps1: post-install launch selects a free port" \
+ "$INSTALL_PS1" 'function Find-PostInstallStudioPort {'
+assert_file_contains \
+ "install.ps1: watcher receives the selected port" \
+ "$INSTALL_PS1" 'ArgumentList @($_watchRootId, $_launchPort)'
+assert_file_contains \
+ "install.ps1: server uses the watcher-selected port" \
+ "$INSTALL_PS1" '& $UnslothExe studio -p $_launchPort'
+# All launcher URL opens must route through the gated helper. The one
+# allowed direct call is inside the post-install $_browserWatch scriptblock,
+# whose Start-Job call site is itself gated on the preference.
+_ps1_direct_open=$(grep -cE 'Start-Process "http://localhost:' "$INSTALL_PS1" || true)
+_ps1_watch_open=$(awk '/\$_browserWatch = \{/{f=1} f && /^ \}$/{exit} f' "$INSTALL_PS1" \
+ | grep -cE 'Start-Process "http://localhost:' || true)
+if [ "$_ps1_direct_open" -eq 1 ] && [ "$_ps1_watch_open" -eq 1 ]; then
+ echo " PASS: only the gated browser watcher opens a URL directly"
+ PASS=$((PASS + 1))
+else
+ echo " FAIL: found $_ps1_direct_open direct URL opens ($_ps1_watch_open in the watcher); all others must route through Open-StudioUrl"
+ FAIL=$((FAIL + 1))
+fi
+
+echo ""
+echo "=== Results ==="
+echo " PASS: $PASS"
+echo " FAIL: $FAIL"
+if [ "$FAIL" -gt 0 ]; then
+ echo "FAILED"
+ exit 1
+fi
+echo "ALL PASSED"