Skip to content

Add safe cleanup of older direct-install copilot binaries#2887

Closed
meagancojocar wants to merge 1 commit intogithub:mainfrom
meagancojocar:meagancojocar/add-safe-install-cleanup
Closed

Add safe cleanup of older direct-install copilot binaries#2887
meagancojocar wants to merge 1 commit intogithub:mainfrom
meagancojocar:meagancojocar/add-safe-install-cleanup

Conversation

@meagancojocar
Copy link
Copy Markdown

@meagancojocar meagancojocar commented Apr 21, 2026

Motivation

When users reinstall the CLI via install.sh into a different prefix, or when multiple direct-install copies accumulate over time, stale older binaries are left behind with no built-in way to clean them up. This PR makes cleanup automatic and has an opt out for the cleanup.

Approach

The install script now automatically removes older direct-install copies of copilot after every successful install. The cleanup is conservative by design -- it only deletes candidates that pass every safety check:

  • Ownership classification: Only standalone executables named copilot in bin/ directories are eligible. Symlinks, node_modules paths, Homebrew Cellar/Caskroom paths, copilot-sdk-* cache dirs, nix/snap/flatpak paths are all classified as managed and skipped.
  • Keep target: The just-installed binary (install flow) or command -v copilot (cleanup-only flow) is never deleted.
  • Version comparison: Candidates must be strictly older than the keep target. Ambiguous or unparseable versions are skipped.
  • Active session protection (two layers):
    1. Lock files (~/.copilot/session-state/*/inuse.<pid>.lock) for recent CLI versions
    2. Process table scan (ps -axww) that catches any running copilot process, covering pre-lock-era CLI versions that never created lock files
  • Non-fatal: Post-install cleanup failures produce a warning but never block the install or PATH setup instructions.

Usage

Cleanup runs by default. Opt out with:

curl -fsSL https://gh.io/copilot-install | NO_CLEANUP=true bash

Standalone cleanup without installing:

curl -fsSL https://gh.io/copilot-install | CLEANUP_ONLY=true bash

Preview mode:

curl -fsSL https://gh.io/copilot-install | CLEANUP_ONLY=true DRY_RUN=true VERBOSE=true bash

Files changed

File Change
install.sh Cleanup logic: candidate discovery, ownership classification, version comparison, session protection, reporting
README.md Document cleanup behavior, opt-out, cleanup-only mode, dry-run, and package-manager uninstall guidance
changelog.md Release note for 1.0.35

Out of scope

  • npm/Homebrew/WinGet-managed installs (reported to user, not deleted)
  • Runtime cache directories (copilot-sdk-*) > I just didnt know what to do with this
  • These are intentionally left to their owning package/runtime systems

Extend install.sh so that every successful install automatically removes
older install-script copies of copilot, while preserving:

- The currently selected CLI (command -v copilot or just-installed binary)
- Any binary backing an active session (via lock-file and process-table scan)
- Package-managed installs (Homebrew, npm, nix, snap, etc.)
- Runtime caches (copilot-sdk-* directories)

Cleanup runs by default after install.  Set NO_CLEANUP=true or pass
--no-cleanup to opt out.  A standalone CLEANUP_ONLY=true / --cleanup-only
mode is also available for cleanup without a fresh download.

Safety model:
- Only standalone executables named 'copilot' in bin/ directories are
  eligible for deletion (classified as direct-install candidates)
- Symlinks, node_modules paths, Homebrew Cellar/Caskroom paths, and
  copilot-sdk-* cache paths are classified as managed and skipped
- Version comparison requires the candidate to be strictly older than
  the keep target; ambiguous or unparseable versions are skipped
- Active-session detection inspects lock file PIDs and scans the process
  table for running copilot processes (covering pre-lock-era CLI versions)
- Post-install cleanup is non-fatal: failures produce a warning but
  do not prevent the install from completing
- Permission failures are surfaced clearly and are non-fatal

Update README.md with cleanup usage, dry-run guidance, scope limits,
and package-manager uninstall guidance.  Add changelog entry.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant