Skip to content

Instantly share code, notes, and snippets.

@akunzai
Last active October 14, 2026 01:17
Show Gist options
  • Select an option

  • Save akunzai/aa34eae4e7debfe70ef7defdfef26f9a to your computer and use it in GitHub Desktop.

Select an option

Save akunzai/aa34eae4e7debfe70ef7defdfef26f9a to your computer and use it in GitHub Desktop.
Muse Code uninstaller
<#
.SYNOPSIS
Removes Muse Code on Windows.
.DESCRIPTION
The installer writes the launcher and binaries to %LOCALAPPDATA%\Programs\muse
(or $env:MUSE_INSTALL_DIR, or ~/.local/bin) and adds that directory to User PATH.
The app keeps login credentials, settings, and session data under ~/.config/muse,
~/.local/share/muse, ~/.local/state/muse, and ~/.cache/muse.
Usage:
.\uninstall-muse-code.ps1 # dry run: list what would be removed
.\uninstall-muse-code.ps1 -Yes # remove matching paths, no prompt
.\uninstall-muse-code.ps1 -Apply # remove matching paths, with a confirm prompt
#>
[CmdletBinding()]
param(
[switch]$Apply,
[switch]$Yes,
[switch]$Help,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]]$RemainingArgs
)
# Support GNU/POSIX style flags passed on command line
$allArgs = @()
if ($RemainingArgs) { $allArgs += $RemainingArgs }
if ($args) { $allArgs += $args }
foreach ($a in $allArgs) {
switch ($a) {
'--yes' { $Yes = $true }
'-y' { $Yes = $true }
'--apply' { $Apply = $true }
'--help' { $Help = $true }
'-h' { $Help = $true }
default {
Write-Error "Unknown argument: $a`nUsage: uninstall-muse-code.ps1 [-Apply|--apply] [-Yes|--yes]"
exit 1
}
}
}
if ($Help) {
Get-Help $MyInvocation.MyCommand.Path
exit 0
}
$mode = "dry-run"
if ($Yes) {
$mode = "apply-yes"
} elseif ($Apply) {
$mode = "apply-confirm"
}
# Determine install directories
$candidateInstallDirs = [System.Collections.Generic.List[string]]::new()
if ($env:MUSE_INSTALL_DIR) {
$candidateInstallDirs.Add($env:MUSE_INSTALL_DIR)
}
$candidateInstallDirs.Add("$env:LOCALAPPDATA\Programs\muse")
$candidateInstallDirs.Add("$HOME\.local\bin")
$configHome = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { "$HOME\.config" }
$dataHome = if ($env:XDG_DATA_HOME) { $env:XDG_DATA_HOME } else { "$HOME\.local\share" }
$stateHome = if ($env:XDG_STATE_HOME) { $env:XDG_STATE_HOME } else { "$HOME\.local\state" }
$cacheHome = if ($env:XDG_CACHE_HOME) { $env:XDG_CACHE_HOME } else { "$HOME\.cache" }
$configDir = Join-Path $configHome 'muse'
$dataDir = Join-Path $dataHome 'muse'
$stateDir = Join-Path $stateHome 'muse'
$cacheDir = Join-Path $cacheHome 'muse'
$appDataDir = "$env:APPDATA\muse"
$localAppDataDir = "$env:LOCALAPPDATA\muse"
$versionPattern = '^[0-9]+\.[0-9]+\.[0-9]+-R[0-9]+(\.[0-9]+)?$'
function Format-FileSize {
param([long]$Bytes)
if ($Bytes -ge 1GB) {
return ("{0:N2} GB" -f ($Bytes / 1GB))
} elseif ($Bytes -ge 1MB) {
return ("{0:N2} MB" -f ($Bytes / 1MB))
} elseif ($Bytes -ge 1KB) {
return ("{0:N2} KB" -f ($Bytes / 1KB))
} else {
return ("$Bytes B")
}
}
function Get-PathSummary {
param([string]$Path)
if (-not (Test-Path -LiteralPath $Path)) {
return $Path
}
try {
$measure = Get-ChildItem -LiteralPath $Path -Recurse -Force -ErrorAction SilentlyContinue |
Measure-Object -Property Length -Sum
$sum = if ($null -ne $measure.Sum) { $measure.Sum } else { 0 }
$size = Format-FileSize -Bytes $sum
return "$size`t$Path"
} catch {
return $Path
}
}
function Test-MuseLauncher {
param([string]$Path)
if (-not (Test-Path -LiteralPath $Path)) { return $false }
try {
$content = Get-Content -LiteralPath $Path -Raw -ErrorAction SilentlyContinue
if (-not $content) { return $false }
return ($content -match 'api\.meta\.ai/muse-launcher' -or $content -match 'muse-bin' -or $content -match '\.muse-launcher\.ps1')
} catch {
return $false
}
}
function Test-MusePathLine {
param([string]$Line)
if (-not $Line) { return $false }
if ($Line -match '# added by muse installer') { return $true }
if ($Line -match 'export PATH=.*muse' -or $Line -match 'Programs[\\/]muse') { return $true }
return $false
}
$targets = [System.Collections.Generic.List[string]]::new()
$skipped = [System.Collections.Generic.List[string]]::new()
$pathDirsToClean = [System.Collections.Generic.List[string]]::new()
$foundInstall = $false
foreach ($dir in $candidateInstallDirs) {
if (-not (Test-Path -LiteralPath $dir)) { continue }
$launcherCmd = Join-Path $dir "muse.cmd"
$launcherPs1 = Join-Path $dir ".muse-launcher.ps1"
$launcherSh = Join-Path $dir "muse"
$versionFile = Join-Path $dir ".muse-version"
$isInstallDirDedicated = ($dir.TrimEnd('\', '/') -ieq "$env:LOCALAPPDATA\Programs\muse".TrimEnd('\', '/'))
$hasLauncher = (Test-MuseLauncher $launcherCmd) -or (Test-MuseLauncher $launcherPs1) -or (Test-MuseLauncher $launcherSh)
$hasVersion = $false
if (Test-Path -LiteralPath $versionFile) {
$verContent = (Get-Content -LiteralPath $versionFile -Raw -ErrorAction SilentlyContinue).Trim()
if ($verContent -match $versionPattern) {
$hasVersion = $true
}
}
if ($hasLauncher -or $hasVersion) {
$foundInstall = $true
$pathDirsToClean.Add($dir)
if ($isInstallDirDedicated) {
# Dedicated directory: can remove entire folder
if (-not $targets.Contains($dir)) {
$targets.Add($dir)
}
} else {
# Shared directory (e.g. ~/.local/bin): remove only muse-specific files
$knownFiles = @(
"muse", "muse.cmd", ".muse-launcher.ps1", ".muse-launcher.previous",
".muse-release-info.json", ".muse-version", ".muse-updater",
".muse-update-checked-at", ".muse-install-lock", ".muse-channel"
)
foreach ($kf in $knownFiles) {
$fp = Join-Path $dir $kf
if (Test-Path -LiteralPath $fp) { $targets.Add($fp) }
}
Get-ChildItem -LiteralPath $dir -Force -ErrorAction SilentlyContinue | Where-Object {
$_.Name -like "muse-bin-*" -or $_.Name -like ".muse-launcher.*" -or $_.Name -like ".muse-update*"
} | ForEach-Object {
if (-not $targets.Contains($_.FullName)) { $targets.Add($_.FullName) }
}
}
} elseif (Test-Path -LiteralPath (Join-Path $dir "muse")) {
$skipped.Add((Join-Path $dir "muse"))
} elseif (Test-Path -LiteralPath (Join-Path $dir "muse.cmd")) {
$skipped.Add((Join-Path $dir "muse.cmd"))
}
}
# Add configuration, data, state, and cache paths if installation was found or if folders exist
$dataCandidates = @($configDir, $dataDir, $stateDir, $cacheDir, $appDataDir, $localAppDataDir)
foreach ($dc in $dataCandidates) {
if (Test-Path -LiteralPath $dc) {
if ($foundInstall -or (Test-Path -LiteralPath (Join-Path $dc "sessions")) -or (Test-Path -LiteralPath (Join-Path $dc "auth.json"))) {
if (-not $targets.Contains($dc)) {
$targets.Add($dc)
}
}
}
}
# Check shell profile hits
$profileFiles = @(
"$HOME\.bashrc",
"$HOME\.bash_profile",
"$HOME\.bash_login",
"$HOME\.profile",
"$HOME\.zshrc",
"$configHome\fish\conf.d\muse.fish",
$PROFILE
) | Where-Object { Test-Path -LiteralPath $_ }
$profileHits = [System.Collections.Generic.List[PSCustomObject]]::new()
foreach ($pf in $profileFiles) {
$lines = Get-Content -LiteralPath $pf -ErrorAction SilentlyContinue
if ($lines) {
foreach ($line in $lines) {
if (Test-MusePathLine $line) {
$profileHits.Add([PSCustomObject]@{ File = $pf; Line = $line })
}
}
}
}
# Check User PATH for entries
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
$activeUserPathEntriesToRemove = [System.Collections.Generic.List[string]]::new()
if ($userPath) {
$parts = $userPath -split ';' | Where-Object { $_ -and $_.Trim() -ne '' }
foreach ($pd in $pathDirsToClean) {
$matching = $parts | Where-Object { $_.Trim().TrimEnd('\', '/') -eq $pd.TrimEnd('\', '/') }
foreach ($m in $matching) {
if (-not $activeUserPathEntriesToRemove.Contains($m)) {
$activeUserPathEntriesToRemove.Add($m)
}
}
}
}
Write-Host "== Muse Code paths =="
if ($targets.Count -eq 0) {
Write-Host "(none found)"
} else {
foreach ($p in $targets) {
Write-Host (Get-PathSummary -Path $p)
}
}
if ($activeUserPathEntriesToRemove.Count -gt 0) {
Write-Host
Write-Host "== Environment Variables =="
foreach ($entry in $activeUserPathEntriesToRemove) {
Write-Host "User PATH contains: $entry (will be removed)"
}
}
if ($profileHits.Count -gt 0) {
Write-Host
Write-Host "== shell profiles =="
foreach ($hit in $profileHits) {
Write-Host "$($hit.File): $($hit.Line)"
}
}
if ($skipped.Count -gt 0) {
Write-Host
Write-Host "== Left in place (not the Muse Code launcher) =="
foreach ($s in $skipped) {
Write-Host $s
}
}
if ($mode -eq "dry-run") {
Write-Host
Write-Host "Dry run only. Re-run with -Apply (asks to confirm) or -Yes (no prompt) to delete the above."
exit 0
}
if ($targets.Count -eq 0 -and $activeUserPathEntriesToRemove.Count -eq 0 -and $profileHits.Count -eq 0) {
Write-Host "`nNothing to remove."
exit 0
}
# Check for running muse processes
$running = Get-Process -ErrorAction SilentlyContinue | Where-Object {
try {
if ($_.ProcessName -match 'muse') { return $true }
if ($_.Path) {
foreach ($pd in $pathDirsToClean) {
if ($_.Path.StartsWith($pd, [System.StringComparison]::OrdinalIgnoreCase)) {
return $true
}
}
}
return $false
} catch {
return $false
}
}
if ($running) {
Write-Warning "Detected running Muse processes:"
$running | Select-Object Id, ProcessName, Path | Out-String | Write-Warning
if ($mode -eq "apply-confirm") {
$killChoice = Read-Host "Terminate these processes to proceed? [y/N]"
if ($killChoice -match '^[Yy]$') {
$running | Stop-Process -Force -ErrorAction SilentlyContinue
} else {
Write-Error "Aborted: cannot delete files while processes are running."
exit 1
}
} else {
$running | Stop-Process -Force -ErrorAction SilentlyContinue
}
}
if ($mode -eq "apply-confirm") {
Write-Host
$reply = Read-Host "Delete everything listed above? [y/N]"
if ($reply -notmatch '^[Yy]$') {
Write-Host "Aborted."
exit 1
}
}
# Remove targets
foreach ($p in $targets) {
if (Test-Path -LiteralPath $p) {
Remove-Item -LiteralPath $p -Recurse -Force -ErrorAction Stop
Write-Host "removed: $p"
}
}
# Clean User PATH
if ($activeUserPathEntriesToRemove.Count -gt 0) {
try {
$currentUserPath = [Environment]::GetEnvironmentVariable("Path", "User")
$parts = $currentUserPath -split ';' | Where-Object { $_ -and $_.Trim() -ne '' }
$cleaned = $parts | Where-Object {
$item = $_.Trim().TrimEnd('\', '/')
$shouldRemove = $false
foreach ($rm in $activeUserPathEntriesToRemove) {
if ($item -eq $rm.TrimEnd('\', '/')) {
$shouldRemove = $true
break
}
}
-not $shouldRemove
}
$newPath = $cleaned -join ';'
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
foreach ($rm in $activeUserPathEntriesToRemove) {
$env:Path = ($env:Path -split ';' | Where-Object { $_.Trim().TrimEnd('\', '/') -ne $rm.TrimEnd('\', '/') }) -join ';'
Write-Host "cleaned: removed $rm from User PATH"
}
} catch {
Write-Warning "Failed to update User PATH: $_"
}
}
# Clean profile lines
if ($profileHits.Count -gt 0) {
$uniqueProfileFiles = $profileHits | Select-Object -ExpandProperty File -Unique
foreach ($pf in $uniqueProfileFiles) {
try {
$lines = Get-Content -LiteralPath $pf
$newLines = [System.Collections.Generic.List[string]]::new()
$modified = $false
foreach ($l in $lines) {
if (Test-MusePathLine $l) {
$modified = $true
Write-Host "removed path line: $pf"
} else {
$newLines.Add($l)
}
}
if ($modified) {
Set-Content -LiteralPath $pf -Value $newLines -Encoding UTF8
}
} catch {
Write-Warning "Failed to update profile ${pf}: $_"
}
}
}
Write-Host "`nDone."
#!/usr/bin/env bash
# Removes Muse Code installed by:
# curl https://dev.meta.ai/install.sh | bash
# The installer writes a launcher to ~/.local/bin/muse (or $MUSE_INSTALL_DIR)
# and a muse-bin-<version> beside it. The app then keeps login and session
# data under ~/.config/muse, ~/.local/share/muse, and, on macOS,
# ~/Library/Application Support/Muse.
#
# A PATH line is removed only when it carries the installer's own marker,
# "# added by muse installer". Other ~/.local/bin PATH entries stay.
#
# Usage:
# uninstall-muse-code.sh # dry run: list what would be removed
# uninstall-muse-code.sh --yes # remove matching paths, no prompt
# uninstall-muse-code.sh --apply # remove matching paths, with a confirm prompt
set -euo pipefail
MODE="dry-run"
case "${1:-}" in
--yes) MODE="apply-yes" ;;
--apply) MODE="apply-confirm" ;;
"") ;;
*)
echo "Usage: $0 [--yes|--apply]" >&2
exit 1
;;
esac
install_dir="${MUSE_INSTALL_DIR:-$HOME/.local/bin}"
config_dir="${XDG_CONFIG_HOME:-$HOME/.config}/muse"
data_dir="${XDG_DATA_HOME:-$HOME/.local/share}/muse"
state_dir="${XDG_STATE_HOME:-$HOME/.local/state}/muse"
cache_dir="${XDG_CACHE_HOME:-$HOME/.cache}/muse"
version_pattern='^[0-9]+\.[0-9]+\.[0-9]+-R[0-9]+(\.[0-9]+)?$'
is_muse_launcher() {
local path="$1"
[[ -f "$path" && ! -L "$path" ]] || return 1
head -n 1 "$path" | grep -q 'sh' || return 1
grep -q 'api.meta.ai/muse-launcher.sh' "$path"
}
is_muse_path_line() {
local line="$1"
[[ "$line" == *" # added by muse installer" ]] || return 1
[[ "$line" == "export PATH="* || "$line" == "contains -- "* ]]
}
inode_id() {
if [[ "$(uname -s)" == Darwin ]]; then
stat -f '%d:%i' "$1"
else
stat -c '%d:%i' "$1"
fi
}
targets=()
skipped=()
seen_inodes=""
profile_files=()
profile_hits=()
add_target() {
local path="$1" id
[[ -e "$path" || -L "$path" ]] || return 0
id="$(inode_id "$path")"
case ":$seen_inodes:" in
*":$id:"*) return 0 ;;
esac
seen_inodes="${seen_inodes}:$id"
targets+=("$path")
}
install_present=0
if is_muse_launcher "$install_dir/muse"; then
install_present=1
elif [[ -e "$install_dir/muse" || -L "$install_dir/muse" ]]; then
skipped+=("$install_dir/muse")
fi
installed_version=""
if [[ -r "$install_dir/.muse-version" ]]; then
installed_version="$(<"$install_dir/.muse-version")"
installed_version="${installed_version//$'\n'/}"
fi
if [[ "$installed_version" =~ $version_pattern && -e "$install_dir/muse-bin-$installed_version" ]]; then
install_present=1
fi
if [[ "$install_present" -eq 1 ]]; then
add_target "$install_dir/muse"
add_target "$install_dir/.muse-launcher.previous"
add_target "$install_dir/.muse-release-info.json"
add_target "$install_dir/.muse-version"
add_target "$install_dir/.muse-updater"
add_target "$install_dir/.muse-install-lock"
add_target "$install_dir/muse-bin"
shopt -s nullglob
for path in \
"$install_dir"/muse-bin-* \
"$install_dir"/.muse-launcher.* \
"$install_dir"/.muse-update*; do
add_target "$path"
done
shopt -u nullglob
add_target "$config_dir"
add_target "$data_dir"
add_target "$state_dir"
add_target "$cache_dir"
if [[ "$(uname -s)" == Darwin ]]; then
add_target "$HOME/Library/Application Support/muse"
add_target "$HOME/Library/Application Support/Muse"
fi
fi
zdotdir="${ZDOTDIR:-$HOME}"
profile_files+=(
"$zdotdir/.zshrc"
"$HOME/.bashrc"
"$HOME/.bash_profile"
"$HOME/.bash_login"
"$HOME/.profile"
)
if [[ "$zdotdir/.zshrc" != "$HOME/.zshrc" ]]; then
profile_files+=("$HOME/.zshrc")
fi
fish_file="${XDG_CONFIG_HOME:-$HOME/.config}/fish/conf.d/muse.fish"
profile_files+=("$fish_file")
for file in "${profile_files[@]}"; do
[[ -f "$file" ]] || continue
while IFS= read -r line || [[ -n "$line" ]]; do
if is_muse_path_line "$line"; then
profile_hits+=("$file"$'\t'"$line")
fi
done <"$file"
done
echo "== Muse Code paths =="
if [[ ${#targets[@]} -eq 0 ]]; then
echo "(none found)"
else
for path in "${targets[@]}"; do
if [[ -L "$path" ]]; then
echo "$path -> $(readlink "$path")"
else
du -sh "$path" 2>/dev/null || echo "$path"
fi
done
fi
if [[ ${#profile_hits[@]} -gt 0 ]]; then
echo
echo "== shell profiles =="
for hit in "${profile_hits[@]}"; do
printf '%s\n' "${hit%%$'\t'*}: ${hit#*$'\t'}"
done
fi
if [[ ${#skipped[@]} -gt 0 ]]; then
echo
echo "== Left in place (not the Muse Code launcher) =="
printf '%s\n' "${skipped[@]}"
fi
if [[ "$MODE" == "dry-run" ]]; then
echo
echo "Dry run only. Re-run with --apply (asks to confirm) or --yes (no prompt) to delete the above."
exit 0
fi
if [[ ${#targets[@]} -eq 0 && ${#profile_hits[@]} -eq 0 ]]; then
exit 0
fi
if [[ "$MODE" == "apply-confirm" ]]; then
echo
read -r -p "Delete everything listed above? [y/N] " reply
[[ "$reply" =~ ^[Yy]$ ]] || {
echo "Aborted."
exit 1
}
fi
for path in "${targets[@]}"; do
rm -rf -- "$path"
echo "removed: $path"
done
strip_profile() {
local file="$1" tmp line kept_nonblank=0
[[ -f "$file" ]] || return 0
tmp="$(mktemp)"
while IFS= read -r line || [[ -n "$line" ]]; do
if is_muse_path_line "$line"; then
echo "removed path line: $file"
continue
fi
printf '%s\n' "$line" >>"$tmp"
[[ -n "${line//[[:space:]]/}" ]] && kept_nonblank=1
done <"$file"
if [[ "$file" == "$fish_file" && "$kept_nonblank" -eq 0 ]]; then
rm -f -- "$tmp" "$file"
echo "removed: $file"
return 0
fi
cat "$tmp" >"$file"
rm -f -- "$tmp"
}
if [[ ${#profile_hits[@]} -gt 0 ]]; then
seen_profiles=""
for hit in "${profile_hits[@]}"; do
file="${hit%%$'\t'*}"
case ":$seen_profiles:" in
*":$file:"*) continue ;;
esac
seen_profiles="${seen_profiles}:$file"
strip_profile "$file"
done
fi
echo
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment