Skip to content

install: support STUDIO_HOME / UNSLOTH_STUDIO_HOME for custom install paths - #5190

Merged
danielhanchen merged 77 commits into
mainfrom
feat/studio-home-env-override
May 6, 2026
Merged

danielhanchen merged 77 commits into
mainfrom
feat/studio-home-env-override

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Apr 26, 2026 •

Copy link
Copy Markdown
Member

Summary

install.sh and install.ps1 hardcode all install paths off $HOME / $env:USERPROFILE with no env-var fallback. This blocks workspace-isolated installs (CI sandboxes, per-PR test environments, multi-tenant boxes) unless the entire HOME / USERPROFILE is faked, which also relocates ~/.gitconfig, ~/.ssh, and other unrelated state.

This PR adds an opt-in env-var override that does only what is needed. Default behavior is unchanged when no env var is set.

Scope

This PR covers shell-launched installs and the Python backend only. The Tauri desktop app is intentionally out of scope (see "Limitations" below).

Resolution priority

Highest to lowest:

  1. UNSLOTH_STUDIO_HOME, if set.
  2. STUDIO_HOME, if set. Convenience alias since the variable name already matches the internal var install.sh sets.
  3. HOME / USERPROFILE explicitly redirected vs the password-database default. Detected via getent (Linux), dscl (macOS), or [Environment]::GetFolderPath("UserProfile") (Windows). Best-effort: when the detection mechanism is unavailable the check is skipped and we fall through to step 4.
  4. Default: legacy $HOME/.unsloth/studio (or $USERPROFILE\.unsloth\studio on Windows). Identical to today's behavior.

The env vars are explicit single-purpose signals (the user typed UNSLOTH_STUDIO_HOME=... specifically to redirect Studio). HOME redirection is broader and incidental: the user may have redirected HOME for unrelated reasons without wanting Studio to follow it. When both are set, the more specific signal wins.

What changes when an env-var override fires

Path Default Override
STUDIO_HOME $HOME/.unsloth/studio the override path
DATA_DIR $HOME/.local/share/unsloth $STUDIO_HOME/share
_LOCAL_BIN (unsloth shim) $HOME/.local/bin $STUDIO_HOME/bin
Shell rc-file PATH append yes no
Windows registry PATH update yes no (current session only)
llama.cpp build dir $HOME/.unsloth/llama.cpp $STUDIO_HOME/llama.cpp (unless override resolves to the legacy default, in which case it stays at $HOME/.unsloth/llama.cpp to keep one shared build across legacy installs)

Persistent shell-profile and registry PATH writes are skipped under env-override mode so the user's profile is not polluted with a workspace-scoped path that may later be deleted. Caller is expected to invoke via absolute path or add the bin dir to PATH explicitly.

Generated runtime launcher

The Unix launcher script (launch-studio.sh) is the only piece that reads DATA_DIR at runtime (it sources studio.conf from there). The hardcoded DATA_DIR inside the LAUNCHER_EOF heredoc is replaced with an @@DATA_DIR@@ placeholder substituted via sed at install time, so the runtime launcher reads studio.conf from the same place install-time wrote it.

The PowerShell launcher already bakes the absolute exe path directly into the launcher script, so no analogous heredoc substitution is needed there.

In env-override mode, studio.conf also exports UNSLOTH_STUDIO_HOME and UNSLOTH_LLAMA_CPP_PATH so a fresh shell launching the binary directly (no shell rc inheritance) still resolves the same Studio root and llama.cpp build dir as the install.

Python CLI / backend

unsloth_cli/commands/studio.py and studio/backend/utils/paths/storage_roots.py resolve the Studio root with the same priority chain (UNSLOTH_STUDIO_HOME -> STUDIO_HOME -> sys.prefix inference with installer sentinel -> legacy default). The Python CLI re-exports UNSLOTH_STUDIO_HOME and UNSLOTH_LLAMA_CPP_PATH only when the resolved root is a real custom override (not the legacy default), so downstream subprocesses (setup.sh, backend run.py) and unsloth-zoo's import-time GGUF binding all see the same custom root.

Limitations

The Tauri desktop app does NOT honor UNSLOTH_STUDIO_HOME / STUDIO_HOME. It continues to use the legacy ~/.unsloth/studio path for:

  • The managed unsloth binary lookup (process.rs::find_unsloth_binary)
  • .desktop_secret for desktop login (desktop_auth.rs)
  • tauri.log location (main.rs::setup_logging)
  • "Open logs directory" command (commands.rs::open_logs_dir)
  • Installer subprocess working directory (install.rs)

This is intentional. The desktop app launches from Finder / Start Menu / Desktop without inheriting the launching shell's environment, so a per-session env var doesn't reach the app process. Bridging that gap requires a persistence mechanism (marker file, registry entry, or app-config setting) with its own cleanup / validation surface, which is out of scope for this PR.

If you need workspace-isolated Studio installs that the Tauri desktop app can also pick up, either:

  1. Use a shell-launched install and run Studio via the printed shim path, or
  2. Set UNSLOTH_STUDIO_HOME in your shell rc / system environment so the desktop app inherits it on every login.

A separate, focused PR can add proper Tauri-side custom-root support later.

Examples

# Workspace-scoped install, no system pollution:
UNSLOTH_STUDIO_HOME=/work/ws_42/studio bash install.sh --local
/work/ws_42/studio/bin/unsloth studio -p 8888

# CI sandbox via HOME redirect (existing pattern, still works):
HOME=/tmp/ci_sandbox bash install.sh --local

# Default (unchanged):
bash install.sh --local
# Same on Windows:
$env:UNSLOTH_STUDIO_HOME = 'D:\work\ws_42\studio'
.\install.ps1 --local
& 'D:\work\ws_42\studio\bin\unsloth.exe' studio

Test plan

  • Default install (no env vars): paths resolve to $HOME/.unsloth/studio, $HOME/.local/share/unsloth, $HOME/.local/bin. Byte-identical to pre-PR.
  • HOME=/tmp/x bash install.sh --local: paths resolve under /tmp/x/.
  • UNSLOTH_STUDIO_HOME=/tmp/y bash install.sh --local: paths resolve under /tmp/y/{share,bin}.
  • STUDIO_HOME=/tmp/z bash install.sh --local (alias): same as above.
  • Both HOME redirect and UNSLOTH_STUDIO_HOME set: env var wins, install follows the override.
  • UNSLOTH_STUDIO_HOME=/proc/1/cantwrite: exits with clear ERROR: STUDIO_HOME=... cannot be created. message.
  • UNSLOTH_STUDIO_HOME=$HOME/.unsloth/studio (override equals legacy default): llama.cpp resolves to $HOME/.unsloth/llama.cpp (legacy-equality branch).
  • bash -n install.sh clean; PowerShell parser clean on install.ps1, setup.sh, setup.ps1.
  • End-to-end probe via test_unsloth_studio.py --pr 5190 --temp-workspace: clones PR branch, installs Studio with UNSLOTH_STUDIO_HOME pinned to a temp workspace, starts the backend, drives the UI via Playwright MCP. PR code resolves under the workspace, /chat and /studio render, all API calls return 200.
  • Tauri Rust suite: cargo test --bins -- --test-threads=1 -> 34/34 pass (pre-PR baseline; Tauri code unchanged).

Backwards compatibility

When no env var is set and HOME is at the password-DB default, the produced file layout, the shell rc PATH append, the Windows registry PATH update, and all desktop / unsloth studio update flows are byte-identical to today. Existing --local, --no-torch, --package, --python, --tauri, --verbose flags are untouched.

… paths

Currently install.sh and install.ps1 hardcode all install paths off
$HOME / $env:USERPROFILE with no env-var fallback. This blocks
workspace-isolated installs (CI sandboxes, per-PR test environments,
multi-tenant boxes) unless the entire HOME / USERPROFILE is faked,
which also relocates ~/.gitconfig, ~/.ssh, and other unrelated state.

Add an opt-in env-var override that does only what is needed.

Resolution priority (highest first):
1. HOME / USERPROFILE explicitly redirected vs the password-database
   default. Detected via getent (Linux), dscl (macOS), or
   [Environment]::GetFolderPath (Windows). Best-effort: when the
   detection mechanism is unavailable the check is skipped and we
   fall through to step 2.
2. UNSLOTH_STUDIO_HOME, if set.
3. STUDIO_HOME, if set (alias for convenience; the variable name
   already matches the internal var install.sh sets).
4. Default: legacy $HOME/.unsloth/studio (or
   $USERPROFILE\.unsloth\studio on Windows). Identical to today's
   behavior when no env var is set.

When an env var override fires:
* DATA_DIR is nested inside ($STUDIO_HOME/share, or $StudioHome\share
  on Windows) so the runtime launcher and shortcuts find studio.conf
  in the same place install-time wrote it.
* The unsloth CLI shim lands at $STUDIO_HOME/bin/unsloth (Unix) or
  $StudioHome\bin\unsloth.exe (Windows). On Windows the shim already
  lives under $StudioHome; the change only redirects DATA_DIR and
  skips the persistent registry PATH update.
* Persistent shell PATH modifications are skipped (no .bashrc /
  .zshrc / .profile append on Unix; no Add-ToUserPath on Windows).
  Caller is expected to invoke via absolute path or add the bin dir
  to PATH explicitly. Avoids polluting the user's profile with a
  workspace-scoped path that may be deleted.

The Unix launcher script is the only piece that must read DATA_DIR
at runtime (it sources studio.conf from there). The hardcoded
DATA_DIR inside the LAUNCHER_EOF heredoc is replaced with an
@@DATA_DIR@@ placeholder substituted via sed at install time, using
the same approach the script already uses for other install-time
substitutions.

Default path behavior is unchanged: when no env var is set and HOME
is not redirected, install.sh / install.ps1 produce exactly the same
file layout as today.

Test scenarios verified locally on install.sh:
* Default (no env vars)             -> $HOME/.unsloth/studio (legacy)
* HOME=/tmp/x                       -> /tmp/x/.unsloth/studio
* UNSLOTH_STUDIO_HOME=/tmp/y        -> /tmp/y as STUDIO_HOME root
* STUDIO_HOME=/tmp/z (alias)        -> /tmp/z as STUDIO_HOME root
* HOME redirect + env var (HOME wins) -> install follows HOME
* Unwritable override               -> exits with clear ERROR message

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for custom installation directories via environment variables (UNSLOTH_STUDIO_HOME and STUDIO_HOME) and handles redirected home directories in both the PowerShell and Shell installers. It also modifies PATH management to avoid persistent system changes when using these overrides. Review feedback identified a bug in the PowerShell script where an invalid property access on a GUID object would prevent unique probe file creation, and suggested using the -- delimiter in shell commands to safely handle paths starting with dashes.

Comment thread install.ps1 Outdated
Write-Host "ERROR: STUDIO_HOME=$envOverride cannot be created or accessed." -ForegroundColor Red
exit 1
}
$probe = Join-Path $StudioHome (".unsloth-write-probe-" + [guid]::NewGuid().Guid)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The property .Guid does not exist on the System.Guid object returned by [guid]::NewGuid(). This results in the probe filename always being .unsloth-write-probe- without a unique suffix, which could lead to collisions if multiple installers run concurrently. Removing .Guid will allow PowerShell to use the default string representation of the GUID, ensuring uniqueness.

        $probe = Join-Path $StudioHome (".unsloth-write-probe-" + [guid]::NewGuid())

Comment thread install.sh Outdated
Comment on lines +191 to +193
mkdir -p "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; }
[ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; }
STUDIO_HOME="$(cd "$_override" && pwd)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is safer to use -- with mkdir and cd to prevent paths starting with a dash from being interpreted as command-line options. This is particularly important for environment variables that might be user-controlled.

Suggested change
mkdir -p "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; }
[ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; }
STUDIO_HOME="$(cd "$_override" && pwd)"
mkdir -p -- "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; }
[ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; }
STUDIO_HOME="$(cd -- "$_override" && pwd)"

Flip the resolution order so explicit env vars take precedence over
HOME / USERPROFILE redirection.

New priority (highest first):
1. UNSLOTH_STUDIO_HOME, if set.
2. STUDIO_HOME, if set.
3. HOME / USERPROFILE explicitly redirected.
4. Default.

Rationale: the env vars are explicit single-purpose signals (the user
typed UNSLOTH_STUDIO_HOME=... specifically to redirect Studio). HOME
redirection is broader and incidental -- the user may have redirected
HOME for unrelated reasons (workspace tools, container builds) without
wanting Studio to follow it. When both are set, the more specific
signal should win.

When only HOME is redirected (no env var), behavior is unchanged from
the previous commit: install follows $HOME.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 64b384b804

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.ps1 Outdated
$StudioRedirectMode = 'env'
} else {
$StudioHome = Join-Path $env:USERPROFILE ".unsloth\studio"
$StudioDataDir = Join-Path $env:LOCALAPPDATA "Unsloth Studio"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Guard LOCALAPPDATA before building StudioDataDir

The new destination-resolution block computes $StudioDataDir with Join-Path $env:LOCALAPPDATA ... before any availability check, and this runs under $ErrorActionPreference = "Stop". In environments where LOCALAPPDATA is unset (for example, some service/CI contexts), Join-Path throws and aborts the installer, whereas the previous flow only skipped shortcut creation when LOCALAPPDATA was unavailable. Please null-check (or defer this assignment) so installs can continue without shortcuts.

Useful? React with 👍 / 👎.

Comment thread install.sh Outdated

# Substitute @@DATA_DIR@@ with the resolved DATA_DIR. Use | as the
# sed delimiter so absolute paths (which contain /) are safe.
sed -i.bak "s|@@DATA_DIR@@|$DATA_DIR|g" "$_css_launcher" && rm -f "${_css_launcher}.bak"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape DATA_DIR before sed template substitution

This substitution inserts raw $DATA_DIR into sed's replacement string; with custom install paths containing replacement metacharacters (notably &), the generated launcher gets a corrupted DATA_DIR (e.g., /tmp/a&b expands to include the matched placeholder text). That breaks launch-studio.sh at runtime because it reads studio.conf from the wrong path. Escape replacement metacharacters before running sed.

Useful? React with 👍 / 👎.

danielhanchen and others added 2 commits April 26, 2026 08:17
… edge cases)

Fixes from gemini-code-assist + chatgpt-codex-connector + reviewer.py
20-parallel run on the open PR.

install.sh:
* Escape sed replacement metacharacters before substituting @@DATA_DIR@@.
  Two-stage escape: ' -> '\'' for safe single-quote shell embedding,
  then \, &, | for sed replacement string + chosen delimiter. Heredoc
  switched to single-quoted DATA_DIR='@@DATA_DIR@@' so we only need
  single-quote escaping at runtime. Verified end-to-end with paths
  containing & and | (the sed delimiter).
* Pass UNSLOTH_STUDIO_HOME into both setup.sh invocations
  (--local and PyPI paths) so the downstream install resolves the
  same Studio root install.sh picked.
* macOS .app stub: replace hardcoded
  exec "$HOME/.local/share/unsloth/launch-studio.sh" with
  exec "$_css_data_dir/launch-studio.sh" so the .app launches the
  resolved launcher even in env-override mode.
* Use mkdir -p -- and cd -- when validating the env override so
  paths starting with - cannot be misread as flags.

install.ps1:
* Drop .Guid from [guid]::NewGuid().Guid: the property does not
  exist; the probe filename was always identical and not unique.
  Default ToString() on System.Guid produces the canonical UUID
  string we want.
* Guard LOCALAPPDATA before Join-Path to avoid aborting the
  installer in service / CI contexts where LOCALAPPDATA is unset
  (Join-Path under $ErrorActionPreference='Stop' would otherwise
  throw). Computed once into $defaultDataDir; both 'profile' and
  'default' branches reuse it.
* Set $env:UNSLOTH_STUDIO_HOME for the duration of the
  'unsloth studio setup' subprocess so studio/setup.ps1 and
  unsloth_cli see the same install root install.ps1 picked.
  Restored in a finally block.

studio/setup.sh:
* Honor UNSLOTH_STUDIO_HOME / STUDIO_HOME (alias) when resolving
  STUDIO_HOME, VENV_DIR, VENV_T5_*_DIR. Falls back to the legacy
  $HOME/.unsloth/studio when no override is set.

studio/setup.ps1:
* Same change in PowerShell: honor $env:UNSLOTH_STUDIO_HOME /
  $env:STUDIO_HOME for $StudioHome / $VenvDir resolution.

unsloth_cli/commands/studio.py:
* Replace the module-level constant
  STUDIO_HOME = Path.home() / ".unsloth" / "studio"
  with a resolver that honors UNSLOTH_STUDIO_HOME / STUDIO_HOME
  before falling through to the legacy default. Same precedence
  the installers use.

Verified locally: 6 install.sh scenarios still produce correct paths
(default, HOME redirect, env var, alias, both, bad override). New
sed-escape unit tests pass for paths containing & and |. Python
resolver matches priority: UNSLOTH_STUDIO_HOME > STUDIO_HOME > default.
@danielhanchen

Copy link
Copy Markdown
Member Author

Pushed c56c1499 addressing review feedback:

install.sh

  • sed substitution now escapes &, \, | (the chosen delimiter) and ' so paths containing those characters do not corrupt the generated launcher. Heredoc switched to single-quoted DATA_DIR='@@DATA_DIR@@' to keep the runtime safe.
  • macOS .app stub now execs $_css_data_dir/launch-studio.sh (the resolved path) instead of the hardcoded $HOME/.local/share/unsloth/launch-studio.sh.
  • mkdir -p and cd now use -- for paths starting with -.
  • Both setup.sh invocations now pass UNSLOTH_STUDIO_HOME so downstream sees the resolved root.

install.ps1

  • Dropped .Guid from [guid]::NewGuid().Guid (property does not exist). Probe filenames are now actually unique.
  • Guarded LOCALAPPDATA before Join-Path to avoid aborting under ErrorActionPreference='Stop' in service / CI contexts where it is unset.
  • Set $env:UNSLOTH_STUDIO_HOME around the unsloth studio setup invocation (restored via finally).

studio/setup.sh, studio/setup.ps1, unsloth_cli/commands/studio.py

  • Honor UNSLOTH_STUDIO_HOME / STUDIO_HOME (alias) for STUDIO_HOME / VENV_DIR / VenvDir resolution. Falls back to the legacy $HOME/.unsloth/studio when no override is set.

Local verification:

  • All 6 install.sh scenarios (default, HOME redirect, UNSLOTH_STUDIO_HOME, STUDIO_HOME alias, both, bad override) produce correct paths.
  • New sed-escape unit tests pass for paths containing & and |.
  • Python resolver priority verified: UNSLOTH_STUDIO_HOME > STUDIO_HOME > default.

@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 570e6d323d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread unsloth_cli/commands/studio.py Outdated
override = os.environ.get("UNSLOTH_STUDIO_HOME") or os.environ.get("STUDIO_HOME")
if override:
return Path(override).expanduser().resolve()
return Path.home() / ".unsloth" / "studio"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve studio home from active venv when override is unset

This fallback hard-codes ~/.unsloth/studio whenever UNSLOTH_STUDIO_HOME/STUDIO_HOME is not exported, but the new installer flow advertises launching from a custom shim path (for example <custom>/bin/unsloth) without requiring users to export env vars each time. In that case studio_default compares sys.prefix against STUDIO_HOME/unsloth_studio, treats the process as outside the Studio venv, then looks for a venv under ~/.unsloth/studio and exits with “Studio not set up,” so custom-path installs cannot launch reliably unless users manually set an env var on every run.

Useful? React with 👍 / 👎.

Comment thread install.sh Outdated
cat > "$_css_macos_dir/launch-studio" << STUB_EOF
#!/bin/sh
exec "$HOME/.local/share/unsloth/launch-studio.sh" "\$@"
exec "$_css_data_dir/launch-studio.sh" "\$@"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Escape custom data dir before writing macOS launch stub

The macOS .app stub embeds $_css_data_dir directly into a double-quoted shell string, so custom install paths containing shell metacharacters (notably $) are expanded at runtime. For example, a path like /tmp/a$B produces a launcher that resolves to the wrong location and fails to execute launch-studio.sh. The main Unix launcher already escapes DATA_DIR; the macOS stub needs the same escaping to keep custom paths literal.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability to override the default installation directory using the UNSLOTH_STUDIO_HOME or STUDIO_HOME environment variables. These changes are implemented across the PowerShell and Bash installers, setup scripts, and the Python CLI to ensure consistent path resolution. The update also includes logic to handle session-specific PATH modifications and permission validation for custom directories. Feedback was provided regarding the portability of a sed command in the Bash installer to ensure compatibility across different systems.

Comment thread install.sh Outdated
# 2) \, &, | for sed replacement-string + chosen delimiter
_sq_escaped=$(printf '%s' "$DATA_DIR" | sed "s/'/'\\\\''/g")
_sed_safe=$(printf '%s' "$_sq_escaped" | sed 's/[\\&|]/\\&/g')
sed -i.bak "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" && rm -f "${_css_launcher}.bak"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of sed -i.bak is not POSIX-compliant and its behavior varies between GNU and BSD (macOS) versions of sed. For a #!/bin/sh script, a more portable approach is to redirect the output to a temporary file and then move it back to the original location. This avoids reliance on the -i flag which may not be available in minimal environments like BusyBox.

Suggested change
sed -i.bak "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" && rm -f "${_css_launcher}.bak"
sed "s|@@DATA_DIR@@|$_sed_safe|g" "$_css_launcher" > "$_css_launcher.tmp" && mv "$_css_launcher.tmp" "$_css_launcher"

GNU sed -i.bak vs BSD/macOS sed -i.bak vs BusyBox sed have subtly
different semantics. Use the POSIX-portable redirect-then-mv pattern
instead. Functionally identical, runs everywhere.
Without this, a custom-root install (UNSLOTH_STUDIO_HOME=/work/studio
bash install.sh --local) only worked in the same shell that ran the
installer. Closing the terminal and reopening lost the env var, the
PATH was deliberately not persisted, and the Python CLI fell back to
~/.unsloth/studio. Result: 'Studio not set up' or quietly operating on
a stale legacy install.

Three persistence layers, all backwards-compatible (default installs
emit zero changes):

1. Unix studio.conf
   install.sh now writes 'export UNSLOTH_STUDIO_HOME=...' next to
   UNSLOTH_EXE in studio.conf when in env-override mode. The launcher
   sources studio.conf at startup so the exec'd binary gets the var.
   Default installs do not write this line; studio.conf stays
   byte-identical to before.

2. Windows launch-studio.ps1
   install.ps1 prepends '$env:UNSLOTH_STUDIO_HOME = ...' to the
   generated launcher when in env-override mode. Default installs
   produce the same launcher content as before.

3. Python sys.prefix inference
   storage_roots.studio_root() and unsloth_cli/commands/studio.py
   now infer the install root from sys.prefix when no env var is
   set (Path(sys.prefix).parent for unsloth_studio venvs). Catches
   direct invocations of <STUDIO_HOME>/bin/unsloth that bypass the
   launcher entirely.

unsloth_cli/commands/studio.py also re-exports the resolved
UNSLOTH_STUDIO_HOME via os.environ.setdefault so child processes
(setup script, backend run.py) inherit it.

Backend storage roots (storage_roots.studio_root, cache_root) now
respect the env var via the shared resolver. run.py PID file,
transformers_version.py T5 venvs, and model_config.py vision-check
venv all switch to studio_root() so custom installs are
self-contained.

studio/setup.ps1: T5 sidecar venvs now resolve under $StudioHome
(was $env:USERPROFILE\.unsloth\studio\.venv_t5_*).

studio/setup.sh + studio/setup.ps1: llama.cpp build dir nests under
$STUDIO_HOME / $StudioHome when env-override is active, otherwise
keeps the legacy ~/.unsloth/llama.cpp.

Verified locally:
* studio.conf write block: env-override mode emits the export line;
  default mode does not (byte-identical to today).
* PowerShell heredoc interpolation: correct output for both modes.
* studio_root() resolver: default, UNSLOTH_STUDIO_HOME, STUDIO_HOME
  alias, and sys.prefix-based inference all return correct paths.
* cache_root() now derives from studio_root().

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bad168e182

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread studio/setup.sh Outdated
Comment on lines +568 to +569
if [ -n "${UNSLOTH_STUDIO_HOME:-}" ] || [ -n "${STUDIO_HOME:-}" ]; then
UNSLOTH_HOME="$STUDIO_HOME"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate llama.cpp relocation on real override state

STUDIO_HOME is always populated earlier in setup.sh, so this condition is always true and default installs now place llama.cpp under $HOME/.unsloth/studio/llama.cpp instead of the legacy $HOME/.unsloth/llama.cpp. The backend binary lookup (_find_llama_server_binary in studio/backend/core/inference/llama_cpp.py) still searches the legacy path unless UNSLOTH_LLAMA_CPP_PATH is set, so fresh default installs can fail to find llama-server for GGUF inference. Please key this branch off actual override mode (for example _studio_override) so non-override installs keep the old location.

Useful? React with 👍 / 👎.

Two fixes from running a 25-scenario simulation sweep against install.sh
across path edge cases (spaces, apostrophes, ampersands, pipes,
backslashes, dollar signs, Unicode, trailing slash, relative paths).

1. UNSLOTH_STUDIO_HOME=~/foo was landing as literal '~/foo' (env vars
   are not subject to tilde expansion). Added a POSIX-portable case
   block in install.sh, install.ps1, studio/setup.sh, studio/setup.ps1
   that expands a leading ~ or ~/ to $HOME / $env:USERPROFILE.
   The prefix-removal pattern is single-quoted ('${var#'~/'}') so the
   shell does not tilde-expand the pattern back to $HOME/ before
   matching -- a subtle dash/bash gotcha.

2. macOS .app stub used an unquoted heredoc ('<< STUB_EOF'), so any
   $VAR / backtick / etc in the path would expand at .app launch time.
   Switched to single-quoted heredoc ('<< 'STUB_EOF'') with a
   placeholder + sed substitution + single-quoted shell embedding,
   matching the @@DATA_DIR@@ pattern already used for launch-studio.sh.

Verified: 25/25 simulation scenarios pass on Linux dash + bash,
including paths with $VAR, &, |, \\, ', spaces, and Unicode. End-to-end
install in env-mode + fresh-shell launcher invocation confirmed: studio
binds to /api/health from a clean env, and sys.prefix-based inference
correctly returns the workspace root.
@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for custom installation directories via the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables across Windows and Unix-like systems. The changes include updated logic in the installation and setup scripts to resolve, validate, and persist these custom paths, as well as centralized path resolution in the backend and CLI components. Feedback was provided to improve the robustness of shell scripts by adding explicit exit checks for subshell assignments, ensuring the scripts terminate correctly if directory resolution fails in shells like dash.

Comment thread install.sh Outdated
if [ -n "$_override" ]; then
mkdir -p -- "$_override" 2>/dev/null || { echo "ERROR: STUDIO_HOME=$_override cannot be created." >&2; exit 1; }
[ -w "$_override" ] || { echo "ERROR: STUDIO_HOME=$_override is not writable." >&2; exit 1; }
STUDIO_HOME="$(cd -- "$_override" && pwd)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In many shells (including dash, the default /bin/sh on Ubuntu), set -e does not trigger an exit when a subshell fails during a variable assignment. If cd fails here, STUDIO_HOME will be empty, which could lead to DATA_DIR being incorrectly set to /share. Adding || exit 1 ensures the script terminates on failure.

Suggested change
STUDIO_HOME="$(cd -- "$_override" && pwd)"
STUDIO_HOME="$(cd -- "$_override" && pwd)" || exit 1

Comment thread studio/setup.sh Outdated
esac
if [ -n "$_studio_override" ]; then
mkdir -p -- "$_studio_override"
STUDIO_HOME="$(cd -- "$_studio_override" && pwd)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Adding || exit 1 to the subshell assignment ensures the script exits if the directory cannot be resolved, preventing STUDIO_HOME from becoming empty and causing downstream path issues.

Suggested change
STUDIO_HOME="$(cd -- "$_studio_override" && pwd)"
STUDIO_HOME="$(cd -- "$_studio_override" && pwd)" || exit 1

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ee28571611

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread studio/setup.ps1 Outdated
Comment on lines +1821 to +1822
if ($env:UNSLOTH_STUDIO_HOME -or $env:STUDIO_HOME) {
$UnslothHome = $StudioHome

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Gate Windows llama.cpp relocation on true override mode

In studio/setup.ps1, the new if ($env:UNSLOTH_STUDIO_HOME -or $env:STUDIO_HOME) condition is true during normal installs because install.ps1 now always sets UNSLOTH_STUDIO_HOME before invoking studio setup. That relocates llama.cpp to $StudioHome\llama.cpp even for default installs, while backend discovery still defaults to %USERPROFILE%\.unsloth\llama.cpp unless UNSLOTH_LLAMA_CPP_PATH is set, so GGUF inference can fail to find llama-server on fresh Windows setups. This branch should key off actual override state, not mere env-var presence.

Useful? React with 👍 / 👎.

danielhanchen and others added 3 commits April 26, 2026 09:23
Reviewer.py 20-runs cycle 1 found a unanimous P1 regression: a default
'unsloth studio update' relocates llama.cpp from ~/.unsloth/llama.cpp
to ~/.unsloth/studio/llama.cpp, because the CLI was re-exporting
UNSLOTH_STUDIO_HOME unconditionally and install.sh / install.ps1 were
passing it into setup.{sh,ps1} unconditionally. The setup scripts
treated the var's mere presence as "env-override mode" and relocated
the llama.cpp build dir away from the legacy path, breaking the
runtime backend's _find_llama_server_binary lookup on default installs.

Fixes:

* unsloth_cli/commands/studio.py: _resolve_studio_home now returns
  (path, is_custom). Re-export only when is_custom -- a real env
  override or a sys.prefix inference that resolves to a non-legacy
  path. Default installs leave UNSLOTH_STUDIO_HOME unset.

* install.sh: gate UNSLOTH_STUDIO_HOME on $_STUDIO_HOME_REDIRECT == env
  before calling setup.sh. Use 'env $VARS bash setup.sh' so the var
  is set only for the subprocess, never leaked.

* install.ps1: gate $env:UNSLOTH_STUDIO_HOME on $StudioRedirectMode
  -eq 'env' before invoking 'unsloth studio setup'. Restore prior
  value in finally block (unset if it wasn't set).

* studio/setup.sh + setup.ps1: decide llama.cpp install root from
  the resolved $STUDIO_HOME (not from env-var presence). If the
  resolved path equals the legacy default ($HOME/.unsloth/studio),
  fall back to ~/.unsloth/llama.cpp. This makes setup robust against
  a stale UNSLOTH_STUDIO_HOME inherited from a parent process that
  happens to point at the legacy default.

* studio/backend/core/inference/llama_cpp.py:
  - _find_llama_server_binary() now searches studio_root() / llama.cpp
    AND the legacy ~/.unsloth/llama.cpp (de-duped). Custom-root
    installs become discoverable; default installs unaffected.
  - kill_orphaned_servers ownership allowlist also includes
    studio_root() / llama.cpp so custom-root processes are cleanable.

Verified locally:
* 25/25 sim scenarios still pass (path edge cases unchanged).
* setup.sh unit test: default-mode lands UNSLOTH_HOME at $HOME/.unsloth;
  env-mode lands at $STUDIO_HOME.
* Python CLI unit test: default-mode returns is_custom=False and does
  NOT setdefault UNSLOTH_STUDIO_HOME; env-mode sets is_custom=True.
Gemini review feedback: in dash, set -e does not trigger on subshell
failures inside variable assignments. If 'cd -- "$_override" && pwd'
fails, STUDIO_HOME stays empty and DATA_DIR collapses to /share. Add
explicit '|| exit 1' on both install.sh:187 and setup.sh:413.
@danielhanchen

Copy link
Copy Markdown
Member Author

Cycle-1 fixes pushed:

  • Default-install regression (P1, 18-20/20 reviewer.py votes): default unsloth studio update no longer relocates llama.cpp from ~/.unsloth/llama.cpp to ~/.unsloth/studio/llama.cpp. CLI re-export, install.sh, install.ps1, setup.sh, setup.ps1 now gate on real env-override mode (resolved path != legacy default), not env-var presence.
  • Backend llama-server discovery (P1): _find_llama_server_binary() and kill_orphaned_servers now search both studio_root() / llama.cpp and the legacy ~/.unsloth/llama.cpp. Custom-root installs become discoverable; default installs unaffected.
  • dash set -e gap (gemini medium): STUDIO_HOME=$(cd ...)" || exit 1 on both install.sh and setup.sh.

Default behavior is now byte-identical to today when no env var is set.

@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02ff12c529

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread install.sh Outdated
_STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME"
fi
if [ "$STUDIO_LOCAL_INSTALL" = true ]; then
env $_STUDIO_ENV_FOR_SETUP \

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Quote custom STUDIO_HOME when passing env to setup.sh

The setup invocation uses env $_STUDIO_ENV_FOR_SETUP ... with an unquoted assignment string, so custom roots containing spaces or shell metacharacters are split before env runs. For example, UNSLOTH_STUDIO_HOME="/tmp/My Studio" becomes separate argv tokens and env fails before setup.sh executes, breaking the new custom-install flow for valid paths. Pass the variable as a quoted assignment (or set it inline with a quoted value) so the full path is preserved.

Useful? React with 👍 / 👎.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for custom installation directories via the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables. The changes include updating the PowerShell and Bash installers to resolve and persist these paths, modifying the Python backend to use a centralized studio_root helper, and updating the CLI to propagate these settings to child processes. Review feedback highlighted a potential issue in the Bash installer where unquoted environment variables could cause failures if paths contain spaces, suggesting a more robust assignment method.

Comment thread install.sh Outdated
Comment on lines 1696 to 1704
_STUDIO_ENV_FOR_SETUP=""
if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then
_STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME"
fi
if [ "$STUDIO_LOCAL_INSTALL" = true ]; then
env $_STUDIO_ENV_FOR_SETUP \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of env $_STUDIO_ENV_FOR_SETUP without quotes is not space-safe. If STUDIO_HOME contains spaces, the shell will split the variable assignment into multiple arguments, causing env to fail (it will try to execute the second part of the path as a command). Additionally, for consistency with the PowerShell installer, UNSLOTH_STUDIO_HOME should be explicitly reset (set to an empty string) when not in env-override mode to prevent inheriting stale values from the parent shell. Using direct variable assignments before the command is a safer and more standard approach in POSIX sh.

Suggested change
_STUDIO_ENV_FOR_SETUP=""
if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then
_STUDIO_ENV_FOR_SETUP="UNSLOTH_STUDIO_HOME=$STUDIO_HOME"
fi
if [ "$STUDIO_LOCAL_INSTALL" = true ]; then
env $_STUDIO_ENV_FOR_SETUP \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \
_STUDIO_HOME_VAL=""
if [ "$_STUDIO_HOME_REDIRECT" = "env" ]; then
_STUDIO_HOME_VAL="$STUDIO_HOME"
fi
if [ "$STUDIO_LOCAL_INSTALL" = true ]; then
UNSLOTH_STUDIO_HOME="$_STUDIO_HOME_VAL" \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \

Comment thread install.sh Outdated
Comment on lines 1715 to 1718
env $_STUDIO_ENV_FOR_SETUP \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Applying the same space-safe assignment and explicit reset for the non-local install path to ensure UNSLOTH_STUDIO_HOME is correctly propagated or cleared.

Suggested change
env $_STUDIO_ENV_FOR_SETUP \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \
UNSLOTH_STUDIO_HOME="$_STUDIO_HOME_VAL" \
SKIP_STUDIO_BASE="$_SKIP_BASE" \
SKIP_STUDIO_FRONTEND="$_SKIP_FRONTEND" \
STUDIO_PACKAGE_NAME="$PACKAGE_NAME" \

Cycle 2 reviewer.py 20-runs found a unanimous P1: passing the env-var
through 'env $_STUDIO_ENV_FOR_SETUP' word-splits on whitespace, so a
custom root like '/tmp/Unsloth Studio' becomes 'UNSLOTH_STUDIO_HOME=
/tmp/Unsloth' followed by env trying to exec 'Studio'.

Replaced with a tiny helper that prepends the env-var directly to the
argv (no string-form intermediary), so spaces are preserved as a
single argument. Default-mode invocation skips the env-var entirely.

Verified: 'UNSLOTH_STUDIO_HOME=/tmp/test space/studio' now reaches
setup.sh as a single value.
@danielhanchen

Copy link
Copy Markdown
Member Author

Cycle-2 fix: argv-safe setup handoff. The unanimous P1 was that env $_STUDIO_ENV_FOR_SETUP \ word-split on space-containing paths. Replaced with a function that prepends UNSLOTH_STUDIO_HOME=$STUDIO_HOME directly to argv. Verified /tmp/test space/studio now reaches setup.sh as one value.

@danielhanchen

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements support for custom installation roots using the UNSLOTH_STUDIO_HOME and STUDIO_HOME environment variables. The changes span the PowerShell and Shell installers, the CLI, and the backend path resolution utilities, ensuring that virtual environments, data directories, and binaries are correctly located in custom workspaces while preserving backward compatibility for default installations. I have no feedback to provide.

danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 2, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 3, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 4, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 4, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 4, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 7, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
Issue #8865 asks for an install that stays in one directory. UNSLOTH_STUDIO_HOME
(#5190) already moves the Studio root, the share dir, the shim and the native
runtimes, and suppresses the shell-rc and desktop-entry writes, but two things
were missing: nothing tells anyone the mode exists, and uv still writes its
wheel cache to ~/.cache/uv, its managed interpreter to ~/.local/share/uv and
that interpreter's symlinks to ~/.local/bin. On a torch install the uv cache is
the largest single thing landing in the home directory.

--portable contains the install where it already is; --root DIR relocates it.
Both pin UV_CACHE_DIR, UV_PYTHON_INSTALL_DIR, UV_TOOL_DIR, UV_PYTHON_BIN_DIR and
UV_NO_MODIFY_PATH before the uv bootstrap runs, because there is no moving a
cache after the fact. Verified against uv directly: a venv, a pip install and a
managed CPython download leave zero files in the home directory.

The shim becomes a wrapper rather than a symlink. A symlink exports nothing, so
bin/unsloth from a fresh shell would find the interpreter (the backend infers
STUDIO_HOME from sys.prefix) and still send uv to ~/.cache/uv -- contained until
the first update, then not. studio.conf restates the same roots for the launcher.

--tauri keeps rejecting a custom root: the desktop app resolves ~/.unsloth/studio
in Rust and never sees a per-session variable, so it would launch a Studio that
is not there. Default installs are unchanged.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
…r asked for

Five defects found by reviewing the stack against its own acceptance criteria.
Each fix was checked by removing it again and watching the new test fail.

1. Uninstalling no longer empties ~/.unsloth. --portable with no --root selects
   that directory for the user, so it is the one root they never named, and
   anything they keep beside Unsloth is theirs. The master-root loop rm -rf'd it
   whole; it now takes the portable children by name and leaves the rest to the
   default block's rmdir, which refuses a non-empty directory. A root the user
   DID name still goes in one piece, as it always has for UNSLOTH_STUDIO_HOME.
   Before: a file at ~/.unsloth/important.txt was deleted. After: it survives.

2. The portable shim, share/studio.conf and _export_portable_roots defaulted the
   cache locations instead of seizing them. storage_roots._setup_cache_env() has
   always yielded to an explicit value and main's _configure_uv_cache reports
   "preserving custom UV_CACHE_DIR", so the same install honoured or discarded a
   user's multi-GB wheel cache depending on the entry point. Identity stays
   forced, and so does UV_NO_MODIFY_PATH, which is a promise rather than a path.
   The installer now names any cache it kept, since one outside the root means
   rm -rf on the root no longer removes everything.

3. Converting a pre-#5190 install with --portable is no longer refused. The
   ownership guard wants a sentinel under STUDIO_HOME, and #5190 shipped all
   three of them alongside custom-root support, so an install last refreshed
   before 2026-05-05 has none: its studio.conf went to ~/.local/share/unsloth.
   That tree was accepted by a plain upgrade and refused by the same upgrade
   plus --portable. The legacy location now counts, but only for the legacy
   default root, never for a directory the user named.

4. .unsloth-master-root is written through a temporary and renamed. The
   redirection truncated on open, so a write that then failed left a previous
   valid record empty, and the error arm cleared its own rollback slot. A full
   volume is exactly what a portable root on a removable disk meets. The -d test
   in front is not redundant: mv moves a file INTO a directory rather than
   failing, which would have reported success and left no record.

5. A plain re-run keeps a portable install portable. The documented update is
   `curl ... | sh` with no arguments, and the shim's environment does not reach
   a fresh shell, so that read as a request for a normal install: the markers
   went, and every cache moved back under $HOME. The installer now adopts the
   marker a previous run left. Converting back is still available and now has to
   be asked for, with UNSLOTH_PORTABLE=0.

   This changes a contract four tests asserted deliberately. What those tests
   protect is that a marker cannot leave the tree reading as portable with no way
   out; that still holds, because UNSLOTH_PORTABLE=0 makes the installer normal,
   which clears the marker, which makes the runtime normal. Only the default
   moved, from converting silently to preserving what is there.

Also: portable mode moves the Hugging Face cache under the root, which costs a
re-download rather than a recompile, so the installer now says so when it finds a
warm ~/.cache/huggingface and the user named no HF variable of their own.

tests/sh: 0 failures across the directory.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
Each was reproduced before it was fixed, and each fix proven by removing it and
watching the new checks fail.

Publish the parent portable marker through a rename. A redirection truncates
before printf runs, so a write that died partway left a zero-byte marker at the
path every reader tests with -f, and the failure arm cleared the rollback slot so
nothing removed it. Measured: install.sh and storage_roots.portable_mode() both
reported portable=true off an empty marker, on an install that had already exited
1. Re-publication over a real portable install truncated its root away. Staging
and renaming gives both answers: nothing on a first failure, the previous bytes
on a later one. A symlink at the marker path is now replaced rather than
followed, which also stops the old in-place write truncating whatever it named.

Tell a typed --tauri from an adopted portable layout. Since portable mode is
adopted from markers on disk, a desktop repair, which passes --tauri and nothing
else, was refused with a message naming --portable and --root on a machine where
neither was supplied. Reachable by following the documented instructions, since
--portable with no --root selects $HOME/.unsloth, the directory the desktop app
uses. Still a refusal, since installing over a portable tree would leave the
desktop launching a Studio that is not there, but the message now describes the
install and gives the way out.

Compare the venv ownership evidence canonically. Installers before #5190 wrote
UNSLOTH_EXE with the lexical $HOME spelling while env-mode canonicalizes
STUDIO_HOME, so on a symlinked HOME our own config stopped vouching for our own
venv and the upgrade died with does not look like an Unsloth Studio install. main
accepted any existing studio.conf, so this refusal came in with the tightening.
The comparison is canonicalized, not dropped: a config naming another venv, or
another program, still fails.

Retire the portable configuration a conversion leaves behind. A nested portable
run writes share/studio.conf and launch-studio.sh at <root>/share, one level
above the tree it owns, and converting back wrote a new pair into
<root>/studio/share while retiring only <root>/bin/unsloth. Two otherwise-valid
launchers over one install, and whichever path the user kept decided where the HF
caches and the projects root went. Moved aside like the wrapper, only when the
config is ours and names this install, and never in the flat layout where that
share/ is the one being written.

Resolve the HF stranding notice through XDG_CACHE_HOME, the way huggingface_hub
resolves it. Hardcoding $HOME/.cache looked in the wrong place for anyone who
sets it, so exactly the users whose cache is somewhere unusual got no warning it
was about to be stranded.

Register the generated shim's staging file with the cleanup trap. Its inline
failure arm cannot run when a signal diverts into the trap, which left
.unsloth.shim.<pid> in the user's ~/.local/bin, where a successful retry never
looks and nothing prunes it.
danielhanchen added a commit that referenced this pull request Sep 8, 2026
The ordering ones are mine, from the two commits before this. _epr_default was
added to stop portable mode overriding a cache location the user chose, but
_export_portable_roots is CALLED after the block that seeds UV_CACHE_DIR, so it
read the installer's own seed back as a caller's choice: a nested install filled
<root>/studio/cache/uv while the shim, studio.conf and storage_roots all read
<root>/cache/uv, and a user who had set nothing was told their cache locations
were being kept. Both halves are fixed, the seed is portable-aware and the
equality case is not counted as a choice.

The conversion escape hatch cleared only the private copy of the root. Nothing
unsets UNSLOTH_HOME, and setup.sh inherits it and prefers it over a custom
Studio root for node, llama.cpp and whisper.cpp, so a conversion could report
success while the runtimes it installed sat under the old master root.

The flat-vs-nested test during conversion used bare directory existence, where
_resolve_studio_destinations and the parent-marker guard both require ownership
sentinels; a flat root with a leftover studio/ converted the wrong tree.

The legacy launcher record is matched byte-exact against a path written with a
logical pwd while env-mode canonicalizes with cd -P, so under a symlinked HOME
the installer refused a pre-#5190 install of its own.

studio/setup.sh run directly recovered the master root after choosing the uv
cache rather than before, and derived neither UV_INSTALL_DIR, UV_NO_MODIFY_PATH
nor NPM_CONFIG_CACHE, so uv landed in ~/.local/bin, shell startup files gained
permanent PATH lines and npm wrote ~/.npm.

The uninstaller never named the default portable root, so the documented
flagless uninstall left bin/, share/, cache/ and the marker behind while
reporting success; a symlinked studio/ had its database recorded lexically and
reported gone while intact on another volume; and a flat root's studio.db was
removed without recording it, closing with no studio.db was found.

README no longer promises that a flagless update finds every portable install.
It cannot find one made with --root, and said so nowhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-addresses-issue Pre-flight: appears to address an open issue auto-review-failed Auto-review rejected the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants